45 private $contentHandlerFactory;
48 private $languageNameUtils;
51 private $loadBalancer;
54 private $searchEngineFactory;
68 parent::__construct(
'PageLanguage',
'pagelang' );
69 $this->contentHandlerFactory = $contentHandlerFactory;
70 $this->languageNameUtils = $languageNameUtils;
71 $this->loadBalancer = $loadBalancer;
72 $this->searchEngineFactory = $searchEngineFactory;
80 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
81 return parent::preHtml();
89 $defaultPageLanguage = $this->contentHandlerFactory->getContentHandler(
$title->getContentModel() )
90 ->getPageLanguage(
$title );
92 $hasCustomLanguageSet = !$defaultPageLanguage->equals(
$title->getPageLanguage() );
94 $hasCustomLanguageSet =
false;
100 'label-message' =>
'pagelang-name',
101 'default' =>
$title ?
$title->getPrefixedText() : $defaultName,
102 'autofocus' => $defaultName ===
null,
108 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
109 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
111 $page[
'selectoptions'] = [
112 'id' =>
'mw-pl-options',
114 'options' => $selectoptions,
115 'default' => $hasCustomLanguageSet ? 2 : 1
120 $languages = $this->languageNameUtils->getLanguageNames( $userLang, LanguageNameUtils::SUPPORTED );
122 foreach ( $languages as $code => $name ) {
123 $options[
"$code - $name"] = $code;
126 $page[
'language'] = [
127 'id' =>
'mw-pl-languageselector',
128 'cssclass' =>
'mw-languageselector',
130 'options' => $options,
131 'label-message' =>
'pagelang-language',
133 $title->getPageLanguage()->getCode() :
134 $this->
getConfig()->get( MainConfigNames::LanguageCode ),
140 'label-message' =>
'pagelang-reason'
148 return $this->showLogFragment( $this->par );
167 $pageName = $data[
'pagename'];
170 if ( $data[
'selectoptions'] == 1 ) {
171 $newLanguage =
'default';
173 $newLanguage = $data[
'language'];
183 $status = PermissionStatus::newEmpty();
185 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
191 $this->goToUrl =
$title->getFullUrlForRedirect(
192 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
199 $data[
'reason'] ??
'',
217 $newLanguage, $reason =
"", array $tags = [],
IDatabase $dbw =
null ) {
219 $defLang = $context->
getConfig()->get( MainConfigNames::LanguageCode );
221 $pageId =
$title->getArticleID();
226 'pagelang-nonexistent-page',
233 $oldLanguage = $dbw->selectField(
236 [
'page_id' => $pageId ],
241 if ( $newLanguage ===
'default' ) {
246 if ( $newLanguage === $oldLanguage ) {
248 if ( !$oldLanguage ) {
251 'pagelang-unchanged-language-default',
254 'pagelang-unchanged-language'
258 'pagelang-unchanged-language',
265 $logOld = $oldLanguage ?: $defLang .
'[def]';
266 $logNew = $newLanguage ?: $defLang .
'[def]';
271 [
'page_lang' => $newLanguage ],
273 'page_id' => $pageId,
274 'page_lang' => $oldLanguage
279 if ( !$dbw->affectedRows() ) {
285 '4::oldlanguage' => $logOld,
286 '5::newlanguage' => $logNew
289 $entry->setPerformer( $context->
getUser() );
290 $entry->setTarget(
$title );
291 $entry->setParameters( $logParams );
292 $entry->setComment( is_string( $reason ) ? $reason :
"" );
293 $entry->addTags( $tags );
295 $logid = $entry->insert();
296 $entry->publish( $logid );
299 $title->invalidateCache();
302 'oldLanguage' => $logOld,
303 'newLanguage' => $logNew,
310 $this->
getOutput()->redirect( $this->goToUrl );
313 private function showLogFragment(
$title ) {
314 $moveLogPage =
new LogPage(
'pagelang' );
315 $out1 =
Xml::element(
'h2',
null, $moveLogPage->getName()->text() );
318 return $out1 . $out2;
330 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,...
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Class to simplify the use of log pages.
Class for creating new log entries and inserting them into the database.
A class containing constants representing the names of configuration variables.
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.
postHtml()
Add post-HTML to the form.
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)
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
static changePageLanguage(IContextSource $context, Title $title, $newLanguage, $reason="", array $tags=[], IDatabase $dbw=null)
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.
preHtml()
Add pre-HTML to the form.
doesWrites()
Indicates whether this special page may perform database writes.
getDisplayFormat()
Get display format for 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.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
Represents a title within MediaWiki.
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.