r72561 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72560‎ | r72561 | r72562 >
Date:22:37, 7 September 2010
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Remove $wgContLanguageCode usage in core.

sed -i 's/$wgContLanguageCode/$wgLanguageCode/g'
These are now the same, always. Per and since r15827.

$wgLanguageCode wins due to being the one set by LocalSettings.

$wgContLanguageCode definition at includes/Setup.php kept for now.
Modified paths:
  • /trunk/phase3/includes/ChangesFeed.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/Feed.php (modified) (history)
  • /trunk/phase3/includes/HTMLFileCache.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/includes/Metadata.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Preferences.php (modified) (history)
  • /trunk/phase3/includes/QueryPage.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/StreamFile.php (modified) (history)
  • /trunk/phase3/includes/StubObject.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFeedWatchlist.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialNewpages.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)
  • /trunk/phase3/maintenance/tests/MessageTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.inc
@@ -550,7 +550,6 @@
551551 'wgSitename' => 'MediaWiki',
552552 'wgServerName' => 'Britney-Spears',
553553 'wgLanguageCode' => $lang,
554 - 'wgContLanguageCode' => $lang,
555554 'wgDBprefix' => $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_',
556555 'wgRawHtml' => isset( $opts['rawhtml'] ),
557556 'wgLang' => null,
Index: trunk/phase3/maintenance/tests/MessageTest.php
@@ -3,9 +3,9 @@
44 class MessageTest extends PHPUnit_Framework_TestCase {
55
66 function setUp() {
7 - global $wgContLanguageCode;
 7+ global $wgLanguageCode;
88
9 - $wgContLanguageCode = 'en'; # For mainpage to be 'Main Page'
 9+ $wgLanguageCode = 'en'; # For mainpage to be 'Main Page'
1010 }
1111
1212 function testExists() {
Index: trunk/phase3/includes/Xml.php
@@ -214,14 +214,14 @@
215215 * @return array of label and select
216216 */
217217 public static function languageSelector( $selected, $customisedOnly = true ) {
218 - global $wgContLanguageCode;
 218+ global $wgLanguageCode;
219219 /**
220220 * Make sure the site language is in the list; a custom language code
221221 * might not have a defined name...
222222 */
223223 $languages = Language::getLanguageNames( $customisedOnly );
224 - if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
225 - $languages[$wgContLanguageCode] = $wgContLanguageCode;
 224+ if( !array_key_exists( $wgLanguageCode, $languages ) ) {
 225+ $languages[$wgLanguageCode] = $wgLanguageCode;
226226 }
227227 ksort( $languages );
228228
@@ -230,7 +230,7 @@
231231 * Otherwise, no default is selected and the user ends up
232232 * with an Afrikaans interface since it's first in the list.
233233 */
234 - $selected = isset( $languages[$selected] ) ? $selected : $wgContLanguageCode;
 234+ $selected = isset( $languages[$selected] ) ? $selected : $wgLanguageCode;
235235 $options = "\n";
236236 foreach( $languages as $code => $name ) {
237237 $options .= Xml::option( "$code - $name", $code, ($code == $selected) ) . "\n";
Index: trunk/phase3/includes/StubObject.php
@@ -122,8 +122,8 @@
123123 }
124124
125125 function _newObject() {
126 - global $wgContLanguageCode;
127 - $obj = Language::factory( $wgContLanguageCode );
 126+ global $wgLanguageCode;
 127+ $obj = Language::factory( $wgLanguageCode );
128128 $obj->initEncoding();
129129 $obj->initContLang();
130130 return $obj;
@@ -146,7 +146,7 @@
147147 }
148148
149149 function _newObject() {
150 - global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang;
 150+ global $wgLanguageCode, $wgRequest, $wgUser, $wgContLang;
151151 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
152152 // BCP 47 - letter case MUST NOT carry meaning
153153 $code = strtolower( $code );
@@ -154,10 +154,10 @@
155155 # Validate $code
156156 if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) || ( $code === 'qqq' ) ) {
157157 wfDebug( "Invalid user language code\n" );
158 - $code = $wgContLanguageCode;
 158+ $code = $wgLanguageCode;
159159 }
160160
161 - if( $code === $wgContLanguageCode ) {
 161+ if( $code === $wgLanguageCode ) {
162162 return $wgContLang;
163163 } else {
164164 $obj = Language::factory( $code );
Index: trunk/phase3/includes/parser/Parser.php
@@ -2785,8 +2785,8 @@
27862786 case 'directionmark':
27872787 return $wgContLang->getDirMark();
27882788 case 'contentlanguage':
2789 - global $wgContLanguageCode;
2790 - return $wgContLanguageCode;
 2789+ global $wgLanguageCode;
 2790+ return $wgLanguageCode;
27912791 default:
27922792 $ret = null;
27932793 if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) ) {
Index: trunk/phase3/includes/MessageCache.php
@@ -334,7 +334,7 @@
335335 */
336336 function loadFromDB( $code ) {
337337 wfProfileIn( __METHOD__ );
338 - global $wgMaxMsgCacheEntrySize, $wgContLanguageCode, $wgAdaptiveMessageCache;
 338+ global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
339339 $dbr = wfGetDB( DB_SLAVE );
340340 $cache = array();
341341
@@ -347,14 +347,14 @@
348348 $mostused = array();
349349 if ( $wgAdaptiveMessageCache ) {
350350 $mostused = $this->getMostUsedMessages();
351 - if ( $code !== $wgContLanguageCode ) {
 351+ if ( $code !== $wgLanguageCode ) {
352352 foreach ( $mostused as $key => $value ) $mostused[$key] = "$value/$code";
353353 }
354354 }
355355
356356 if ( count( $mostused ) ) {
357357 $conds['page_title'] = $mostused;
358 - } elseif ( $code !== $wgContLanguageCode ) {
 358+ } elseif ( $code !== $wgLanguageCode ) {
359359 $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), "/$code" );
360360 } else {
361361 # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
@@ -534,7 +534,7 @@
535535 * "msg/lang".
536536 */
537537 function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
538 - global $wgContLanguageCode, $wgContLang;
 538+ global $wgLanguageCode, $wgContLang;
539539
540540 if ( !is_string( $key ) ) {
541541 throw new MWException( "Non-string key given" );
@@ -568,7 +568,7 @@
569569 # Try the MediaWiki namespace
570570 if( !$this->mDisable && $useDB ) {
571571 $title = $uckey;
572 - if(!$isFullKey && ( $langcode != $wgContLanguageCode ) ) {
 572+ if(!$isFullKey && ( $langcode != $wgLanguageCode ) ) {
573573 $title .= '/' . $langcode;
574574 }
575575 $message = $this->getMsgFromNamespace( $title, $langcode );
@@ -599,8 +599,8 @@
600600 # Is this a custom message? Try the default language in the db...
601601 if( ($message === false || $message === '-' ) &&
602602 !$this->mDisable && $useDB &&
603 - !$isFullKey && ($langcode != $wgContLanguageCode) ) {
604 - $message = $this->getMsgFromNamespace( $uckey, $wgContLanguageCode );
 603+ !$isFullKey && ($langcode != $wgLanguageCode) ) {
 604+ $message = $this->getMsgFromNamespace( $uckey, $wgLanguageCode );
605605 }
606606
607607 # Final fallback
@@ -813,15 +813,15 @@
814814 }
815815
816816 public function figureMessage( $key ) {
817 - global $wgContLanguageCode;
 817+ global $wgLanguageCode;
818818 $pieces = explode( '/', $key );
819819 if( count( $pieces ) < 2 )
820 - return array( $key, $wgContLanguageCode );
 820+ return array( $key, $wgLanguageCode );
821821
822822 $lang = array_pop( $pieces );
823823 $validCodes = Language::getLanguageNames();
824824 if( !array_key_exists( $lang, $validCodes ) )
825 - return array( $key, $wgContLanguageCode );
 825+ return array( $key, $wgLanguageCode );
826826
827827 $message = implode( '/', $pieces );
828828 return array( $message, $lang );
Index: trunk/phase3/includes/Feed.php
@@ -137,8 +137,8 @@
138138 * @return String
139139 */
140140 public function getLanguage() {
141 - global $wgContLanguageCode;
142 - return $wgContLanguageCode;
 141+ global $wgLanguageCode;
 142+ return $wgLanguageCode;
143143 }
144144
145145 /**
Index: trunk/phase3/includes/Export.php
@@ -362,7 +362,7 @@
363363 * @return string
364364 */
365365 function openStream() {
366 - global $wgContLanguageCode;
 366+ global $wgLanguageCode;
367367 $ver = $this->schemaVersion();
368368 return Xml::element( 'mediawiki', array(
369369 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
@@ -370,7 +370,7 @@
371371 'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
372372 "http://www.mediawiki.org/xml/export-$ver.xsd",
373373 'version' => $ver,
374 - 'xml:lang' => $wgContLanguageCode ),
 374+ 'xml:lang' => $wgLanguageCode ),
375375 null ) .
376376 "\n" .
377377 $this->siteInfo();
Index: trunk/phase3/includes/ChangesFeed.php
@@ -27,8 +27,8 @@
2828 * @return ChannelFeed subclass or false on failure
2929 */
3030 public function getFeedObject( $title, $description ) {
31 - global $wgSitename, $wgContLanguageCode, $wgFeedClasses, $wgTitle;
32 - $feedTitle = "$wgSitename - {$title} [$wgContLanguageCode]";
 31+ global $wgSitename, $wgLanguageCode, $wgFeedClasses, $wgTitle;
 32+ $feedTitle = "$wgSitename - {$title} [$wgLanguageCode]";
3333 if( !isset($wgFeedClasses[$this->format] ) )
3434 return false;
3535 return new $wgFeedClasses[$this->format](
Index: trunk/phase3/includes/OutputPage.php
@@ -1569,7 +1569,7 @@
15701570 */
15711571 public function output() {
15721572 global $wgUser, $wgOutputEncoding, $wgRequest;
1573 - global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
 1573+ global $wgLanguageCode, $wgDebugRedirects, $wgMimeType;
15741574 global $wgUseAjax, $wgAjaxWatch;
15751575 global $wgEnableMWSuggest, $wgUniversalEditButton;
15761576 global $wgArticle;
@@ -1657,7 +1657,7 @@
16581658 ob_start();
16591659
16601660 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1661 - $wgRequest->response()->header( 'Content-language: ' . $wgContLanguageCode );
 1661+ $wgRequest->response()->header( 'Content-language: ' . $wgLanguageCode );
16621662
16631663 if ( $this->mArticleBodyOnly ) {
16641664 $this->out( $this->mBodytext );
Index: trunk/phase3/includes/api/ApiFeedWatchlist.php
@@ -54,7 +54,7 @@
5555 * Wrap the result as an RSS/Atom feed.
5656 */
5757 public function execute() {
58 - global $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgContLanguageCode;
 58+ global $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgLanguageCode;
5959
6060 try {
6161 $params = $this->extractRequestParams();
@@ -102,7 +102,7 @@
103103 $feedItems[] = $this->createFeedItem( $info );
104104 }
105105
106 - $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgContLanguageCode . ']';
 106+ $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgLanguageCode . ']';
107107 $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL();
108108
109109 $feed = new $wgFeedClasses[$params['feedformat']] ( $feedTitle, htmlspecialchars( wfMsgForContent( 'watchlist' ) ), $feedUrl );
@@ -114,7 +114,7 @@
115115 // Error results should not be cached
116116 $this->getMain()->setCacheMaxAge( 0 );
117117
118 - $feedTitle = $wgSitename . ' - Error - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgContLanguageCode . ']';
 118+ $feedTitle = $wgSitename . ' - Error - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgLanguageCode . ']';
119119 $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL();
120120
121121 $feedFormat = isset( $params['feedformat'] ) ? $params['feedformat'] : 'rss';
Index: trunk/phase3/includes/HTMLFileCache.php
@@ -134,7 +134,7 @@
135135
136136 /* Working directory to/from output */
137137 public function loadFromFileCache() {
138 - global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode;
 138+ global $wgOut, $wgMimeType, $wgOutputEncoding, $wgLanguageCode;
139139 wfDebug( __METHOD__ . "()\n");
140140 $filename = $this->fileCacheName();
141141 // Raw pages should handle cache control on their own,
@@ -142,7 +142,7 @@
143143 if( $this->mType !== 'raw' ) {
144144 $wgOut->sendCacheControl();
145145 header( "Content-Type: $wgMimeType; charset={$wgOutputEncoding}" );
146 - header( "Content-Language: $wgContLanguageCode" );
 146+ header( "Content-Language: $wgLanguageCode" );
147147 }
148148
149149 if( $this->useGzip() ) {
Index: trunk/phase3/includes/StreamFile.php
@@ -41,8 +41,8 @@
4242 return;
4343 }
4444
45 - global $wgContLanguageCode;
46 - header( "Content-Disposition: inline;filename*=utf-8'$wgContLanguageCode'" . urlencode( basename( $fname ) ) );
 45+ global $wgLanguageCode;
 46+ header( "Content-Disposition: inline;filename*=utf-8'$wgLanguageCode'" . urlencode( basename( $fname ) ) );
4747
4848 foreach ( $headers as $header ) {
4949 header( $header );
Index: trunk/phase3/includes/SkinTemplate.php
@@ -133,7 +133,7 @@
134134 */
135135 function outputPage( OutputPage $out ) {
136136 global $wgArticle, $wgUser, $wgLang, $wgContLang;
137 - global $wgScript, $wgStylePath, $wgContLanguageCode;
 137+ global $wgScript, $wgStylePath, $wgLanguageCode;
138138 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
139139 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
140140 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
@@ -426,7 +426,7 @@
427427 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
428428 global $wgBetterDirectionality;
429429 if ( $wgBetterDirectionality ) {
430 - $realBodyAttribs = array( 'lang' => $wgContLanguageCode, 'dir' => $wgContLang->getDir() );
 430+ $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
431431 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
432432 }
433433 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
Index: trunk/phase3/includes/specials/SpecialNewpages.php
@@ -374,10 +374,10 @@
375375 }
376376
377377 protected function feedTitle() {
378 - global $wgContLanguageCode, $wgSitename;
 378+ global $wgLanguageCode, $wgSitename;
379379 $page = SpecialPage::getPage( 'Newpages' );
380380 $desc = $page->getDescription();
381 - return "$wgSitename - $desc [$wgContLanguageCode]";
 381+ return "$wgSitename - $desc [$wgLanguageCode]";
382382 }
383383
384384 protected function feedItem( $row ) {
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -428,10 +428,10 @@
429429 }
430430
431431 protected function feedTitle() {
432 - global $wgContLanguageCode, $wgSitename;
 432+ global $wgLanguageCode, $wgSitename;
433433 $page = SpecialPage::getPage( 'Contributions' );
434434 $desc = $page->getDescription();
435 - return "$wgSitename - $desc [$wgContLanguageCode]";
 435+ return "$wgSitename - $desc [$wgLanguageCode]";
436436 }
437437
438438 protected function feedItem( $row ) {
Index: trunk/phase3/includes/Metadata.php
@@ -63,11 +63,11 @@
6464 }
6565
6666 protected function basics() {
67 - global $wgContLanguageCode, $wgSitename;
 67+ global $wgLanguageCode, $wgSitename;
6868
6969 $this->element( 'title', $this->mArticle->mTitle->getText() );
7070 $this->pageOrString( 'publisher', wfMsg( 'aboutpage' ), $wgSitename );
71 - $this->element( 'language', $wgContLanguageCode );
 71+ $this->element( 'language', $wgLanguageCode );
7272 $this->element( 'type', 'Text' );
7373 $this->element( 'format', 'text/html' );
7474 $this->element( 'identifier', $this->reallyFullUrl() );
Index: trunk/phase3/includes/Preferences.php
@@ -228,10 +228,10 @@
229229 }
230230
231231 // Language
232 - global $wgContLanguageCode;
 232+ global $wgLanguageCode;
233233 $languages = Language::getLanguageNames( false );
234 - if ( !array_key_exists( $wgContLanguageCode, $languages ) ) {
235 - $languages[$wgContLanguageCode] = $wgContLanguageCode;
 234+ if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
 235+ $languages[$wgLanguageCode] = $wgLanguageCode;
236236 }
237237 ksort( $languages );
238238
Index: trunk/phase3/includes/QueryPage.php
@@ -532,10 +532,10 @@
533533 }
534534
535535 function feedTitle() {
536 - global $wgContLanguageCode, $wgSitename;
 536+ global $wgLanguageCode, $wgSitename;
537537 $page = SpecialPage::getPage( $this->getName() );
538538 $desc = $page->getDescription();
539 - return "$wgSitename - $desc [$wgContLanguageCode]";
 539+ return "$wgSitename - $desc [$wgLanguageCode]";
540540 }
541541
542542 function feedDesc() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r72562Follow-up r72561. Missed language folder.platonides22:39, 7 September 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r15827$wgLanguageCode no longer indicates the user language, for that use $wgLang->...tstarling08:26, 26 July 2006

Comments

#Comment by Nikerabbit (talk | contribs)   07:30, 8 September 2010

I think $wgContLanguageCode would have been a better name.

#Comment by Siebrand (talk | contribs)   12:11, 8 September 2010

In svn extensions, only LanguageSelector uses $wgContLanguageCode. Would you consider cleaning that up, too?

#Comment by Platonides (talk | contribs)   13:12, 8 September 2010

I found many more instances in my grepping, that's why I deferred it to another commit.

I agree Nikerabbit, but all wikis have $wgLanguageCode in LocalSettings, not $wgContLanguageCode. Even for MW developers, $wgContLanguageCode is not a well known variable.

#Comment by Siebrand (talk | contribs)   13:29, 8 September 2010

Right. Apparently we no longer check out all extension in the translatewiki.net production folder, so I grepped an incomplete checkout. Sorry.

Status & tagging log