47 private $contentHandlerFactory;
50 private $languageNameUtils;
53 private $loadBalancer;
56 private $searchEngineFactory;
70 parent::__construct(
'PageLanguage',
'pagelang' );
71 $this->contentHandlerFactory = $contentHandlerFactory;
72 $this->languageNameUtils = $languageNameUtils;
73 $this->loadBalancer = $loadBalancer;
74 $this->searchEngineFactory = $searchEngineFactory;
82 $this->
getOutput()->addModules(
'mediawiki.misc-authed-ooui' );
83 return parent::preHtml();
89 $title = $defaultName ? Title::newFromText( $defaultName ) :
null;
91 $defaultPageLanguage = $this->contentHandlerFactory->getContentHandler(
$title->getContentModel() )
92 ->getPageLanguage(
$title );
94 $hasCustomLanguageSet = !$defaultPageLanguage->equals(
$title->getPageLanguage() );
96 $hasCustomLanguageSet =
false;
100 $page[
'pagename'] = [
102 'label-message' =>
'pagelang-name',
103 'default' =>
$title ?
$title->getPrefixedText() : $defaultName,
104 'autofocus' => $defaultName ===
null,
110 (string)$this->
msg(
'pagelang-use-default' )->escaped() => 1,
111 (string)$this->
msg(
'pagelang-select-lang' )->escaped() => 2,
113 $page[
'selectoptions'] = [
114 'id' =>
'mw-pl-options',
116 'options' => $selectoptions,
117 'default' => $hasCustomLanguageSet ? 2 : 1
122 $languages = $this->languageNameUtils->getLanguageNames( $userLang, LanguageNameUtils::SUPPORTED );
124 foreach ( $languages as $code => $name ) {
125 $options[
"$code - $name"] = $code;
128 $page[
'language'] = [
129 'id' =>
'mw-pl-languageselector',
130 'cssclass' =>
'mw-languageselector',
132 'options' => $options,
133 'label-message' =>
'pagelang-language',
135 $title->getPageLanguage()->getCode() :
136 $this->
getConfig()->get( MainConfigNames::LanguageCode ),
142 'label-message' =>
'pagelang-reason'
150 return $this->showLogFragment( $this->par );
169 $pageName = $data[
'pagename'];
172 if ( $data[
'selectoptions'] == 1 ) {
173 $newLanguage =
'default';
175 $newLanguage = $data[
'language'];
179 $title = Title::newFromTextThrow( $pageName );
185 $status = PermissionStatus::newEmpty();
187 $wikitext = $this->
getOutput()->formatPermissionStatus( $status );
189 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
193 $this->goToUrl =
$title->getFullUrlForRedirect(
194 $title->isRedirect() ? [
'redirect' =>
'no' ] : []
201 $data[
'reason'] ??
'',
203 $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_PRIMARY )
219 $newLanguage, $reason =
"", array $tags = [],
IDatabase $dbw =
null ) {
221 $defLang = $context->
getConfig()->get( MainConfigNames::LanguageCode );
223 $pageId =
$title->getArticleID();
227 return Status::newFatal(
228 'pagelang-nonexistent-page',
235 $oldLanguage = $dbw->selectField(
238 [
'page_id' => $pageId ],
243 if ( $newLanguage ===
'default' ) {
248 if ( $newLanguage === $oldLanguage ) {
250 if ( !$oldLanguage ) {
251 return Status::newFatal( ApiMessage::create(
253 'pagelang-unchanged-language-default',
256 'pagelang-unchanged-language'
259 return Status::newFatal(
260 'pagelang-unchanged-language',
267 $logOld = $oldLanguage ?: $defLang .
'[def]';
268 $logNew = $newLanguage ?: $defLang .
'[def]';
273 [
'page_lang' => $newLanguage ],
275 'page_id' => $pageId,
276 'page_lang' => $oldLanguage
281 if ( !$dbw->affectedRows() ) {
282 return Status::newFatal(
'pagelang-db-failed' );
287 '4::oldlanguage' => $logOld,
288 '5::newlanguage' => $logNew
291 $entry->setPerformer( $context->
getUser() );
292 $entry->setTarget(
$title );
293 $entry->setParameters( $logParams );
294 $entry->setComment( is_string( $reason ) ? $reason :
"" );
295 $entry->addTags( $tags );
297 $logid = $entry->insert();
298 $entry->publish( $logid );
301 $title->invalidateCache();
303 return Status::newGood( (
object)[
304 'oldLanguage' => $logOld,
305 'newLanguage' => $logNew,
312 $this->
getOutput()->redirect( $this->goToUrl );
315 private function showLogFragment(
$title ) {
316 $moveLogPage =
new LogPage(
'pagelang' );
317 $out1 = Xml::element(
'h2',
null, $moveLogPage->getName()->text() );
319 LogEventsList::showLogExtract( $out2,
'pagelang',
$title );
320 return $out1 . $out2;
332 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
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.
Factory class for SearchEngine.
Special page for changing the content language of a page.
getFormFields()
Get an HTMLForm descriptor array.
postHtml()
Add post-HTML to the form.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
__construct(IContentHandlerFactory $contentHandlerFactory, LanguageNameUtils $languageNameUtils, ILoadBalancer $loadBalancer, SearchEngineFactory $searchEngineFactory)
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
static changePageLanguage(IContextSource $context, Title $title, $newLanguage, $reason="", array $tags=[], IDatabase $dbw=null)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
preHtml()
Add pre-HTML to the form.
doesWrites()
Indicates whether this special page may perform database writes.
getDisplayFormat()
Get display format for the form.
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
getConfig()
Shortcut to get main config object.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
getLanguage()
Shortcut to get user's language.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.