Expand core post edit functionality to match VE
authorAlex Monk <krenair@gmail.com>
Sun, 20 Apr 2014 14:50:13 +0000 (16:50 +0200)
committerAlex Monk <krenair@wikimedia.org>
Tue, 29 Apr 2014 00:59:41 +0000 (01:59 +0100)
Then VE can just use the core messages

Bug: 52871
Change-Id: I2cd9defecd47321a30461a4d9ddd627c5018a891

includes/EditPage.php
languages/i18n/en.json
languages/i18n/qqq.json
resources/Resources.php
resources/src/mediawiki.action/mediawiki.action.view.postEdit.js

index c266996..2d62135 100644 (file)
@@ -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 );
                        }
                }
 
index d94cd30..8f4d11a 100644 (file)
     "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": "",
index 4e4872d..b2b6e09 100644 (file)
        "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}}",
index 8b0d675..81b99cb 100644 (file)
@@ -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(
index 6e4df9f..3419b5a 100644 (file)
        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 = $(
 
        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 ) );