67 parent::__construct(
'PageLanguage',
'pagelang' );
79 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
80 return parent::preText();
86 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
88 $defaultPageLanguage = $this->contentHandlerFactory->getContentHandler(
$title->getContentModel() )
89 ->getPageLanguage(
$title );
91 $hasCustomLanguageSet = !$defaultPageLanguage->equals(
$title->getPageLanguage() );
93 $hasCustomLanguageSet =
false;
99 'label-message' =>
'pagelang-name',
100 'default' =>
$title ?
$title->getPrefixedText() : $defaultName,
101 'autofocus' => $defaultName ===
null,
107 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
108 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
110 $page[
'selectoptions'] = [
111 'id' =>
'mw-pl-options',
113 'options' => $selectoptions,
114 'default' => $hasCustomLanguageSet ? 2 : 1
119 $languages = $this->languageNameUtils->getLanguageNames( $userLang,
'mwfile' );
121 foreach ( $languages as $code => $name ) {
122 $options[
"$code - $name"] = $code;
125 $page[
'language'] = [
126 'id' =>
'mw-pl-languageselector',
127 'cssclass' =>
'mw-languageselector',
129 'options' => $options,
130 'label-message' =>
'pagelang-language',
132 $title->getPageLanguage()->getCode() :
133 $this->
getConfig()->get(
'LanguageCode' ),
139 'label-message' =>
'pagelang-reason'
166 $pageName = $data[
'pagename'];
169 if ( $data[
'selectoptions'] == 1 ) {
170 $newLanguage =
'default';
172 $newLanguage = $data[
'language'];
176 $title = Title::newFromTextThrow( $pageName );
182 $status = PermissionStatus::newEmpty();
184 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
186 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
190 $this->goToUrl =
$title->getFullUrlForRedirect(
191 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
198 $data[
'reason'] ??
'',
200 $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_PRIMARY )
216 $newLanguage, $reason, array $tags = [],
IDatabase $dbw =
null ) {
218 $defLang = $context->
getConfig()->get(
'LanguageCode' );
220 $pageId =
$title->getArticleID();
224 return Status::newFatal(
225 'pagelang-nonexistent-page',
232 $oldLanguage = $dbw->selectField(
235 [
'page_id' => $pageId ],
240 if ( $newLanguage ===
'default' ) {
245 if ( $newLanguage === $oldLanguage ) {
247 if ( !$oldLanguage ) {
248 return Status::newFatal( ApiMessage::create(
250 'pagelang-unchanged-language-default',
253 'pagelang-unchanged-language'
256 return Status::newFatal(
257 'pagelang-unchanged-language',
264 $logOld = $oldLanguage ?: $defLang .
'[def]';
265 $logNew = $newLanguage ?: $defLang .
'[def]';
270 [
'page_lang' => $newLanguage ],
272 'page_id' => $pageId,
273 'page_lang' => $oldLanguage
278 if ( !$dbw->affectedRows() ) {
279 return Status::newFatal(
'pagelang-db-failed' );
284 '4::oldlanguage' => $logOld,
285 '5::newlanguage' => $logNew
288 $entry->setPerformer( $context->
getUser() );
289 $entry->setTarget(
$title );
290 $entry->setParameters( $logParams );
291 $entry->setComment( $reason );
292 $entry->addTags( $tags );
294 $logid = $entry->insert();
295 $entry->publish( $logid );
298 $title->invalidateCache();
300 return Status::newGood( (
object)[
301 'oldLanguage' => $logOld,
302 'newLanguage' => $logNew,
309 $this->
getOutput()->redirect( $this->goToUrl );
313 $moveLogPage =
new LogPage(
'pagelang' );
314 $out1 = Xml::element(
'h2',
null, $moveLogPage->getName()->text() );
316 LogEventsList::showLogExtract( $out2,
'pagelang',
$title );
317 return $out1 . $out2;
329 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
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.
Factory class for SearchEngine.
Special page for changing the content language of a page.
getFormFields()
Get an HTMLForm descriptor array.
SearchEngineFactory $searchEngineFactory
postText()
Add post-text to the form.
LanguageNameUtils $languageNameUtils
static changePageLanguage(IContextSource $context, Title $title, $newLanguage, $reason, array $tags=[], IDatabase $dbw=null)
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
__construct(IContentHandlerFactory $contentHandlerFactory, LanguageNameUtils $languageNameUtils, ILoadBalancer $loadBalancer, SearchEngineFactory $searchEngineFactory)
ILoadBalancer $loadBalancer
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...
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
IContentHandlerFactory $contentHandlerFactory
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.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
getConfig()
Shortcut to get main config object.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
getLanguage()
Shortcut to get user's language.
Represents a title within MediaWiki.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.