49 parent::__construct(
'PageLanguage',
'pagelang' );
59 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
60 return parent::preHtml();
67 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
69 $defaultPageLanguage = $this->contentHandlerFactory->getContentHandler( $title->getContentModel() )
70 ->getPageLanguage( $title );
72 $hasCustomLanguageSet = !$defaultPageLanguage->equals( $title->getPageLanguage() );
74 $hasCustomLanguageSet =
false;
80 'label-message' =>
'pagelang-name',
81 'default' => $title ? $title->getPrefixedText() : $defaultName,
82 'autofocus' => $defaultName ===
null,
88 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
89 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
91 $page[
'selectoptions'] = [
92 'id' =>
'mw-pl-options',
94 'options' => $selectoptions,
95 'default' => $hasCustomLanguageSet ? 2 : 1
100 'id' =>
'mw-pl-languageselector',
101 'cssclass' =>
'mw-languageselector',
102 'type' =>
'language',
104 'label-message' =>
'pagelang-language',
106 $title->getPageLanguage()->getCode() :
113 'label-message' =>
'pagelang-reason'
122 return $this->showLogFragment( $this->par );
134 $form->
setId(
'mw-pagelanguage-form' )
135 ->setSubmitTextMsg(
'pagelang-submit' );
143 $pageName = $data[
'pagename'];
146 if ( $data[
'selectoptions'] == 1 ) {
147 $newLanguage =
'default';
149 $newLanguage = $data[
'language'];
153 $title = Title::newFromTextThrow( $pageName );
159 $status = PermissionStatus::newEmpty();
160 if ( !$this->
getAuthority()->authorizeWrite(
'edit', $title, $status ) ) {
161 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
163 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
167 $this->goToUrl = $title->getFullUrlForRedirect(
168 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
175 $data[
'reason'] ??
'',
177 $this->dbProvider->getPrimaryDatabase()
193 $newLanguage, $reason =
"", array $tags = [], ?
IDatabase $dbw =
null ) {
201 return Status::newFatal(
202 'pagelang-nonexistent-page',
209 $oldLanguage = $dbw->newSelectQueryBuilder()
210 ->select(
'page_lang' )
212 ->where( [
'page_id' => $pageId ] )
213 ->caller( __METHOD__ )->fetchField();
216 if ( $newLanguage ===
'default' ) {
221 if ( $newLanguage === $oldLanguage ) {
223 if ( !$oldLanguage ) {
224 return Status::newFatal( ApiMessage::create(
226 'pagelang-unchanged-language-default',
229 'pagelang-unchanged-language'
232 return Status::newFatal(
233 'pagelang-unchanged-language',
240 $logOld = $oldLanguage ?: $defLang .
'[def]';
241 $logNew = $newLanguage ?: $defLang .
'[def]';
244 $pageUpdate = $dbw->newUpdateQueryBuilder()
246 ->set( [
'page_lang' => $newLanguage ] )
248 'page_id' => $pageId,
249 'page_lang' => $oldLanguage,
251 ->caller( __METHOD__ );
252 $pageUpdate->execute();
255 if ( !$dbw->affectedRows() ) {
256 return Status::newFatal(
'pagelang-db-failed' );
261 '4::oldlanguage' => $logOld,
262 '5::newlanguage' => $logNew
265 $entry->setPerformer( $context->
getUser() );
266 $entry->setTarget( $title );
267 $entry->setParameters( $logParams );
268 $entry->setComment( is_string( $reason ) ? $reason :
"" );
269 $entry->addTags( $tags );
271 $logid = $entry->insert();
272 $entry->publish( $logid );
277 return Status::newGood( (
object)[
278 'oldLanguage' => $logOld,
279 'newLanguage' => $logNew,
286 $this->
getOutput()->redirect( $this->goToUrl );
289 private function showLogFragment(
string $title ): string {
290 $moveLogPage = new
LogPage(
'pagelang' );
291 $out1 =
Html::element(
'h2', [], $moveLogPage->getName()->text() );
293 LogEventsList::showLogExtract( $out2,
'pagelang', $title );
294 return $out1 . $out2;
306 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
319class_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.
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(private readonly IContentHandlerFactory $contentHandlerFactory, private readonly LanguageNameUtils $languageNameUtils, private readonly IConnectionProvider $dbProvider, private readonly 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.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.