Page MenuHomePhabricator

Cancel button returns Undefined error
Closed, ResolvedPublic

Description

I recently installed MediaWiki for a group I'm affiliated with: http://wiki.vvfh.org.

When I enabled the Publish/Cancel buttons, I discovered that the Cancel button returns an undefined error. The Publish button works as expected

See this discussion for details: https://www.mediawiki.org/w/index.php?title=Topic:Tzak3kzab3w3cfc0&fromnotif=1#flow-post-tzbcevfsuccaxe68

This is browser-displayed error. The error is not browser-dependent. (I've tested it in Safari, Chrome and Edge.)

Not Found
The requested URL /undefined was not found on this server.

This is my system software:

Installed software
Product Version
MediaWiki 1.29.1
PHP 7.1.9 (apache2handler)
MySQL 5.6.36
ICU 59.1

I have it disabled until I can resolve this.

Event Timeline

As this is a configuration that is not in use by WMF, it is not well maintained. There's been some talk of removing it for that reason.

Has this been closed? Or is it still being worked on?

Where do I find the code? I'll take a look, but I'm not a programmer, so....

I found out that the code is in jquery.WikiEditor.publish.js.
This is the relevant section:

context.fn.addButton( {
                                       captionMsg: 'wikieditor-publish-button-cancel',
                                       action: function () {
                                               window.location.href = $( '#mw-editform-cancel' ).attr( 'href' );
                                               return false;
                                       }
                               } );

window.location.href seems odd here. Why wouldn't you use window.history.back()? Cancelling should take you back to the previous page, just as hitting back in the browser.

I changed the code to this, and it worked as expected.

context.fn.addButton( {
        captionMsg: 'wikieditor-publish-button-cancel',
        action: function () {
/*              window.location.href = $( '#mw-editform-cancel' ).attr( 'href' ); */
                window.history.back() ;
                return false;
        }
} );

"Why wouldn't you use"

Because that's not supported in older versions of IE.

So what is supported? And what would happen in older versions of IE? Would it crater? Or just not work?

Frankly, I'd be inclined to tell the user to upgrade their browser. :)

It's working fine on my site, so I'm happy.

I propose window.location.href = $( '#mw-editform-cancel a' ).attr( 'href' ); hence, as soon as jQuery works (it’s a pre-condition here), it will work.

jQuery 1.x (provided until MW 1.30) supports old browsers (IE 6-8) and jQuery 3 (provided by MW 1.31) supports only more recent browsers like IE9+.

With such a pure-jQuery solution, the associated support is linked to the MediaWiki version. Compared to the current situation where it works nowhere, any of the two proposed solution would be an improvement.

Change 393282 had a related patch set uploaded (by Seb35; owner: Seb35):
[mediawiki/extensions/WikiEditor@master] Cancel button returns Undefined error

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

I can confirm that this change works on my site using Mac OS High Sierra 10.13.1 and Safari 11.0.1 as well as Google Chrome 62.0.3202.94.

Change 393282 merged by jenkins-bot:
[mediawiki/extensions/WikiEditor@master] Cancel button returns Undefined error

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

Seb35 claimed this task.