From b64abcf64e966a8d52fc4f0e43c0a1c9f870726f Mon Sep 17 00:00:00 2001 From: MtDu Date: Fri, 6 Jan 2017 07:04:41 -0600 Subject: [PATCH] Add a reason field to both Special:PageLanguage and ApiSetPageLanguage Most MediaWiki actions allow a user to enter a comment/reason for taking the action. This is logged in the change log. Currently, both ApiSetPageLanguage and Special:PageLanguage don't do this. This patch fixes this issue. Bug: T154644 Change-Id: I6ae021086e1ec4440d6b2894a1b85d62eb36e172 --- includes/api/ApiSetPageLanguage.php | 2 ++ includes/api/i18n/en.json | 1 + includes/api/i18n/qqq.json | 1 + includes/specials/SpecialPageLanguage.php | 17 +++++++++++++++-- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiSetPageLanguage.php b/includes/api/ApiSetPageLanguage.php index 3f03c02680..3ff99f11c0 100755 --- a/includes/api/ApiSetPageLanguage.php +++ b/includes/api/ApiSetPageLanguage.php @@ -84,6 +84,7 @@ class ApiSetPageLanguage extends ApiBase { $this, $titleObj, $params['lang'], + $params['reason'] === null ? '' : $params['reason'], $params['tags'] ?: [] ); @@ -121,6 +122,7 @@ class ApiSetPageLanguage extends ApiBase { ), ApiBase::PARAM_REQUIRED => true, ], + 'reason' => null, 'tags' => [ ApiBase::PARAM_TYPE => 'tags', ApiBase::PARAM_ISMULTI => true, diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 9915d391ca..1385097e40 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1360,6 +1360,7 @@ "apihelp-setpagelanguage-param-title": "Title of the page whose language you wish to change. Cannot be used together with $1pageid.", "apihelp-setpagelanguage-param-pageid": "Page ID of the page whose language you wish to change. Cannot be used together with $1title.", "apihelp-setpagelanguage-param-lang": "Language code of the language to change the page to. Use default to reset the page to the wiki's default content language.", + "apihelp-setpagelanguage-param-reason": "Reason for the change.", "apihelp-setpagelanguage-param-tags": "Change tags to apply to the log entry resulting from this action.", "apihelp-setpagelanguage-example-language": "Change the language of Main Page to Basque.", "apihelp-setpagelanguage-example-default": "Change the language of the page with ID 123 to the wiki's default content language.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index c6b14cd72b..cab2a3ead3 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1268,6 +1268,7 @@ "apihelp-setpagelanguage-param-title": "{{doc-apihelp-param|setpagelanguage|title}}", "apihelp-setpagelanguage-param-pageid": "{{doc-apihelp-param|setpagelanguage|pageid}}", "apihelp-setpagelanguage-param-lang": "{{doc-apihelp-param|setpagelanguage|lang}}", + "apihelp-setpagelanguage-param-reason": "{{doc-apihelp-param|setpagelanguage|reason}}", "apihelp-setpagelanguage-param-tags": "{{doc-apihelp-param|setpagelanguage|tags}}", "apihelp-setpagelanguage-example-language": "{{doc-apihelp-example|setpagelanguage}}", "apihelp-setpagelanguage-example-default": "{{doc-apihelp-example|setpagelanguage}}", diff --git a/includes/specials/SpecialPageLanguage.php b/includes/specials/SpecialPageLanguage.php index 8546a08d89..d4cd2ac6f2 100644 --- a/includes/specials/SpecialPageLanguage.php +++ b/includes/specials/SpecialPageLanguage.php @@ -89,6 +89,12 @@ class SpecialPageLanguage extends FormSpecialPage { 'default' => $this->getConfig()->get( 'LanguageCode' ), ]; + // Allow user to enter a comment explaining the change + $page['reason'] = [ + 'type' => 'text', + 'label-message' => 'pagelang-reason' + ]; + return $page; } @@ -132,18 +138,24 @@ class SpecialPageLanguage extends FormSpecialPage { // Url to redirect to after the operation $this->goToUrl = $title->getFullURL(); - return self::changePageLanguage( $this->getContext(), $title, $newLanguage ); + return self::changePageLanguage( + $this->getContext(), + $title, + $newLanguage, + $data['reason'] === null ? '' : $data['reason'] + ); } /** * @param IContextSource $context * @param Title $title * @param string $newLanguage Language code + * @param string $reason Reason for the change * @param array $tags Change tags to apply to the log entry * @return Status */ public static function changePageLanguage( IContextSource $context, Title $title, - $newLanguage, array $tags = [] ) { + $newLanguage, $reason, array $tags = [] ) { // Get the default language for the wiki $defLang = $context->getConfig()->get( 'LanguageCode' ); @@ -218,6 +230,7 @@ class SpecialPageLanguage extends FormSpecialPage { $entry->setPerformer( $context->getUser() ); $entry->setTarget( $title ); $entry->setParameters( $logParams ); + $entry->setComment( $reason ); $entry->setTags( $tags ); $logid = $entry->insert(); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 076ce40474..4131777a18 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -4063,6 +4063,7 @@ "pagelang-language": "Language", "pagelang-use-default": "Use default language", "pagelang-select-lang": "Select language", + "pagelang-reason": "Reason", "pagelang-submit": "Submit", "pagelang-nonexistent-page": "The page $1 does not exist.", "pagelang-unchanged-language": "The page $1 is already set to language $2.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index bf23a1b789..78a0f9c43e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -4247,6 +4247,7 @@ "pagelang-language": "Language selector label for Special:PageLanguage\n{{Identical|Language}}", "pagelang-use-default": "Radio label for selector on Special:PageLanguage for default language", "pagelang-select-lang": "Radio label for selector on Special:PageLanguage for language selection\n{{Identical|Select language}}", + "pagelang-reason": "Input label for reason on Special:PageLanguage\n\n{{Identical|Reason}}", "pagelang-submit": "Submit button label for Special:PageLanguage form\n{{Identical|Submit}}", "pagelang-nonexistent-page": "Error message shown when the page the user is trying to change the language on does not exist.\n\nParameters:\n* $1 - the title of the nonexistent page", "pagelang-unchanged-language": "Error message shown when the language the user is trying to change the page to and the current language the page is in are the same.\n\nParameters:\n* $1 - the title of the target page\n* $2 - the current language of the page", -- 2.20.1