From: Timo Tijhof Date: Wed, 8 Mar 2017 04:57:16 +0000 (-0800) Subject: postEdit: Only call mw.cookie.get() if needed X-Git-Tag: 1.31.0-rc.0~3816 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=475e0f2243eedb460520f70f0bec21dd1fa388bf;p=lhc%2Fweb%2Fwiklou.git postEdit: Only call mw.cookie.get() if needed Avoid synchronous document.cookie reads unconditionally during page load. At least avoid the read where it isn't needed, such as non-view actions and special pages. Ideally this would happen in mw.requestIdleCallback, but unfurtunately various extensions have a fragile dependency on reading mw.config wgPostEdit at initialitation time which would likely fail if this is no longer set synchronously. To be revisited... Change-Id: Ib655bf6507333c1a9845a05eb436dca522efbab7 --- diff --git a/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js b/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js index b339371da0..5dfdede408 100644 --- a/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js +++ b/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js @@ -25,8 +25,7 @@ var config = mw.config.get( [ 'wgAction', 'wgCurRevisionId' ] ), // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX: cookieKey = 'PostEditRevision' + config.wgCurRevisionId, - cookieVal = mw.cookie.get( cookieKey ), - $div, id; + cookieVal, $div, id; function removeConfirmation() { $div.remove(); @@ -64,20 +63,26 @@ mw.hook( 'postEdit' ).add( showConfirmation ); - if ( config.wgAction === 'view' && cookieVal ) { - mw.config.set( 'wgPostEdit', true ); - - mw.hook( 'postEdit' ).fire( { - // The following messages can be used here: - // postedit-confirmation-saved - // postedit-confirmation-created - // postedit-confirmation-restored - message: mw.msg( - 'postedit-confirmation-' + cookieVal, - mw.user - ) - } ); - mw.cookie.set( cookieKey, null ); + // Only when viewing wiki pages, that exist + // (E.g. not on special pages or non-view actions) + if ( config.wgCurRevisionId && config.wgAction === 'view' ) { + cookieVal = mw.cookie.get( cookieKey ); + if ( cookieVal ) { + mw.config.set( 'wgPostEdit', true ); + + mw.hook( 'postEdit' ).fire( { + // The following messages can be used here: + // postedit-confirmation-saved + // postedit-confirmation-created + // postedit-confirmation-restored + message: mw.msg( + 'postedit-confirmation-' + cookieVal, + mw.user + ) + } ); + + mw.cookie.set( cookieKey, null ); + } } }( mediaWiki, jQuery ) );