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
$this,
$titleObj,
$params['lang'],
+ $params['reason'] === null ? '' : $params['reason'],
$params['tags'] ?: []
);
),
ApiBase::PARAM_REQUIRED => true,
],
+ 'reason' => null,
'tags' => [
ApiBase::PARAM_TYPE => 'tags',
ApiBase::PARAM_ISMULTI => true,
"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.",
"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}}",
'default' => $this->getConfig()->get( 'LanguageCode' ),
];
+ // Allow user to enter a comment explaining the change
+ $page['reason'] = [
+ 'type' => 'text',
+ 'label-message' => 'pagelang-reason'
+ ];
+
return $page;
}
// 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' );
$entry->setPerformer( $context->getUser() );
$entry->setTarget( $title );
$entry->setParameters( $logParams );
+ $entry->setComment( $reason );
$entry->setTags( $tags );
$logid = $entry->insert();
"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.",
"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",