Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
— | — | @@ -68,6 +68,7 @@ |
69 | 69 | $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH ); |
70 | 70 | $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS ); |
71 | 71 | $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) ); |
| 72 | + $parser->setFunctionHook( 'groupconvert', array( __CLASS__, 'groupconvert' ), SFH_NO_HASH ); |
72 | 73 | |
73 | 74 | if ( $wgAllowDisplayTitle ) { |
74 | 75 | $parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), SFH_NO_HASH ); |
— | — | @@ -104,7 +105,7 @@ |
105 | 106 | $date = $df->reformat( $pref, $date, array('match-whole') ); |
106 | 107 | return $date; |
107 | 108 | } |
108 | | - |
| 109 | + |
109 | 110 | static function ns( $parser, $part1 = '' ) { |
110 | 111 | global $wgContLang; |
111 | 112 | if ( intval( $part1 ) || $part1 == "0" ) { |
— | — | @@ -616,4 +617,12 @@ |
617 | 618 | ); |
618 | 619 | return $parser->extensionSubstitution( $params, $frame ); |
619 | 620 | } |
| 621 | + |
| 622 | + /** |
| 623 | + * magic word call for a group convert from LanguageConverter. |
| 624 | + */ |
| 625 | + public static function groupconvert( $parser, $group ) { |
| 626 | + global $wgContLang; |
| 627 | + return $wgContLang->groupConvert( $group ); |
| 628 | + } |
620 | 629 | } |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | var $mFlags; |
36 | 36 | var $mDescCodeSep = ':',$mDescVarSep = ';'; |
37 | 37 | var $mUcfirst = false; |
| 38 | + var $mGroups = array(); |
38 | 39 | |
39 | 40 | const CACHE_VERSION_KEY = 'VERSION 6'; |
40 | 41 | |
— | — | @@ -414,7 +415,7 @@ |
415 | 416 | global $wgDisableLangConversion; |
416 | 417 | /* don't do anything if this is the conversion table */ |
417 | 418 | if ( $parser->getTitle()->getNamespace() == NS_MEDIAWIKI && |
418 | | - strpos($parser->mTitle->getText(), "Conversiontable") !== false ) |
| 419 | + strpos($parser->mTitle->getText(), 'onversiontable') !== false ) |
419 | 420 | { |
420 | 421 | return $text; |
421 | 422 | } |
— | — | @@ -663,7 +664,7 @@ |
664 | 665 | * load conversion tables either from the cache or the disk |
665 | 666 | * @private |
666 | 667 | */ |
667 | | - function loadTables($fromcache=true) { |
| 668 | + function loadTables( $fromcache = true ) { |
668 | 669 | global $wgMemc; |
669 | 670 | if( $this->mTablesLoaded ) |
670 | 671 | return; |
— | — | @@ -681,9 +682,14 @@ |
682 | 683 | // we will first load the default tables |
683 | 684 | // then update them using things in MediaWiki:Zhconversiontable/* |
684 | 685 | $this->loadDefaultTables(); |
685 | | - foreach($this->mVariants as $var) { |
686 | | - $cached = $this->parseCachedTable($var); |
687 | | - $this->mTables[$var]->mergeArray($cached); |
| 686 | + foreach( $this->mVariants as $var ) { |
| 687 | + $cached = $this->parseCachedTable( $var ); |
| 688 | + // load group convert table, e.g. [[MediaWiki:Groupconversiontable-StarTrek]]. |
| 689 | + foreach( $this->mGroups as $group ) { |
| 690 | + $cachedgroup = $this->parseCachedTable( $var, '', true, "Groupconversiontable-$group" ); |
| 691 | + $cached = array_merge( $cached, $cachedgroup ); |
| 692 | + } |
| 693 | + $this->mTables[$var]->mergeArray( $cached ); |
688 | 694 | } |
689 | 695 | |
690 | 696 | $this->postLoadTables(); |
— | — | @@ -731,24 +737,24 @@ |
732 | 738 | * and will be parsed recursively if $recursive=true |
733 | 739 | * |
734 | 740 | */ |
735 | | - function parseCachedTable($code, $subpage='', $recursive=true) { |
| 741 | + function parseCachedTable($code, $subpage='', $recursive=true, $table='Conversiontable') { |
736 | 742 | global $wgMessageCache; |
737 | 743 | static $parsed = array(); |
738 | 744 | |
739 | 745 | if(!is_object($wgMessageCache)) |
740 | 746 | return array(); |
741 | 747 | |
742 | | - $key = 'Conversiontable/'.$code; |
| 748 | + $key = "$table/".$code; |
743 | 749 | if($subpage) |
744 | 750 | $key .= '/' . $subpage; |
745 | 751 | |
746 | 752 | if(array_key_exists($key, $parsed)) |
747 | 753 | return array(); |
748 | | - |
| 754 | + |
749 | 755 | if ( strpos( $code, '/' ) === false ) { |
750 | | - $txt = $wgMessageCache->get( 'Conversiontable', true, $code ); |
| 756 | + $txt = $wgMessageCache->get( $table, true, $code ); |
751 | 757 | } else { |
752 | | - $title = Title::makeTitleSafe( NS_MEDIAWIKI, "Conversiontable/$code" ); |
| 758 | + $title = Title::makeTitleSafe( NS_MEDIAWIKI, "$table/$code" ); |
753 | 759 | if ( $title && $title->exists() ) { |
754 | 760 | $article = new Article( $title ); |
755 | 761 | $txt = $article->getContents(); |
— | — | @@ -756,10 +762,9 @@ |
757 | 763 | $txt = ''; |
758 | 764 | } |
759 | 765 | } |
760 | | - |
761 | 766 | // get all subpage links of the form |
762 | 767 | // [[MediaWiki:conversiontable/zh-xx/...|...]] |
763 | | - $linkhead = $this->mLangObj->getNsText(NS_MEDIAWIKI) . ':Conversiontable'; |
| 768 | + $linkhead = $this->mLangObj->getNsText(NS_MEDIAWIKI) . ":$table"; |
764 | 769 | $subs = explode('[[', $txt); |
765 | 770 | $sublinks = array(); |
766 | 771 | foreach( $subs as $sub ) { |
— | — | @@ -778,7 +783,6 @@ |
779 | 784 | } |
780 | 785 | } |
781 | 786 | |
782 | | - |
783 | 787 | // parse the mappings in this page |
784 | 788 | $blocks = explode($this->mMarkup['begin'], $txt); |
785 | 789 | array_shift($blocks); |
— | — | @@ -869,6 +873,17 @@ |
870 | 874 | $ret = $this->mMarkup['begin'] . 'R|' . $text . $this->mMarkup['end']; |
871 | 875 | return $ret; |
872 | 876 | } |
| 877 | + |
| 878 | + /** |
| 879 | + * Callback function for magicword 'groupconvert' |
| 880 | + * |
| 881 | + * @param string $group: the group name called for |
| 882 | + * @return blank string |
| 883 | + */ |
| 884 | + function groupConvert( $group ) { |
| 885 | + $this->mGroups[] = $group; |
| 886 | + return ''; |
| 887 | + } |
873 | 888 | } |
874 | 889 | |
875 | 890 | /** |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -339,6 +339,7 @@ |
340 | 340 | 'staticredirect' => array( 1, '__STATICREDIRECT__' ), |
341 | 341 | 'protectionlevel' => array( 1, 'PROTECTIONLEVEL' ), |
342 | 342 | 'formatdate' => array( 0, 'formatdate', 'dateformat' ), |
| 343 | + 'groupconvert' => array( 0, 'GROUPCONVERT:', 'GC:' ), |
343 | 344 | ); |
344 | 345 | |
345 | 346 | /** |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -46,6 +46,7 @@ |
47 | 47 | function convertCategoryKey( $key ) {return $key; } |
48 | 48 | function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); } |
49 | 49 | function armourMath($text){ return $text; } |
| 50 | + function groupConvert($group) {return '';} |
50 | 51 | } |
51 | 52 | |
52 | 53 | /** |
— | — | @@ -2290,6 +2291,16 @@ |
2291 | 2292 | function markNoConversion( $text, $noParse=false ) { |
2292 | 2293 | return $this->mConverter->markNoConversion( $text, $noParse ); |
2293 | 2294 | } |
| 2295 | + |
| 2296 | + /** |
| 2297 | + * Callback function for magicword 'groupconvert' |
| 2298 | + * |
| 2299 | + * @param string $group: the group name called for |
| 2300 | + * @return blank string |
| 2301 | + */ |
| 2302 | + function groupConvert( $group ) { |
| 2303 | + return $this->mConverter->groupConvert( $group ); |
| 2304 | + } |
2294 | 2305 | |
2295 | 2306 | /** |
2296 | 2307 | * A regular expression to match legal word-trailing characters |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -154,6 +154,9 @@ |
155 | 155 | * Add CSS defintion of the 'wikitable' class to shared.css |
156 | 156 | * (bug 17163) Added MediaWiki:Talkpage which will be displayed when viewing talk |
157 | 157 | pages |
| 158 | +* Add group convertsion support for LanguageConverter. New magic word "{{GROUPCONVERT:xxx}}" |
| 159 | + enabled for this new feature. You can set related conversion rules in |
| 160 | + [[MediaWiki:Groupconversiontable-xxx]]. |
158 | 161 | |
159 | 162 | === Bug fixes in 1.15 === |
160 | 163 | * (bug 16968) Special:Upload no longer throws useless warnings. |