Brickimedia / brickimedia

Brickimedia Source Code
http://www.brickimedia.org
13 stars 4 forks source link

"Your edit was saved" dialog returning when it shouldn't #112

Closed georgebarnick closed 10 years ago

georgebarnick commented 10 years ago

After saving an edit to a page, then leaving the page, and later returning to the page, the "Your edit was saved" dialog is still there, when it shouldn't be. I've only tried this in the Refreshed skin so far.

rgmlcrh

neoncitylights commented 10 years ago

This seems to be happening on Deepsea too.

seaside98 commented 10 years ago

I found the problem. The cookie set to add them has the wrong expiration date. I would fix it, but I'm not sure where the code is for it. Does anyone know?

georgebarnick commented 10 years ago

@seaside98: mediawiki.action.view.postEdit.js

seaside98 commented 10 years ago

Where is the code for submitting an edit? That is really the root of the problem. There is no need for the cookie to be avaliable in all the subdomains.

georgebarnick commented 10 years ago

@seaside98: EditPage.php?

seaside98 commented 10 years ago

Ok, on line 1214 of EditPage.php a cookie is set. This cookie (on brickimedia) has the domain property of ".brickimedia.org". This value has to be referenced in the postEdit.js when deleting the cookie. It would be easy enough to fix for Brickimedia, but I don't know how it would affect others that don't have subdomains.

The easiest solution would be to edit postEdit.js and add in the domain. I don't know if it will work universally though. Line 70 should be:

$.cookie( cookieKey, null, { path: '/', domain: wgServer.replace(/.*?([^\.\/]*\.[^\.]*)$/, '.$1') } );

I used regex to break apart the wgServer variable and make sure no subdomains get matched. I know that this will work on Brickimedia, I just can't be absolutely certain about other wikis.

georgebarnick commented 10 years ago

Yeah, it must be using $wgCookieDomain, which is set in LocalSettings_private.php on our server. Can a cookie fix be made front-end with JavaScript? We don't really want to have any core since Brickimedia (unlike Wikia) uses completely pure MediaWiki.

seaside98 commented 10 years ago

Yes, easily. Where should I add it?

georgebarnick commented 10 years ago

First I'd suggest adding it to Special:MyPage/common.js to see if it works, and then I can add it to MediaWiki:Global.js once you have it working.

seaside98 commented 10 years ago
// Remove cookie after edit
var config = mw.config.get( [ 'wgAction', 'wgCookiePrefix', 'wgCurRevisionId' ] ),
cookieKey = config.wgCookiePrefix + 'PostEditRevision' + config.wgCurRevisionId;
if ( config.wgAction === 'view' && $.cookie( cookieKey ) === '1' ) {
    $.cookie( cookieKey, null, { path: '/', domain: '.brickimedia.org' } );
}
It runs great in the console, and there is no complex JS that would prevent it from working on the Global.js.
georgebarnick commented 10 years ago

I've added that to MediaWiki:Global.js, however I don't seem to get the "Your edit was saved" box at all now, when it should trigger.

seaside98 commented 10 years ago

Hmm. Then lets make it wait to fire until the whole page has loaded.

// Remove cookie after edit
$(window).bind('load', function() {
    var config = mw.config.get( [ 'wgAction', 'wgCookiePrefix', 'wgCurRevisionId' ] ),
    cookieKey = config.wgCookiePrefix + 'PostEditRevision' + config.wgCurRevisionId;
    if ( config.wgAction === 'view' && $.cookie( cookieKey ) === '1' ) {
        $.cookie( cookieKey, null, { path: '/', domain: '.brickimedia.org' } );
    }
});
georgebarnick commented 10 years ago

Works great! Thanks for the fix, Seaside! :smile: