From 02660685708747d5c2e01176a8bd315ca96bc897 Mon Sep 17 00:00:00 2001 From: m4tx Date: Mon, 8 Dec 2014 19:45:15 +0100 Subject: [PATCH] Display error when user tries to create self-redirect Bug: T29683 Change-Id: Idcd7a50d12c8f124bc447805654b1a9e86dee3e4 --- includes/EditPage.php | 33 +++++++++++++++++++++++++++++++++ languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 3 files changed, 35 insertions(+) diff --git a/includes/EditPage.php b/includes/EditPage.php index 4a013ef3dd..db2e442bf6 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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( "
\n$1\n
", 'blankarticle' ); } + if ( $this->selfRedirect ) { + $wgOut->wrapWikiMsg( "
\n$1\n
", 'selfredirect' ); + } + if ( $this->hookError !== '' ) { $wgOut->addWikiText( $this->hookError ); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 4b4188d854..52e3a78f8d 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -590,6 +590,7 @@ "anoneditwarning": "Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you [$1 log in] or [$2 create an account], your edits will be attributed to your username, along with other benefits.", "anonpreviewwarning": "You are not logged in. Saving will record your IP address in this page's edit history.", "missingsummary": "Reminder: You have not provided an edit summary.\nIf you click \"{{int:savearticle}}\" again, your edit will be saved without one.", + "selfredirect": "Warning: 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": "Reminder: 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 4387623edd..2082104069 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, {{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}\n* $2 – A link to sign up, {{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}\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}}.", -- 2.20.1