74 parent::__construct(
'PageLanguage',
'pagelang' );
75 $this->contentHandlerFactory = $contentHandlerFactory;
76 $this->languageNameUtils = $languageNameUtils;
77 $this->dbProvider = $dbProvider;
78 $this->searchEngineFactory = $searchEngineFactory;
86 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
87 return parent::preHtml();
93 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
95 $defaultPageLanguage = $this->contentHandlerFactory->getContentHandler( $title->getContentModel() )
96 ->getPageLanguage( $title );
98 $hasCustomLanguageSet = !$defaultPageLanguage->equals( $title->getPageLanguage() );
100 $hasCustomLanguageSet =
false;
104 $page[
'pagename'] = [
106 'label-message' =>
'pagelang-name',
107 'default' => $title ? $title->getPrefixedText() : $defaultName,
108 'autofocus' => $defaultName ===
null,
114 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
115 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
117 $page[
'selectoptions'] = [
118 'id' =>
'mw-pl-options',
120 'options' => $selectoptions,
121 'default' => $hasCustomLanguageSet ? 2 : 1
126 $languages = $this->languageNameUtils->getLanguageNames( $userLang, LanguageNameUtils::SUPPORTED );
128 foreach ( $languages as $code => $name ) {
129 $options[
"$code - $name"] = $code;
132 $page[
'language'] = [
133 'id' =>
'mw-pl-languageselector',
134 'cssclass' =>
'mw-languageselector',
136 'options' => $options,
137 'label-message' =>
'pagelang-language',
138 'default' => $title ?
139 $title->getPageLanguage()->getCode() :
146 'label-message' =>
'pagelang-reason'
154 return $this->showLogFragment( $this->par );
173 $pageName = $data[
'pagename'];
176 if ( $data[
'selectoptions'] == 1 ) {
177 $newLanguage =
'default';
179 $newLanguage = $data[
'language'];
183 $title = Title::newFromTextThrow( $pageName );
189 $status = PermissionStatus::newEmpty();
190 if ( !$this->
getAuthority()->authorizeWrite(
'edit', $title, $status ) ) {
191 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
193 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
197 $this->goToUrl = $title->getFullUrlForRedirect(
198 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
205 $data[
'reason'] ??
'',
207 $this->dbProvider->getPrimaryDatabase()
223 $newLanguage, $reason =
"", array $tags = [], ?
IDatabase $dbw =
null ) {
231 return Status::newFatal(
232 'pagelang-nonexistent-page',
239 $oldLanguage = $dbw->newSelectQueryBuilder()
240 ->select(
'page_lang' )
242 ->where( [
'page_id' => $pageId ] )
243 ->caller( __METHOD__ )->fetchField();
246 if ( $newLanguage ===
'default' ) {
251 if ( $newLanguage === $oldLanguage ) {
253 if ( !$oldLanguage ) {
254 return Status::newFatal( ApiMessage::create(
256 'pagelang-unchanged-language-default',
259 'pagelang-unchanged-language'
262 return Status::newFatal(
263 'pagelang-unchanged-language',
270 $logOld = $oldLanguage ?: $defLang .
'[def]';
271 $logNew = $newLanguage ?: $defLang .
'[def]';
274 $dbw->newUpdateQueryBuilder()
276 ->set( [
'page_lang' => $newLanguage ] )
278 'page_id' => $pageId,
279 'page_lang' => $oldLanguage,
281 ->caller( __METHOD__ )->execute();
283 if ( !$dbw->affectedRows() ) {
284 return Status::newFatal(
'pagelang-db-failed' );
289 '4::oldlanguage' => $logOld,
290 '5::newlanguage' => $logNew
293 $entry->setPerformer( $context->
getUser() );
294 $entry->setTarget( $title );
295 $entry->setParameters( $logParams );
296 $entry->setComment( is_string( $reason ) ? $reason :
"" );
297 $entry->addTags( $tags );
299 $logid = $entry->insert();
300 $entry->publish( $logid );
305 return Status::newGood( (
object)[
306 'oldLanguage' => $logOld,
307 'newLanguage' => $logNew,
314 $this->
getOutput()->redirect( $this->goToUrl );
317 private function showLogFragment( $title ) {
318 $moveLogPage =
new LogPage(
'pagelang' );
319 $out1 =
Xml::element(
'h2',
null, $moveLogPage->getName()->text() );
321 LogEventsList::showLogExtract( $out2,
'pagelang', $title );
322 return $out1 . $out2;
334 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
346class_alias( SpecialPageLanguage::class,
'SpecialPageLanguage' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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.
const LanguageCode
Name constant for the LanguageCode setting, for use with Config::get()
Special page which uses an HTMLForm to handle processing.
string null $par
The subpage of the special page.
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
prefixSearchString( $search, $limit, $offset, ?SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
getAuthority()
Shortcut to get the Authority executing this instance.
getLanguage()
Shortcut to get user's language.
Special page for changing the content language of a page.
getDisplayFormat()
Get display format for the form.
__construct(IContentHandlerFactory $contentHandlerFactory, LanguageNameUtils $languageNameUtils, IConnectionProvider $dbProvider, SearchEngineFactory $searchEngineFactory)
static changePageLanguage(IContextSource $context, Title $title, $newLanguage, $reason="", array $tags=[], ?IDatabase $dbw=null)
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...
doesWrites()
Indicates whether POST requests to this special page require write access to the wiki.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
preHtml()
Add pre-HTML to the form.
postHtml()
Add post-HTML to the form.
getFormFields()
Get an HTMLForm descriptor array.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Factory class for SearchEngine.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.