77 parent::__construct(
'PageLanguage',
'pagelang' );
78 $this->contentHandlerFactory = $contentHandlerFactory;
79 $this->languageNameUtils = $languageNameUtils;
80 $this->dbProvider = $dbProvider;
81 $this->searchEngineFactory = $searchEngineFactory;
89 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
90 return parent::preHtml();
96 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
98 $defaultPageLanguage = $this->contentHandlerFactory->getContentHandler( $title->getContentModel() )
99 ->getPageLanguage( $title );
101 $hasCustomLanguageSet = !$defaultPageLanguage->equals( $title->getPageLanguage() );
103 $hasCustomLanguageSet =
false;
107 $page[
'pagename'] = [
109 'label-message' =>
'pagelang-name',
110 'default' => $title ? $title->getPrefixedText() : $defaultName,
111 'autofocus' => $defaultName ===
null,
117 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
118 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
120 $page[
'selectoptions'] = [
121 'id' =>
'mw-pl-options',
123 'options' => $selectoptions,
124 'default' => $hasCustomLanguageSet ? 2 : 1
129 $languages = $this->languageNameUtils->getLanguageNames( $userLang, LanguageNameUtils::SUPPORTED );
131 foreach ( $languages as $code => $name ) {
132 $options[
"$code - $name"] = $code;
135 $page[
'language'] = [
136 'id' =>
'mw-pl-languageselector',
137 'cssclass' =>
'mw-languageselector',
139 'options' => $options,
140 'label-message' =>
'pagelang-language',
141 'default' => $title ?
142 $title->getPageLanguage()->getCode() :
149 'label-message' =>
'pagelang-reason'
157 return $this->showLogFragment( $this->par );
176 $pageName = $data[
'pagename'];
179 if ( $data[
'selectoptions'] == 1 ) {
180 $newLanguage =
'default';
182 $newLanguage = $data[
'language'];
186 $title = Title::newFromTextThrow( $pageName );
192 $status = PermissionStatus::newEmpty();
193 if ( !$this->
getAuthority()->authorizeWrite(
'edit', $title, $status ) ) {
194 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
196 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
200 $this->goToUrl = $title->getFullUrlForRedirect(
201 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
208 $data[
'reason'] ??
'',
210 $this->dbProvider->getPrimaryDatabase()
226 $newLanguage, $reason =
"", array $tags = [],
IDatabase $dbw =
null ) {
234 return Status::newFatal(
235 'pagelang-nonexistent-page',
242 $oldLanguage = $dbw->newSelectQueryBuilder()
243 ->select(
'page_lang' )
245 ->where( [
'page_id' => $pageId ] )
246 ->caller( __METHOD__ )->fetchField();
249 if ( $newLanguage ===
'default' ) {
254 if ( $newLanguage === $oldLanguage ) {
256 if ( !$oldLanguage ) {
257 return Status::newFatal( ApiMessage::create(
259 'pagelang-unchanged-language-default',
262 'pagelang-unchanged-language'
265 return Status::newFatal(
266 'pagelang-unchanged-language',
273 $logOld = $oldLanguage ?: $defLang .
'[def]';
274 $logNew = $newLanguage ?: $defLang .
'[def]';
277 $dbw->newUpdateQueryBuilder()
279 ->set( [
'page_lang' => $newLanguage ] )
281 'page_id' => $pageId,
282 'page_lang' => $oldLanguage,
284 ->caller( __METHOD__ )->execute();
286 if ( !$dbw->affectedRows() ) {
287 return Status::newFatal(
'pagelang-db-failed' );
292 '4::oldlanguage' => $logOld,
293 '5::newlanguage' => $logNew
296 $entry->setPerformer( $context->
getUser() );
297 $entry->setTarget( $title );
298 $entry->setParameters( $logParams );
299 $entry->setComment( is_string( $reason ) ? $reason :
"" );
300 $entry->addTags( $tags );
302 $logid = $entry->insert();
303 $entry->publish( $logid );
308 return Status::newGood( (
object)[
309 'oldLanguage' => $logOld,
310 'newLanguage' => $logNew,
317 $this->
getOutput()->redirect( $this->goToUrl );
320 private function showLogFragment( $title ) {
321 $moveLogPage =
new LogPage(
'pagelang' );
322 $out1 = Xml::element(
'h2',
null, $moveLogPage->getName()->text() );
324 LogEventsList::showLogExtract( $out2,
'pagelang', $title );
325 return $out1 . $out2;
337 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
349class_alias( SpecialPageLanguage::class,
'SpecialPageLanguage' );
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Extension of Message implementing IApiMessage.
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 sub-page of the special page.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
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.
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)
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=[], IDatabase $dbw=null)
doesWrites()
Indicates whether this special page may perform database writes.
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.
Module of static functions for generating XML.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.