Page MenuHomePhabricator

AJAX button not working on MW 1.20+: "ReferenceError: wgDraft is not defined"
Closed, ResolvedPublic

Description

Author: ilia-kats

Description:
Upon clicking the Save Draft button, the page is normally saved and I am redirected to the page view, where my changes have been incorporated. A draft is not saved, the error console says ReferenceError: wgDraft is not defined. The following changes need to be applied to make it work:

  • Drafts.hooks.php.bak 2013-01-12 20:28:03.000000000 +0100

+++ Drafts.hooks.php 2013-01-12 20:29:00.000000000 +0100
@@ -211,7 +211,7 @@

}
$ajaxButton = Xml::escapeJsString(
        Xml::element( 'input',
  • array( 'type' => 'submit' ) + $buttonAttribs

+ array( 'type' => 'button' ) + $buttonAttribs

+ ( $wgRequest->getText( 'action' ) !== 'submit' ?
        array ( 'disabled' => 'disabled' )
        : array()
  • modules/ext.Drafts.js.bak 2013-01-12 20:08:37.000000000 +0100

+++ modules/ext.Drafts.js 2013-01-12 20:27:45.000000000 +0100
@@ -194,5 +194,5 @@

}

}

-var wgDraft = new Draft();
+window["wgDraft"] = new Draft();
wgDraft.initialize();


Version: master
Severity: normal

Details

Reference
bz43910

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:39 AM
bzimport set Reference to bz43910.
bzimport added a subscriber: Unknown Object (MLST).

Hi! Thanks for your patch!

You are welcome to use Developer access

https://www.mediawiki.org/wiki/Developer_access

to submit this as a Git branch directly into Gerrit:

https://www.mediawiki.org/wiki/Git/Tutorial

Putting your branch in Git makes it easier for us to review it quickly.
Thanks again! We appreciate your contribution.

Hi Ilia! Thanks for your patch!
You are welcome to use Developer access

https://www.mediawiki.org/wiki/Developer_access

to submit this as a Git branch directly into Gerrit:

https://www.mediawiki.org/wiki/Git/Tutorial

Putting your branch in Git makes it easier for us to review it quickly.
Thanks again! We appreciate your contribution.

boy90177 wrote:

I used other way to solve this bug.
I modify modules/ext.Drafts.js.
You have to modify 2 position.
line:121
line:135

BEFORE:

// Sets timer to save automatically after a period of time
timer = setTimeout(

'wgDraft.save()', configuration.autoSaveWait * 1000

);

AFTER:

// Sets timer to save automatically after a period of time
timer = setTimeout(

function () {self.save()}, configuration.autoSaveWait * 1000

);

I use v1.21 .
In IE9 & chrome & firefox,it can work.

  • Bug 55395 has been marked as a duplicate of this bug. ***

Confirming that this bug exists in current master (1.22), and I was able to reproduce it on 1.21 too.

I can easily reproduce this bug, but when I use &debug=true it works just fine.

Also, Chromium and Firefox both handle this error differently. Firefox will submit the form and save the page (bug 55395), but Chromium just sits there.

Change 88151 had a related patch set uploaded by Legoktm:
ReferenceError: wgDraft is not defined

https://gerrit.wikimedia.org/r/88151

(In reply to comment #0)

  • Drafts.hooks.php.bak 2013-01-12 20:28:03.000000000 +0100

+++ Drafts.hooks.php 2013-01-12 20:29:00.000000000 +0100

<snip>

So this part was already committed for the most part.

  • modules/ext.Drafts.js.bak 2013-01-12 20:08:37.000000000 +0100

+++ modules/ext.Drafts.js 2013-01-12 20:27:45.000000000 +0100
@@ -194,5 +194,5 @@

}

}

-var wgDraft = new Draft();
+window["wgDraft"] = new Draft();
wgDraft.initialize();

I put this part in gerrit.

Change 88151 abandoned by Legoktm:
ReferenceError: wgDraft is not defined

https://gerrit.wikimedia.org/r/88151

(In reply to comment #9)

Change 88151 abandoned by Legoktm:

As Yuvi pointed out, this is an ugly hack, and should be fixed in some other way.

Aklapper lowered the priority of this task from Medium to Low.Dec 29 2014, 11:49 PM
ashley claimed this task.
ashley subscribed.

As Yuvi pointed out, this is an ugly hack, and should be fixed in some other way.

I ended up going with the exact same ugly hack, albeit written slightly differently, back in November 2020 (28f48e343e675fc887ea2fe59025de7ce7d19208).
It's not the greatest thing ever but it got the job done so I'm marking this ticket as RESOLVED.