From: Alex Monk Date: Sun, 20 Apr 2014 14:50:13 +0000 (+0200) Subject: Expand core post edit functionality to match VE X-Git-Tag: 1.31.0-rc.0~15926^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;ds=sidebyside;h=e86f68c978d7a6cc89ec19508bba3387b9d15d9f;p=lhc%2Fweb%2Fwiklou.git Expand core post edit functionality to match VE Then VE can just use the core messages Bug: 52871 Change-Id: I2cd9defecd47321a30461a4d9ddd627c5018a891 --- diff --git a/includes/EditPage.php b/includes/EditPage.php index c266996082..2d62135058 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1213,13 +1213,22 @@ class EditPage { * * If the variable were set on the server, it would be cached, which is unwanted * since the post-edit state should only apply to the load right after the save. + * + * @param $statusValue int The status value (to check for new article status) */ - protected function setPostEditCookie() { + protected function setPostEditCookie( $statusValue ) { $revisionId = $this->mArticle->getLatest(); $postEditKey = self::POST_EDIT_COOKIE_KEY_PREFIX . $revisionId; + $val = 'saved'; + if ( $statusValue == self::AS_SUCCESS_NEW_ARTICLE ) { + $val = 'created'; + } elseif ( $this->oldid ) { + $val = 'restored'; + } + $response = RequestContext::getMain()->getRequest()->response(); - $response->setcookie( $postEditKey, '1', time() + self::POST_EDIT_COOKIE_DURATION, array( + $response->setcookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION, array( 'path' => '/', 'httpOnly' => false, ) ); @@ -1257,7 +1266,7 @@ class EditPage { if ( $status->value == self::AS_SUCCESS_UPDATE || $status->value == self::AS_SUCCESS_NEW_ARTICLE ) { $this->didSave = true; if ( !$resultDetails['nullEdit'] ) { - $this->setPostEditCookie(); + $this->setPostEditCookie( $status->value ); } } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index d94cd30ae0..8f4d11a881 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -692,7 +692,9 @@ "edit-gone-missing": "Could not update the page.\nIt appears to have been deleted.", "edit-conflict": "Edit conflict.", "edit-no-change": "Your edit was ignored because no change was made to the text.", - "postedit-confirmation": "Your edit was saved.", + "postedit-confirmation-created": "The page has been created.", + "postedit-confirmation-restored": "The page has been restored.", + "postedit-confirmation-saved": "Your edit was saved.", "edit-already-exists": "Could not create a new page.\nIt already exists.", "addsection-preload": "", "addsection-editintro": "", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 4e4872d979..b2b6e0909f 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -854,7 +854,9 @@ "edit-gone-missing": "Used as error message.\n\nSee also:\n* {{msg-mw|edit-hook-aborted}}\n* {{msg-mw|edit-conflict}}\n* {{msg-mw|edit-no-change}}\n* {{msg-mw|edit-already-exists}}", "edit-conflict": "An 'Edit conflict' happens when more than one edit is being made to a page at the same time. This would usually be caused by separate individuals working on the same page. However, if the system is slow, several edits from one individual could back up and attempt to apply simultaneously - causing the conflict.\n\nSee also:\n* {{msg-mw|edit-hook-aborted}}\n* {{msg-mw|edit-gone-missing}}\n* {{msg-mw|edit-no-change}}\n* {{msg-mw|edit-already-exists}}", "edit-no-change": "Used as error message.\n\nSee also:\n* {{msg-mw|edit-hook-aborted}}\n* {{msg-mw|edit-gone-missing}}\n* {{msg-mw|edit-conflict}}\n* {{msg-mw|edit-already-exists}}", - "postedit-confirmation": "{{gender}}\nConfirmation message that is displayed upon successful edit.\n\nParameters:\n* $1 - (Optional) the current user, for GENDER support", + "postedit-confirmation-created": "{{gender}}\nShown after a user creates a new page. Parameters:\n* $1 - the current user, for GENDER support", + "postedit-confirmation-restored": "{{gender}}\nShown after a user restores a page to a previous revision. Parameters:\n* $1 - the current user, for GENDER support", + "postedit-confirmation-saved": "{{gender}}\nShown after a user saves a page. Parameters:\n* $1 - the current user, for GENDER support", "edit-already-exists": "Used as error message.\n\nSee also:\n* {{msg-mw|edit-hook-aborted}}\n* {{msg-mw|edit-gone-missing}}\n* {{msg-mw|edit-conflict}}\n* {{msg-mw|edit-no-change}}", "addsection-preload": "{{notranslate}}", "addsection-editintro": "{{notranslate}}", diff --git a/resources/Resources.php b/resources/Resources.php index 8b0d675524..81b99cbde7 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -967,7 +967,9 @@ return array( 'mediawiki.jqueryMsg' ), 'messages' => array( - 'postedit-confirmation', + 'postedit-confirmation-created', + 'postedit-confirmation-restored', + 'postedit-confirmation-saved', ), ), 'mediawiki.action.view.redirectToFragment' => array( diff --git a/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js b/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js index 6e4df9f0d2..3419b5a989 100644 --- a/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js +++ b/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js @@ -21,12 +21,13 @@ var config = mw.config.get( [ 'wgAction', 'wgCookiePrefix', 'wgCurRevisionId' ] ), // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX: cookieKey = config.wgCookiePrefix + 'PostEditRevision' + config.wgCurRevisionId, + cookieVal = $.cookie( cookieKey ), $div, id; function showConfirmation( data ) { data = data || {}; if ( data.message === undefined ) { - data.message = $.parseHTML( mw.message( 'postedit-confirmation', data.user || mw.user ).escaped() ); + data.message = $.parseHTML( mw.message( 'postedit-confirmation-saved', data.user || mw.user ).escaped() ); } $div = $( @@ -66,11 +67,20 @@ mw.hook( 'postEdit' ).add( showConfirmation ); - if ( config.wgAction === 'view' && $.cookie( cookieKey ) === '1' ) { - $.cookie( cookieKey, null, { path: '/' } ); + if ( config.wgAction === 'view' && cookieVal ) { mw.config.set( 'wgPostEdit', true ); - mw.hook( 'postEdit' ).fire(); + 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 + ) + } ); + $.cookie( cookieKey, null, { path: '/' } ); } } ( mediaWiki, jQuery ) );