r97849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97848‎ | r97849 | r97850 >
Date:20:31, 22 September 2011
Author:robin
Status:resolved
Tags:
Comment:
Re-do r96798 ("LanguageConverter now depends on the page content language"), without the change in WikiPage which caused an infinite loop (see bug 31098)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SkinLegacy.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -61,6 +61,8 @@
6262 to stop it from replace an already existing default sort, and suppress error.
6363 * (bug 18578) Rewrote revision delete related messages to allow better
6464 localisation
 65+* (bug 30364) LanguageConverter now depends on the page content language
 66+ instead of the wiki content language
6567
6668 === Bug fixes in 1.19 ===
6769 * $wgUploadNavigationUrl should be used for file redlinks if
Index: trunk/phase3/includes/parser/Parser.php
@@ -321,7 +321,7 @@
322322 * to internalParse() which does all the real work.
323323 */
324324
325 - global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
 325+ global $wgUseTidy, $wgAlwaysUseTidy, $wgDisableLangConversion, $wgDisableTitleConversion;
326326 $fname = __METHOD__.'-' . wfGetCaller();
327327 wfProfileIn( __METHOD__ );
328328 wfProfileIn( $fname );
@@ -376,8 +376,7 @@
377377 # The position of the convert() call should not be changed. it
378378 # assumes that the links are all replaced and the only thing left
379379 # is the <nowiki> mark.
380 -
381 - $text = $wgContLang->convert( $text );
 380+ $text = $this->getFunctionLang()->convert( $text );
382381 }
383382
384383 /**
@@ -393,11 +392,11 @@
394393 || isset( $this->mDoubleUnderscores['notitleconvert'] )
395394 || $this->mOutput->getDisplayTitle() !== false ) )
396395 {
397 - $convruletitle = $wgContLang->getConvRuleTitle();
 396+ $convruletitle = $this->getFunctionLang()->getConvRuleTitle();
398397 if ( $convruletitle ) {
399398 $this->mOutput->setTitleText( $convruletitle );
400399 } else {
401 - $titleText = $wgContLang->convertTitle( $title );
 400+ $titleText = $this->getFunctionLang()->convertTitle( $title );
402401 $this->mOutput->setTitleText( $titleText );
403402 }
404403 }
@@ -1194,7 +1193,6 @@
11951194 * @private
11961195 */
11971196 function makeFreeExternalLink( $url ) {
1198 - global $wgContLang;
11991197 wfProfileIn( __METHOD__ );
12001198
12011199 $trail = '';
@@ -1227,7 +1225,7 @@
12281226 $text = $this->maybeMakeExternalImage( $url );
12291227 if ( $text === false ) {
12301228 # Not an image, make a link
1231 - $text = Linker::makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
 1229+ $text = Linker::makeExternalLink( $url, $this->getFunctionLang()->markNoConversion($url), true, 'free',
12321230 $this->getExternalLinkAttribs( $url ) );
12331231 # Register it in the output object...
12341232 # Replace unnecessary URL escape codes with their equivalent characters
@@ -1455,7 +1453,6 @@
14561454 * @return string
14571455 */
14581456 function replaceExternalLinks( $text ) {
1459 - global $wgContLang;
14601457 wfProfileIn( __METHOD__ );
14611458
14621459 $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
@@ -1501,7 +1498,7 @@
15021499 list( $dtrail, $trail ) = Linker::splitTrail( $trail );
15031500 }
15041501
1505 - $text = $wgContLang->markNoConversion( $text );
 1502+ $text = $this->getFunctionLang()->markNoConversion( $text );
15061503
15071504 $url = Sanitizer::cleanUrl( $url );
15081505
@@ -1658,8 +1655,6 @@
16591656 * @private
16601657 */
16611658 function replaceInternalLinks2( &$s ) {
1662 - global $wgContLang;
1663 -
16641659 wfProfileIn( __METHOD__ );
16651660
16661661 wfProfileIn( __METHOD__.'-setup' );
@@ -1683,7 +1678,7 @@
16841679 $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
16851680 $s = substr( $s, 1 );
16861681
1687 - $useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
 1682+ $useLinkPrefixExtension = $this->getFunctionLang()->linkPrefixExtension();
16881683 $e2 = null;
16891684 if ( $useLinkPrefixExtension ) {
16901685 # Match the end of a line for a word that's not followed by whitespace,
@@ -1709,8 +1704,8 @@
17101705 $prefix = '';
17111706 }
17121707
1713 - if ( $wgContLang->hasVariants() ) {
1714 - $selflink = $wgContLang->autoConvertToAllVariants( $this->mTitle->getPrefixedText() );
 1708+ if ( $this->getFunctionLang()->hasVariants() ) {
 1709+ $selflink = $this->getFunctionLang()->autoConvertToAllVariants( $this->mTitle->getPrefixedText() );
17151710 } else {
17161711 $selflink = array( $this->mTitle->getPrefixedText() );
17171712 }
@@ -1878,6 +1873,7 @@
18791874
18801875 # Link not escaped by : , create the various objects
18811876 if ( $noforce ) {
 1877+ global $wgContLang;
18821878
18831879 # Interwikis
18841880 wfProfileIn( __METHOD__."-interwiki" );
@@ -1927,7 +1923,7 @@
19281924 }
19291925 $sortkey = Sanitizer::decodeCharReferences( $sortkey );
19301926 $sortkey = str_replace( "\n", '', $sortkey );
1931 - $sortkey = $wgContLang->convertCategoryKey( $sortkey );
 1927+ $sortkey = $this->getFunctionLang()->convertCategoryKey( $sortkey );
19321928 $this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
19331929
19341930 /**
@@ -3028,7 +3024,7 @@
30293025 * @private
30303026 */
30313027 function braceSubstitution( $piece, $frame ) {
3032 - global $wgContLang, $wgNonincludableNamespaces, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
 3028+ global $wgNonincludableNamespaces, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
30333029 wfProfileIn( __METHOD__ );
30343030 wfProfileIn( __METHOD__.'-setup' );
30353031
@@ -3129,7 +3125,7 @@
31303126 $function = $this->mFunctionSynonyms[1][$function];
31313127 } else {
31323128 # Case insensitive functions
3133 - $function = $wgContLang->lc( $function );
 3129+ $function = $this->getFunctionLang()->lc( $function );
31343130 if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
31353131 $function = $this->mFunctionSynonyms[0][$function];
31363132 } else {
@@ -3205,8 +3201,8 @@
32063202 }
32073203 $titleText = $title->getPrefixedText();
32083204 # Check for language variants if the template is not found
3209 - if ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) {
3210 - $wgContLang->findVariantLink( $part1, $title, true );
 3205+ if ( $this->getFunctionLang()->hasVariants() && $title->getArticleID() == 0 ) {
 3206+ $this->getFunctionLang()->findVariantLink( $part1, $title, true );
32113207 }
32123208 # Do recursion depth check
32133209 $limit = $this->mOptions->getMaxTemplateDepth();
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -275,11 +275,11 @@
276276 *
277277 * @since 1.17
278278 * @param $forOptions Array
279 - * @param $title Title: will be used to get the page content language (since r97636)
 279+ * @param $title Title: used to get the content language of the page (since r97636)
280280 * @return \string Page rendering hash
281281 */
282282 public function optionsHash( $forOptions, $title = null ) {
283 - global $wgContLang, $wgRenderHashAppend;
 283+ global $wgRenderHashAppend;
284284
285285 $confstr = '';
286286
@@ -323,7 +323,12 @@
324324
325325 // add in language specific options, if any
326326 // @todo FIXME: This is just a way of retrieving the url/user preferred variant
327 - $confstr .= $wgContLang->getExtraHashOptions();
 327+ if( !is_null( $title ) ) {
 328+ $confstr .= $title->getPageLanguage()->getExtraHashOptions();
 329+ } else {
 330+ global $wgContLang;
 331+ $confstr .= $wgContLang->getExtraHashOptions();
 332+ }
328333
329334 $confstr .= $wgRenderHashAppend;
330335
Index: trunk/phase3/includes/OutputPage.php
@@ -1654,12 +1654,12 @@
16551655 * /w/index.php?title=Main_page&variant=zh-cn should never be served.
16561656 */
16571657 function addAcceptLanguage() {
1658 - global $wgContLang;
1659 - if( !$this->getRequest()->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
1660 - $variants = $wgContLang->getVariants();
 1658+ $lang = $this->getTitle()->getPageLanguage();
 1659+ if( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
 1660+ $variants = $lang->getVariants();
16611661 $aloption = array();
16621662 foreach ( $variants as $variant ) {
1663 - if( $variant === $wgContLang->getCode() ) {
 1663+ if( $variant === $lang->getCode() ) {
16641664 continue;
16651665 } else {
16661666 $aloption[] = 'string-contains=' . $variant;
@@ -2614,7 +2614,7 @@
26152615 * have to be purged on configuration changes.
26162616 */
26172617 protected function getJSVars() {
2618 - global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
 2618+ global $wgUseAjax, $wgEnableMWSuggest;
26192619
26202620 $title = $this->getTitle();
26212621 $ns = $title->getNamespace();
@@ -2640,9 +2640,10 @@
26412641 'wgCategories' => $this->getCategories(),
26422642 'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
26432643 );
2644 - if ( $wgContLang->hasVariants() ) {
2645 - $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
2646 - }
 2644+ $lang = $this->getTitle()->getPageLanguage();
 2645+ if ( $lang->hasVariants() ) {
 2646+ $vars['wgUserVariant'] = $lang->getPreferredVariant();
 2647+ }
26472648 foreach ( $title->getRestrictionTypes() as $type ) {
26482649 $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
26492650 }
@@ -2693,7 +2694,7 @@
26942695 global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
26952696 $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
26962697 $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
2697 - $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang,
 2698+ $wgDisableLangConversion, $wgCanonicalLanguageLinks,
26982699 $wgRightsPage, $wgRightsUrl;
26992700
27002701 $tags = array();
@@ -2819,14 +2820,16 @@
28202821 ) );
28212822 }
28222823
 2824+ $lang = $this->getTitle()->getPageLanguage();
 2825+
28232826 # Language variants
28242827 if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
2825 - && $wgContLang->hasVariants() ) {
 2828+ && $lang->hasVariants() ) {
28262829
2827 - $urlvar = $wgContLang->getURLVariant();
 2830+ $urlvar = $lang->getURLVariant();
28282831
28292832 if ( !$urlvar ) {
2830 - $variants = $wgContLang->getVariants();
 2833+ $variants = $lang->getVariants();
28312834 foreach ( $variants as $_v ) {
28322835 $tags[] = Html::element( 'link', array(
28332836 'rel' => 'alternate',
Index: trunk/phase3/includes/Title.php
@@ -885,7 +885,7 @@
886886 */
887887 public function getLocalURL( $query = '', $variant = false ) {
888888 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
889 - global $wgVariantArticlePath, $wgContLang;
 889+ global $wgVariantArticlePath;
890890
891891 if ( is_array( $query ) ) {
892892 $query = wfArrayToCGI( $query );
@@ -904,7 +904,7 @@
905905 } else {
906906 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
907907 if ( $query == '' ) {
908 - if ( $variant != false && $wgContLang->hasVariants() ) {
 908+ if ( $variant != false && $this->getPageLanguage()->hasVariants() ) {
909909 if ( !$wgVariantArticlePath ) {
910910 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
911911 } else {
Index: trunk/phase3/includes/SkinLegacy.php
@@ -269,13 +269,15 @@
270270 $s = '';
271271
272272 /* show links to different language variants */
273 - global $wgDisableLangConversion, $wgLang, $wgContLang;
 273+ global $wgDisableLangConversion, $wgLang;
274274
275 - $variants = $wgContLang->getVariants();
 275+ $lang = $this->getSkin()->getTitle()->getPageLanguage();
 276+ $variants = $lang->getVariants();
276277
277 - if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
 278+ if ( !$wgDisableLangConversion && sizeof( $variants ) > 1
 279+ && $title->getNamespace() != NS_SPECIAL ) {
278280 foreach ( $variants as $code ) {
279 - $varname = $wgContLang->getVariantname( $code );
 281+ $varname = $lang->getVariantname( $code );
280282
281283 if ( $varname == 'disable' ) {
282284 continue;
Index: trunk/phase3/includes/SkinTemplate.php
@@ -1011,16 +1011,21 @@
10121012 array( &$this, &$content_navigation ) );
10131013 }
10141014
 1015+ $pageLang = $title->getPageLanguage();
 1016+
10151017 // Gets list of language variants
1016 - $variants = $wgContLang->getVariants();
 1018+ $variants = $pageLang->getVariants();
10171019 // Checks that language conversion is enabled and variants exist
1018 - if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
1019 - // Gets preferred variant
1020 - $preferred = $wgContLang->getPreferredVariant();
 1020+ // And if it is not in the special namespace
 1021+ if( !$wgDisableLangConversion && count( $variants ) > 1
 1022+ && $title->getNamespace() != NS_SPECIAL ) {
 1023+ // Gets preferred variant (note that user preference is
 1024+ // only possible for wiki content language variant)
 1025+ $preferred = $pageLang->getPreferredVariant();
10211026 // Loops over each variant
10221027 foreach( $variants as $code ) {
10231028 // Gets variant name from language code
1024 - $varname = $wgContLang->getVariantname( $code );
 1029+ $varname = $pageLang->getVariantname( $code );
10251030 // Checks if the variant is marked as disabled
10261031 if( $varname == 'disable' ) {
10271032 // Skips this variant

Follow-up revisions

RevisionCommit summaryAuthorDate
r101291Bug 31098: Template loop through MediaWiki: messages (int: function) not bein...platonides22:22, 29 October 2011
r113001* Fix for r41340, r96405, r97849: introduce a function which gets the current...tstarling05:53, 5 March 2012
r113024Transitional patch for bug 34832: introduce a CI-style option to allow deploy...tstarling12:14, 5 March 2012
r113127Partial revert of r97849: the wgUserVariant variable is useful and used even ...tstarling11:11, 6 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96798(Bug 30364) LanguageConverter should depend on the page content language inst...robin17:56, 11 September 2011
r97636Re-do several things of r96798 in preparation of re-doing the rest (there's a...robin15:55, 20 September 2011
r97821Parser test for bug 31098, disabled of coursenikerabbit16:00, 22 September 2011

Status & tagging log