68 parent::__construct(
'PageLanguage',
'pagelang' );
69 $this->contentHandlerFactory = $contentHandlerFactory;
70 $this->languageNameUtils = $languageNameUtils;
71 $this->dbProvider = $dbProvider;
72 $this->searchEngineFactory = $searchEngineFactory;
80 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
81 return parent::preHtml();
87 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
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',
132 'default' => $title ?
133 $title->getPageLanguage()->getCode() :
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'];
177 $title = Title::newFromTextThrow( $pageName );
183 $status = PermissionStatus::newEmpty();
184 if ( !$this->
getAuthority()->authorizeWrite(
'edit', $title, $status ) ) {
185 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
187 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
191 $this->goToUrl = $title->getFullUrlForRedirect(
192 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
199 $data[
'reason'] ??
'',
201 $this->dbProvider->getPrimaryDatabase()
217 $newLanguage, $reason =
"", array $tags = [], ?
IDatabase $dbw =
null ) {
225 return Status::newFatal(
226 'pagelang-nonexistent-page',
233 $oldLanguage = $dbw->newSelectQueryBuilder()
234 ->select(
'page_lang' )
236 ->where( [
'page_id' => $pageId ] )
237 ->caller( __METHOD__ )->fetchField();
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]';
268 $dbw->newUpdateQueryBuilder()
270 ->set( [
'page_lang' => $newLanguage ] )
272 'page_id' => $pageId,
273 'page_lang' => $oldLanguage,
275 ->caller( __METHOD__ )->execute();
277 if ( !$dbw->affectedRows() ) {
278 return Status::newFatal(
'pagelang-db-failed' );
283 '4::oldlanguage' => $logOld,
284 '5::newlanguage' => $logNew
287 $entry->setPerformer( $context->
getUser() );
288 $entry->setTarget( $title );
289 $entry->setParameters( $logParams );
290 $entry->setComment( is_string( $reason ) ? $reason :
"" );
291 $entry->addTags( $tags );
293 $logid = $entry->insert();
294 $entry->publish( $logid );
299 return Status::newGood( (
object)[
300 'oldLanguage' => $logOld,
301 'newLanguage' => $logNew,
308 $this->
getOutput()->redirect( $this->goToUrl );
311 private function showLogFragment(
string $title ): string {
312 $moveLogPage = new
LogPage(
'pagelang' );
313 $out1 =
Html::element(
'h2', [], $moveLogPage->getName()->text() );
315 LogEventsList::showLogExtract( $out2,
'pagelang', $title );
316 return $out1 . $out2;
328 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
340class_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.
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.