Kunalgrover05 has uploaded a new change for review. https://gerrit.wikimedia.org/r/135312
Change subject: First version of Page Language selector ...................................................................... First version of Page Language selector Using Special:PageLanguage to set the page language of a page. Added API method to get the page language. Bug: 35489 Change-Id: I0f82b146fbe948f917c1c5d29f7469644d797e80 --- M includes/AutoLoader.php M includes/Title.php M includes/WikiPage.php M includes/api/ApiQueryInfo.php M includes/installer/MysqlUpdater.php M includes/specialpage/SpecialPageFactory.php A includes/specials/SpecialPageLanguage.php M languages/i18n/en.json M languages/messages/MessagesEn.php A maintenance/archives/patch-page_lang.sql M maintenance/tables.sql 11 files changed, 178 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/12/135312/1 diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 338274c..becc9b9 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -1014,6 +1014,7 @@ 'SpecialMyuploads' => 'includes/specials/SpecialMyRedirectPages.php', 'SpecialNewFiles' => 'includes/specials/SpecialNewimages.php', 'SpecialNewpages' => 'includes/specials/SpecialNewpages.php', + 'SpecialPageLanguage' => 'includes/specials/SpecialPageLanguage.php', 'SpecialPasswordReset' => 'includes/specials/SpecialPasswordReset.php', 'SpecialPagesWithProp' => 'includes/specials/SpecialPagesWithProp.php', 'SpecialPermanentLink' => 'includes/specials/SpecialPermanentLink.php', diff --git a/includes/Title.php b/includes/Title.php index 67958ff..6844bee 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -147,8 +147,8 @@ /** @var bool Whether a page has any subpages */ private $mHasSubpages; - /** @var bool The (string) language code of the page's language and content code. */ - private $mPageLanguage = false; + /** @var string The (string) language code of the page's language and content code. */ + private $mPageLanguage = null; /** @var TitleValue A corresponding TitleValue object */ private $mTitleValue = null; @@ -421,6 +421,7 @@ * @param stdClass|bool $row Database row */ public function loadFromRow( $row ) { + global $wgLanguageCode; if ( $row ) { // page found if ( isset( $row->page_id ) ) { $this->mArticleID = (int)$row->page_id; @@ -438,6 +439,11 @@ $this->mContentModel = strval( $row->page_content_model ); } else { $this->mContentModel = false; # initialized lazily in getContentModel() + } + if ( isset( $row->page_lang ) ) { + $this->mPageLanguage = strval( $row->page_lang ); + } else { + $this->mPageLanguage = strval( $wgLanguageCode ); } } else { // page not found $this->mArticleID = 0; @@ -3316,7 +3322,7 @@ $this->mLatestID = false; $this->mContentModel = false; $this->mEstimateRevisions = null; - $this->mPageLanguage = false; + $this->mPageLanguage = null; } /** @@ -4968,6 +4974,29 @@ // special pages are in the user language wfProfileOut( __METHOD__ ); return $wgLang; + } else { + wfProfileOut( __METHOD__ ); + return wfGetLangObj( $this->mPageLanguage ); + } + } + + public function setPageLanguage( $lang ) { + $db = wfGetDB( DB_MASTER ); + $p = $this->getTitleValue(); + $title = substr( $p, strpos( $p, ':' )+1 ); + $db->update( 'page', array( 'page_lang' => $lang ), + array( + 'page_title' => $title, + ), + __METHOD__ + ); + } + /* global $wgLang, $wgLanguageCode; + wfProfileIn( __METHOD__ ); + if ( $this->isSpecialPage() ) { + // special pages are in the user language + wfProfileOut( __METHOD__ ); + return $wgLang; } if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) { @@ -4985,7 +5014,7 @@ } wfProfileOut( __METHOD__ ); return $langObj; - } + }*/ /** * Get the language in which the content of this page is written when diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 9a26c15..d131dfd 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -292,6 +292,7 @@ 'page_links_updated', 'page_latest', 'page_len', + 'page_lang', ); if ( $wgContentHandlerUseDB ) { diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index f160791..2b426f5 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -40,7 +40,7 @@ private $params, $titles, $missing, $everything, $pageCounter; private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched, - $pageLatest, $pageLength; + $pageLatest, $pageLength, $pageLanguage; private $protections, $watched, $watchers, $notificationtimestamps, $talkids, $subjectids, $displaytitles; @@ -71,6 +71,7 @@ $pageSet->requestField( 'page_touched' ); $pageSet->requestField( 'page_latest' ); $pageSet->requestField( 'page_len' ); + $pageSet->requestField( 'page_lang' ); if ( $wgContentHandlerUseDB ) { $pageSet->requestField( 'page_content_model' ); } @@ -303,6 +304,7 @@ $this->pageTouched = $pageSet->getCustomField( 'page_touched' ); $this->pageLatest = $pageSet->getCustomField( 'page_latest' ); $this->pageLength = $pageSet->getCustomField( 'page_len' ); + $this->pageLanguage = $pageSet->getCustomField( 'page_lang' ); // Get protection info if requested if ( $this->fld_protection ) { @@ -836,6 +838,7 @@ ApiBase::PROP_NULLABLE => true ), 'contentmodel' => 'string', + 'pagelanguage' => 'string', ), 'watched' => array( 'watched' => 'boolean' @@ -876,7 +879,7 @@ ), 'displaytitle' => array( 'displaytitle' => 'string' - ) + ), ); self::addTokenProperties( $props, $this->getTokenFunctions() ); diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 8b77cb1..018a5a2 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -229,7 +229,7 @@ array( 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ), array( 'doEnableProfiling' ), array( 'addField', 'uploadstash', 'us_props', 'patch-uploadstash-us_props.sql' ), - array( 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ), + array( 'modifyField', 'us0er_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ), array( 'modifyField', 'user_former_groups', 'ufg_group', 'patch-ufg_group-length-increase-255.sql' ), array( 'addIndex', 'page_props', 'pp_propname_page', @@ -254,6 +254,8 @@ // 1.24 array( 'addField', 'page_props', 'pp_sortkey', 'patch-pp_sortkey.sql' ), array( 'dropField', 'recentchanges', 'rc_cur_time', 'patch-drop-rc_cur_time.sql' ), + //array( 'addField', 'page', 'page_lang', 'patch-page_lang.sql' ), + array ( 'setPageLangs' ), ); } @@ -511,6 +513,7 @@ page_touched char(14) binary NOT NULL default '', page_latest int(8) unsigned NOT NULL, page_len int(8) unsigned NOT NULL, + page_lang varchar(32) NOT NULL, PRIMARY KEY page_id (page_id), UNIQUE INDEX name_title (page_namespace,page_title), @@ -1061,4 +1064,38 @@ 'Making iwl_prefix_title_from index non-UNIQUE' ); } + + protected function setPageLangs() { + if ( $this->db->fieldExists( 'page', 'page_lang', __METHOD__ ) ) { + $this->output( "...already have pagelangs field.\n" ); + + } + else { + $this->applyPatch( + 'patch-page_lang.sql', + false, + 'Setting page language for existing pages' + ); + // This part might not be needed as Brian Wolff suggested. + // Set the field as some value only if it is not the default wiki language. + /* + $page = $this->db->tableName( 'page' ); + $res = $this->db->query( " + SELECT page_title, page_lang + FROM $page", + __METHOD__ + ); + + foreach ( $res as $row ) { + $lang = Title::newFromRow( $row )->getPageLanguage()->getCode(); + $sql = "UPDATE $page + SET page_lang = '$lang' + WHERE page_title = '$row->page_title'"; + + $this->db->query( $sql, __METHOD__ ); + $this->output( "done.\n" ); + } + */ + } + } } diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index 53cef7f..74a1f38 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -79,6 +79,7 @@ 'Categories' => 'SpecialCategories', 'Listredirects' => 'ListredirectsPage', 'PagesWithProp' => 'SpecialPagesWithProp', + 'PageLanguage' => 'SpecialPageLanguage', 'TrackingCategories' => 'SpecialTrackingCategories', // Login/create account diff --git a/includes/specials/SpecialPageLanguage.php b/includes/specials/SpecialPageLanguage.php new file mode 100644 index 0000000..35271ba --- /dev/null +++ b/includes/specials/SpecialPageLanguage.php @@ -0,0 +1,90 @@ +<?php +/** + * Implements Special:PageLanguage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup SpecialPage + */ + +/** + * A special page that allows to set page language + * + * @ingroup SpecialPage + * @since 1.23 + */ + +class SpecialPageLanguage extends SpecialPage { + + function __construct() { + parent::__construct( 'PageLanguage' ); + } + + function execute( $par ) { + $request = $this->getRequest(); + $this->setHeaders(); + $this->outputHeader(); + $out = $this->getOutput(); + $out->allowClickjacking(); + $out->addHTML( $this->buildForm() ); + + // GET values + $page = $request->getVal( 'page' ); + $lang = $request->getVal( 'lang' ); + + if( isset( $page ) && isset( $lang )) { + $title = Title::newFromText( $page ); + $title->setPageLanguage( $lang ); + } + } + + function buildForm() { + global $wgScript; + $out = ''; + + $title = $this->getTitle(); + + $langSelect = Xml::languageSelector( 'en', false, null, array( 'name' => 'lang' ) ); + + $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); + $out .= Html::hidden( 'title', $title->getPrefixedText() ); + $out .= Xml::openElement( 'fieldset' ); + $out .= Xml::element( 'legend', null, 'Language Selector' ); + $out .= Xml::openElement( 'table', array( 'id' => 'lang-select', 'class' => 'allpages' ) ); + $out .= "<tr> + <td class='mw-label'>" . + Xml::label( 'Page name', 'page-name' ) . + " </td> + <td class='mw-input'>" . + Xml::input( 'page', 30 ) . + " </td>\n + </tr>" . + " <tr>\n + <td class=\"mw-label\">" . $langSelect[0] . "</td>\n + <td class=\"mw-input\">" . $langSelect[1] . "</td>\n + </tr>" . + " <td class='mw-input'>" . + Xml::submitButton( 'Submit' ) . + " </td> + </tr>"; + $out .= Xml::closeElement( 'table' ); + $out .= Xml::closeElement( 'fieldset' ); + $out .= Xml::closeElement( 'form' ); + + return $out; + } +} \ No newline at end of file diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 27a08c4..465a324 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3530,5 +3530,7 @@ "expand_templates_remove_nowiki": "Suppress <nowiki> tags in result", "expand_templates_generate_xml": "Show XML parse tree", "expand_templates_generate_rawhtml": "Show raw HTML", - "expand_templates_preview": "Preview" + "expand_templates_preview": "Preview", + "pagelanguage": "Page language selector", + "pagelanguage-summary": "This page is used to set the content language for mediawiki pages." } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 39036d7..b2445d8 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -444,6 +444,7 @@ 'Myuploads' => array( 'MyUploads', 'MyFiles' ), 'Newimages' => array( 'NewFiles', 'NewImages' ), 'Newpages' => array( 'NewPages' ), + 'PageLanguage' => array( 'PageLanguage' ), 'PagesWithProp' => array( 'PagesWithProp', 'Pageswithprop', 'PagesByProp', 'Pagesbyprop' ), 'PasswordReset' => array( 'PasswordReset' ), 'PermanentLink' => array( 'PermanentLink', 'PermaLink' ), diff --git a/maintenance/archives/patch-page_lang.sql b/maintenance/archives/patch-page_lang.sql new file mode 100644 index 0000000..81b4cef --- /dev/null +++ b/maintenance/archives/patch-page_lang.sql @@ -0,0 +1,2 @@ +ALTER TABLE /*$wgDBprefix*/page + ADD page_lang varchar(32) DEFAULT NULL; \ No newline at end of file diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 1b8d618..02ca47d 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -275,7 +275,9 @@ page_len int unsigned NOT NULL, -- content model, see CONTENT_MODEL_XXX constants - page_content_model varbinary(32) DEFAULT NULL + page_content_model varbinary(32) DEFAULT NULL, + + page_len varchar(10) DEFAULT NULL ) /*$wgDBTableOptions*/; CREATE UNIQUE INDEX /*i*/name_title ON /*_*/page (page_namespace,page_title); -- To view, visit https://gerrit.wikimedia.org/r/135312 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0f82b146fbe948f917c1c5d29f7469644d797e80 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Kunalgrover05 <kunalgrove...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits