40 parent::__construct(
'PageLanguage',
'pagelang' );
48 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
49 return parent::preText();
55 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
57 $defaultPageLanguage = MediaWikiServices::getInstance()
58 ->getContentHandlerFactory()
59 ->getContentHandler(
$title->getContentModel() )
60 ->getPageLanguage(
$title );
62 $hasCustomLanguageSet = !$defaultPageLanguage->equals(
$title->getPageLanguage() );
64 $hasCustomLanguageSet =
false;
70 'label-message' =>
'pagelang-name',
71 'default' =>
$title ?
$title->getPrefixedText() : $defaultName,
72 'autofocus' => $defaultName ===
null,
78 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
79 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
81 $page[
'selectoptions'] = [
82 'id' =>
'mw-pl-options',
84 'options' => $selectoptions,
85 'default' => $hasCustomLanguageSet ? 2 : 1
90 $languages = MediaWikiServices::getInstance()
91 ->getLanguageNameUtils()
92 ->getLanguageNames( $userLang,
'mwfile' );
94 foreach ( $languages as $code => $name ) {
95 $options[
"$code - $name"] = $code;
99 'id' =>
'mw-pl-languageselector',
100 'cssclass' =>
'mw-languageselector',
102 'options' => $options,
103 'label-message' =>
'pagelang-language',
105 $title->getPageLanguage()->getCode() :
106 $this->
getConfig()->get(
'LanguageCode' ),
112 'label-message' =>
'pagelang-reason'
139 $pageName = $data[
'pagename'];
142 if ( $data[
'selectoptions'] == 1 ) {
143 $newLanguage =
'default';
145 $newLanguage = $data[
'language'];
149 $title = Title::newFromTextThrow( $pageName );
155 $errors = MediaWikiServices::getInstance()->getPermissionManager()
160 $wikitext = $out->formatPermissionsErrorMessage( $errors );
162 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
166 $this->goToUrl =
$title->getFullUrlForRedirect(
167 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
174 $data[
'reason'] ??
''
187 $newLanguage, $reason, array $tags = [] ) {
189 $defLang = $context->
getConfig()->get(
'LanguageCode' );
191 $pageId =
$title->getArticleID();
195 return Status::newFatal(
196 'pagelang-nonexistent-page',
203 $oldLanguage = $dbw->selectField(
206 [
'page_id' => $pageId ],
211 if ( $newLanguage ===
'default' ) {
216 if ( $newLanguage === $oldLanguage ) {
218 if ( !$oldLanguage ) {
219 return Status::newFatal( ApiMessage::create(
221 'pagelang-unchanged-language-default',
224 'pagelang-unchanged-language'
227 return Status::newFatal(
228 'pagelang-unchanged-language',
235 $logOld = $oldLanguage ?: $defLang .
'[def]';
236 $logNew = $newLanguage ?: $defLang .
'[def]';
241 [
'page_lang' => $newLanguage ],
243 'page_id' => $pageId,
244 'page_lang' => $oldLanguage
249 if ( !$dbw->affectedRows() ) {
250 return Status::newFatal(
'pagelang-db-failed' );
255 '4::oldlanguage' => $logOld,
256 '5::newlanguage' => $logNew
259 $entry->setPerformer( $context->
getUser() );
260 $entry->setTarget(
$title );
261 $entry->setParameters( $logParams );
262 $entry->setComment( $reason );
263 $entry->addTags( $tags );
265 $logid = $entry->insert();
266 $entry->publish( $logid );
269 $title->invalidateCache();
271 return Status::newGood( (
object)[
272 'oldLanguage' => $logOld,
273 'newLanguage' => $logNew,
280 $this->
getOutput()->redirect( $this->goToUrl );
284 $moveLogPage =
new LogPage(
'pagelang' );
285 $out1 = Xml::element(
'h2',
null, $moveLogPage->getName()->text() );
287 LogEventsList::showLogExtract( $out2,
'pagelang',
$title );
288 return $out1 . $out2;
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
Class to simplify the use of log pages.
Class for creating new log entries and inserting them into the database.
Variant of the Message class.
Special page for changing the content language of a page.
getFormFields()
Get an HTMLForm descriptor array.
postText()
Add post-text to the form.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
static changePageLanguage(IContextSource $context, Title $title, $newLanguage, $reason, array $tags=[])
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
doesWrites()
Indicates whether this special page may perform database writes.
getDisplayFormat()
Get display format for the form.
string $goToUrl
URL to go to if language change successful.
preText()
Add pre-text to the form.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
Represents a title within MediaWiki.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.