3fe66b5452efb690f30fef730e707d775fea0ea3
3 * Implements Special:PageLanguage
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
22 * @author Kunal Grover
27 * Special page for changing the content language of a page
29 * @ingroup SpecialPage
31 class SpecialPageLanguage
extends FormSpecialPage
{
33 * @var $goToUrl URL to go to if language change successful
37 public function __construct() {
38 parent
::__construct( 'PageLanguage', 'pagelang' );
41 protected function preText() {
42 $this->getOutput()->addModules( 'mediawiki.special.pageLanguage' );
45 protected function getFormFields() {
46 global $wgLanguageCode;
47 // Get default from the subpage of Special page
48 $defaultName = $this->par
;
51 $page['pagename'] = array(
53 'label-message' => 'pagelang-name',
54 'default' => $defaultName,
57 // Options for whether to use the default language or select language
58 $selectoptions = array(
59 (string)$this->msg( 'pagelang-use-default' )->escaped() => 1,
60 (string)$this->msg( 'pagelang-select-lang' )->escaped() => 2,
62 $page['selectoptions'] = array(
63 'id' => 'mw-pl-options',
65 'options' => $selectoptions,
69 // Building a language selector
70 $userLang = $this->getLanguage()->getCode();
71 $languages = Language
::fetchLanguageNames( $userLang, 'mwfile' );
74 foreach ( $languages as $code => $name ) {
75 $options["$code - $name"] = $code;
78 $page['languageSelector'] = array(
79 'id' => 'mw-pl-languageselector',
81 'options' => $options,
82 'label-message' => 'pagelang-language',
83 'default' => $wgLanguageCode
86 $page['language'] = array(
87 'id' => 'mw-pl-languagevalue',
89 'default' => $wgLanguageCode
95 public function alterForm( HTMLForm
$form ) {
96 $form->setDisplayFormat( 'vform' );
97 $form->setWrapperLegend( false );
104 public function onSubmit( array $data ) {
105 $title = Title
::newFromText( $data['pagename'] );
107 // Check if title is valid
112 // Get the default language for the wiki
113 // Returns the default since the page is not loaded from DB
114 $defLang = $title->getPageLanguage()->getCode();
116 $pageId = $title->getArticleID();
118 // Check if article exists
123 // Load the page language from DB
124 $dbw = wfGetDB( DB_MASTER
);
125 $langOld = $dbw->selectField(
128 array( 'page_id' => $pageId ),
132 // Url to redirect to after the operation
133 $this->goToUrl
= $title->getFullURL();
135 // Check if user wants to use default language
136 if ( $data['selectoptions'] == 1 ) {
139 $langNew = $data['language'];
142 // No change in language
143 if ( $langNew === $langOld ) {
147 // Hardcoded [def] if the language is set to null
148 $logOld = $langOld ?
$langOld : $defLang . '[def]';
149 $logNew = $langNew ?
$langNew : $defLang . '[def]';
151 // Writing new page language to database
152 $dbw = wfGetDB( DB_MASTER
);
155 array( 'page_lang' => $langNew ),
157 'page_id' => $pageId,
158 'page_lang' => $langOld
163 if ( !$dbw->affectedRows() ) {
167 // Logging change of language
169 '4::oldlanguage' => $logOld,
170 '5::newlanguage' => $logNew
172 $entry = new ManualLogEntry( 'pagelang', 'pagelang' );
173 $entry->setPerformer( $this->getUser() );
174 $entry->setTarget( $title );
175 $entry->setParameters( $logParams );
177 $logid = $entry->insert();
178 $entry->publish( $logid );
183 public function onSuccess() {
184 // Success causes a redirect
185 $this->getOutput()->redirect( $this->goToUrl
);