15use MediaWiki\Languages\LanguageNameUtils;
44 private LanguageNameUtils $languageNameUtils;
50 LanguageNameUtils $languageNameUtils,
54 parent::__construct(
'PageLanguage',
'pagelang' );
55 $this->contentHandlerFactory = $contentHandlerFactory;
56 $this->languageNameUtils = $languageNameUtils;
57 $this->dbProvider = $dbProvider;
58 $this->searchEngineFactory = $searchEngineFactory;
68 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
69 return parent::preHtml();
76 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
78 $defaultPageLanguage = $this->contentHandlerFactory->getContentHandler( $title->getContentModel() )
79 ->getPageLanguage( $title );
81 $hasCustomLanguageSet = !$defaultPageLanguage->equals( $title->getPageLanguage() );
83 $hasCustomLanguageSet =
false;
89 'label-message' =>
'pagelang-name',
90 'default' => $title ? $title->getPrefixedText() : $defaultName,
91 'autofocus' => $defaultName ===
null,
97 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
98 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
100 $page[
'selectoptions'] = [
101 'id' =>
'mw-pl-options',
103 'options' => $selectoptions,
104 'default' => $hasCustomLanguageSet ? 2 : 1
109 $languages = $this->languageNameUtils->getLanguageNames( $userLang, LanguageNameUtils::SUPPORTED );
111 foreach ( $languages as $code => $name ) {
112 $options[
"$code - $name"] = $code;
115 $page[
'language'] = [
116 'id' =>
'mw-pl-languageselector',
117 'cssclass' =>
'mw-languageselector',
119 'options' => $options,
120 'label-message' =>
'pagelang-language',
121 'default' => $title ?
122 $title->getPageLanguage()->getCode() :
129 'label-message' =>
'pagelang-reason'
138 return $this->showLogFragment( $this->par );
158 $pageName = $data[
'pagename'];
161 if ( $data[
'selectoptions'] == 1 ) {
162 $newLanguage =
'default';
164 $newLanguage = $data[
'language'];
168 $title = Title::newFromTextThrow( $pageName );
174 $status = PermissionStatus::newEmpty();
175 if ( !$this->
getAuthority()->authorizeWrite(
'edit', $title, $status ) ) {
176 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
178 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
182 $this->goToUrl = $title->getFullUrlForRedirect(
183 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
190 $data[
'reason'] ??
'',
192 $this->dbProvider->getPrimaryDatabase()
208 $newLanguage, $reason =
"", array $tags = [], ?
IDatabase $dbw =
null ) {
216 return Status::newFatal(
217 'pagelang-nonexistent-page',
224 $oldLanguage = $dbw->newSelectQueryBuilder()
225 ->select(
'page_lang' )
227 ->where( [
'page_id' => $pageId ] )
228 ->caller( __METHOD__ )->fetchField();
231 if ( $newLanguage ===
'default' ) {
236 if ( $newLanguage === $oldLanguage ) {
238 if ( !$oldLanguage ) {
239 return Status::newFatal( ApiMessage::create(
241 'pagelang-unchanged-language-default',
244 'pagelang-unchanged-language'
247 return Status::newFatal(
248 'pagelang-unchanged-language',
255 $logOld = $oldLanguage ?: $defLang .
'[def]';
256 $logNew = $newLanguage ?: $defLang .
'[def]';
259 $dbw->newUpdateQueryBuilder()
261 ->set( [
'page_lang' => $newLanguage ] )
263 'page_id' => $pageId,
264 'page_lang' => $oldLanguage,
266 ->caller( __METHOD__ )->execute();
268 if ( !$dbw->affectedRows() ) {
269 return Status::newFatal(
'pagelang-db-failed' );
274 '4::oldlanguage' => $logOld,
275 '5::newlanguage' => $logNew
278 $entry->setPerformer( $context->
getUser() );
279 $entry->setTarget( $title );
280 $entry->setParameters( $logParams );
281 $entry->setComment( is_string( $reason ) ? $reason :
"" );
282 $entry->addTags( $tags );
284 $logid = $entry->insert();
285 $entry->publish( $logid );
290 return Status::newGood( (
object)[
291 'oldLanguage' => $logOld,
292 'newLanguage' => $logNew,
299 $this->
getOutput()->redirect( $this->goToUrl );
302 private function showLogFragment(
string $title ): string {
303 $moveLogPage = new
LogPage(
'pagelang' );
304 $out1 =
Html::element(
'h2', [], $moveLogPage->getName()->text() );
306 LogEventsList::showLogExtract( $out2,
'pagelang', $title );
307 return $out1 . $out2;
319 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
332class_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.See HTMLForm documentation for available values.1....
__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.string HTML which will be sent to $form->addPreHtml() 1.38
postHtml()
Add post-HTML to the form.string HTML which will be sent to $form->addPostHtml() 1....
getFormFields()
Get an HTMLForm descriptor array.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.