Add a reason field to both Special:PageLanguage and ApiSetPageLanguage
authorMtDu <justin.d128@gmail.com>
Fri, 6 Jan 2017 13:04:41 +0000 (07:04 -0600)
committerMtDu <justin.d128@gmail.com>
Fri, 6 Jan 2017 13:39:20 +0000 (07:39 -0600)
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
includes/api/i18n/en.json
includes/api/i18n/qqq.json
includes/specials/SpecialPageLanguage.php
languages/i18n/en.json
languages/i18n/qqq.json

index 3f03c02..3ff99f1 100755 (executable)
@@ -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,
index 9915d39..1385097 100644 (file)
        "apihelp-setpagelanguage-param-title": "Title of the page whose language you wish to change. Cannot be used together with <var>$1pageid</var>.",
        "apihelp-setpagelanguage-param-pageid": "Page ID of the page whose language you wish to change. Cannot be used together with <var>$1title</var>.",
        "apihelp-setpagelanguage-param-lang": "Language code of the language to change the page to. Use <kbd>default</kbd> 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 <kbd>Main Page</kbd> to Basque.",
        "apihelp-setpagelanguage-example-default": "Change the language of the page with ID 123 to the wiki's default content language.",
index c6b14cd..cab2a3e 100644 (file)
        "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}}",
index 8546a08..d4cd2ac 100644 (file)
@@ -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();
index 076ce40..4131777 100644 (file)
        "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.",
index bf23a1b..78a0f9c 100644 (file)
        "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",