jenkins-bot has submitted this change and it was merged.

Change subject: Display error when user tries to create self-redirect
......................................................................


Display error when user tries to create self-redirect

Bug: T29683
Change-Id: Idcd7a50d12c8f124bc447805654b1a9e86dee3e4
---
M includes/EditPage.php
M languages/i18n/en.json
M languages/i18n/qqq.json
3 files changed, 35 insertions(+), 0 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/EditPage.php b/includes/EditPage.php
index 4a013ef..db2e442 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -151,6 +151,12 @@
        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
         */
        const AS_PARSE_ERROR = 240;
@@ -255,6 +261,12 @@
 
        /** @var bool */
        protected $allowBlankArticle = false;
+
+       /** @var bool */
+       protected $selfRedirect = false;
+
+       /** @var bool */
+       protected $allowSelfRedirect = false;
 
        /** @var string */
        public $autoSumm = '';
@@ -848,6 +860,7 @@
                        $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 @@
                        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 @@
                        $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 @@
                        $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 @@
                                $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 );
                        }
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index 4b4188d..52e3a78 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -590,6 +590,7 @@
        "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:",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 4387623..2082104 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -754,6 +754,7 @@
        "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}}.",

-- 
To view, visit https://gerrit.wikimedia.org/r/178238
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idcd7a50d12c8f124bc447805654b1a9e86dee3e4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: M4tx <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: M4tx <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tpt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to