Display error when user tries to create self-redirect
authorm4tx <m4tx@m4tx.pl>
Mon, 8 Dec 2014 18:45:15 +0000 (19:45 +0100)
committerm4tx <m4tx@m4tx.pl>
Mon, 8 Dec 2014 20:37:42 +0000 (21:37 +0100)
Bug: T29683
Change-Id: Idcd7a50d12c8f124bc447805654b1a9e86dee3e4

includes/EditPage.php
languages/i18n/en.json
languages/i18n/qqq.json

index 4a013ef..db2e442 100644 (file)
@@ -150,6 +150,12 @@ class EditPage {
         */
        const AS_NO_CHANGE_CONTENT_MODEL = 235;
 
+       /**
+        * Status: user tried to create self-redirect (redirect to the same article) and
+        * wpIgnoreSelfRedirect == false
+        */
+       const AS_SELF_REDIRECT = 236;
+
        /**
         * Status: can't parse content
         */
@@ -256,6 +262,12 @@ class EditPage {
        /** @var bool */
        protected $allowBlankArticle = false;
 
+       /** @var bool */
+       protected $selfRedirect = false;
+
+       /** @var bool */
+       protected $allowSelfRedirect = false;
+
        /** @var string */
        public $autoSumm = '';
 
@@ -848,6 +860,7 @@ class EditPage {
                        $this->autoSumm = $request->getText( 'wpAutoSummary' );
 
                        $this->allowBlankArticle = $request->getBool( 'wpIgnoreBlankArticle' );
+                       $this->allowSelfRedirect = $request->getBool( 'wpIgnoreSelfRedirect' );
                } else {
                        # Not a posted form? Start with nothing.
                        wfDebug( __METHOD__ . ": Not a posted form.\n" );
@@ -1334,6 +1347,7 @@ class EditPage {
                        case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
                        case self::AS_END:
                        case self::AS_BLANK_ARTICLE:
+                       case self::AS_SELF_REDIRECT:
                                return true;
 
                        case self::AS_HOOK_ERROR:
@@ -1901,6 +1915,17 @@ class EditPage {
                        $status->value = self::AS_SUCCESS_UPDATE;
                }
 
+               if ( !$this->allowSelfRedirect
+                       && $content->isRedirect()
+                       && $content->getRedirectTarget()->equals( $this->getTitle() )
+               ) {
+                       $this->selfRedirect = true;
+                       $status->fatal( 'selfredirect' );
+                       $status->value = self::AS_SELF_REDIRECT;
+                       wfProfileOut( __METHOD__ );
+                       return $status;
+               }
+
                // Check for length errors again now that the section is merged in
                $this->kblength = (int)( strlen( $this->toEditText( $content ) ) / 1024 );
                if ( $this->kblength > $wgMaxArticleSize ) {
@@ -2445,6 +2470,10 @@ class EditPage {
                        $wgOut->addHTML( Html::hidden( 'wpUndidRevision', $this->undidRev ) );
                }
 
+               if ( $this->selfRedirect ) {
+                       $wgOut->addHTML( Html::hidden( 'wpIgnoreSelfRedirect', true ) );
+               }
+
                if ( $this->hasPresetSummary ) {
                        // If a summary has been preset using &summary= we don't want to prompt for
                        // a different summary. Only prompt for a summary if the summary is blanked.
@@ -2609,6 +2638,10 @@ class EditPage {
                                $wgOut->wrapWikiMsg( "<div id='mw-blankarticle'>\n$1\n</div>", 'blankarticle' );
                        }
 
+                       if ( $this->selfRedirect ) {
+                               $wgOut->wrapWikiMsg( "<div id='mw-selfredirect'>\n$1\n</div>", 'selfredirect' );
+                       }
+
                        if ( $this->hookError !== '' ) {
                                $wgOut->addWikiText( $this->hookError );
                        }
index 4b4188d..52e3a78 100644 (file)
        "anoneditwarning": "<strong>Warning:</strong> You are not logged in. Your IP address will be publicly visible if you make any edits. If you <strong>[$1 log in]</strong> or <strong>[$2 create an account]</strong>, your edits will be attributed to your username, along with other benefits.",
        "anonpreviewwarning": "<em>You are not logged in. Saving will record your IP address in this page's edit history.</em>",
        "missingsummary": "<strong>Reminder:</strong> You have not provided an edit summary.\nIf you click \"{{int:savearticle}}\" again, your edit will be saved without one.",
+       "selfredirect": "<strong>Warning:</strong> You are creating redirect to the same article.\nIf you click \"{{int:savearticle}}\" again, the redirect will be created.",
        "missingcommenttext": "Please enter a comment below.",
        "missingcommentheader": "<strong>Reminder:</strong> You have not provided a subject/headline for this comment.\nIf you click \"{{int:savearticle}}\" again, your edit will be saved without one.",
        "summary-preview": "Summary preview:",
index 4387623..2082104 100644 (file)
        "anoneditwarning": "Shown when editing a page anonymously.\n\nParameters:\n* $1 – A link to log in, <nowiki>{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}</nowiki>\n* $2 – A link to sign up, <nowiki>{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}</nowiki>\n\nSee also:\n* {{msg-mw|mobile-frontend-editor-anoneditwarning}}",
        "anonpreviewwarning": "See also:\n* {{msg-mw|Anoneditwarning}}",
        "missingsummary": "The text \"edit summary\" is in {{msg-mw|Summary}}.\n\nSee also:\n* {{msg-mw|Missingcommentheader}}\n* {{msg-mw|Savearticle}}",
+       "selfredirect": "Notice displayed once after the user tries to create a redirect to the same article.",
        "missingcommenttext": "This message is shown, when the textbox by a new-section is empty.",
        "missingcommentheader": "Edit summary that is shown if you enable \"Prompt me when entering a blank summary\" and add a new section without headline to a talk page.\n\nSee also:\n* {{msg-mw|Missingsummary}}\n* {{msg-mw|Savearticle}}",
        "summary-preview": "Preview of the edit summary, shown under the edit summary itself.\nShould match: {{msg-mw|summary}}.",