r48984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48983‎ | r48984 | r48985 >
Date:08:55, 29 March 2009
Author:philip
Status:reverted (Comments)
Tags:
Comment:
Add group convertsion support for LanguageConverter. New magic word "{{GROUPCONVERT:xxx}}" enabled for this new feature. You can set related conversion rules in [[MediaWiki:Groupconversiontable-xxx]].
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -68,6 +68,7 @@
6969 $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH );
7070 $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
7171 $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) );
 72+ $parser->setFunctionHook( 'groupconvert', array( __CLASS__, 'groupconvert' ), SFH_NO_HASH );
7273
7374 if ( $wgAllowDisplayTitle ) {
7475 $parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), SFH_NO_HASH );
@@ -104,7 +105,7 @@
105106 $date = $df->reformat( $pref, $date, array('match-whole') );
106107 return $date;
107108 }
108 -
 109+
109110 static function ns( $parser, $part1 = '' ) {
110111 global $wgContLang;
111112 if ( intval( $part1 ) || $part1 == "0" ) {
@@ -616,4 +617,12 @@
617618 );
618619 return $parser->extensionSubstitution( $params, $frame );
619620 }
 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+ }
620629 }
Index: trunk/phase3/languages/LanguageConverter.php
@@ -34,6 +34,7 @@
3535 var $mFlags;
3636 var $mDescCodeSep = ':',$mDescVarSep = ';';
3737 var $mUcfirst = false;
 38+ var $mGroups = array();
3839
3940 const CACHE_VERSION_KEY = 'VERSION 6';
4041
@@ -414,7 +415,7 @@
415416 global $wgDisableLangConversion;
416417 /* don't do anything if this is the conversion table */
417418 if ( $parser->getTitle()->getNamespace() == NS_MEDIAWIKI &&
418 - strpos($parser->mTitle->getText(), "Conversiontable") !== false )
 419+ strpos($parser->mTitle->getText(), 'onversiontable') !== false )
419420 {
420421 return $text;
421422 }
@@ -663,7 +664,7 @@
664665 * load conversion tables either from the cache or the disk
665666 * @private
666667 */
667 - function loadTables($fromcache=true) {
 668+ function loadTables( $fromcache = true ) {
668669 global $wgMemc;
669670 if( $this->mTablesLoaded )
670671 return;
@@ -681,9 +682,14 @@
682683 // we will first load the default tables
683684 // then update them using things in MediaWiki:Zhconversiontable/*
684685 $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 );
688694 }
689695
690696 $this->postLoadTables();
@@ -731,24 +737,24 @@
732738 * and will be parsed recursively if $recursive=true
733739 *
734740 */
735 - function parseCachedTable($code, $subpage='', $recursive=true) {
 741+ function parseCachedTable($code, $subpage='', $recursive=true, $table='Conversiontable') {
736742 global $wgMessageCache;
737743 static $parsed = array();
738744
739745 if(!is_object($wgMessageCache))
740746 return array();
741747
742 - $key = 'Conversiontable/'.$code;
 748+ $key = "$table/".$code;
743749 if($subpage)
744750 $key .= '/' . $subpage;
745751
746752 if(array_key_exists($key, $parsed))
747753 return array();
748 -
 754+
749755 if ( strpos( $code, '/' ) === false ) {
750 - $txt = $wgMessageCache->get( 'Conversiontable', true, $code );
 756+ $txt = $wgMessageCache->get( $table, true, $code );
751757 } else {
752 - $title = Title::makeTitleSafe( NS_MEDIAWIKI, "Conversiontable/$code" );
 758+ $title = Title::makeTitleSafe( NS_MEDIAWIKI, "$table/$code" );
753759 if ( $title && $title->exists() ) {
754760 $article = new Article( $title );
755761 $txt = $article->getContents();
@@ -756,10 +762,9 @@
757763 $txt = '';
758764 }
759765 }
760 -
761766 // get all subpage links of the form
762767 // [[MediaWiki:conversiontable/zh-xx/...|...]]
763 - $linkhead = $this->mLangObj->getNsText(NS_MEDIAWIKI) . ':Conversiontable';
 768+ $linkhead = $this->mLangObj->getNsText(NS_MEDIAWIKI) . ":$table";
764769 $subs = explode('[[', $txt);
765770 $sublinks = array();
766771 foreach( $subs as $sub ) {
@@ -778,7 +783,6 @@
779784 }
780785 }
781786
782 -
783787 // parse the mappings in this page
784788 $blocks = explode($this->mMarkup['begin'], $txt);
785789 array_shift($blocks);
@@ -869,6 +873,17 @@
870874 $ret = $this->mMarkup['begin'] . 'R|' . $text . $this->mMarkup['end'];
871875 return $ret;
872876 }
 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+ }
873888 }
874889
875890 /**
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -339,6 +339,7 @@
340340 'staticredirect' => array( 1, '__STATICREDIRECT__' ),
341341 'protectionlevel' => array( 1, 'PROTECTIONLEVEL' ),
342342 'formatdate' => array( 0, 'formatdate', 'dateformat' ),
 343+ 'groupconvert' => array( 0, 'GROUPCONVERT:', 'GC:' ),
343344 );
344345
345346 /**
Index: trunk/phase3/languages/Language.php
@@ -46,6 +46,7 @@
4747 function convertCategoryKey( $key ) {return $key; }
4848 function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); }
4949 function armourMath($text){ return $text; }
 50+ function groupConvert($group) {return '';}
5051 }
5152
5253 /**
@@ -2290,6 +2291,16 @@
22912292 function markNoConversion( $text, $noParse=false ) {
22922293 return $this->mConverter->markNoConversion( $text, $noParse );
22932294 }
 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+ }
22942305
22952306 /**
22962307 * A regular expression to match legal word-trailing characters
Index: trunk/phase3/RELEASE-NOTES
@@ -154,6 +154,9 @@
155155 * Add CSS defintion of the 'wikitable' class to shared.css
156156 * (bug 17163) Added MediaWiki:Talkpage which will be displayed when viewing talk
157157 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]].
158161
159162 === Bug fixes in 1.15 ===
160163 * (bug 16968) Special:Upload no longer throws useless warnings.

Follow-up revisions

RevisionCommit summaryAuthorDate
r48985Follow up on r48984, RELEASE-NOTES modified.philip09:20, 29 March 2009
r51405Reverted r48984. Fragile, doesn't work if memcached is enabled. See CodeReview.tstarling14:51, 3 June 2009
r51406Follow-up to r51405 (Reverted r48984)....siebrand15:02, 3 June 2009

Comments

#Comment by Tim Starling (talk | contribs)   08:21, 19 May 2009

I don't see how this could work. Isn't loadTables() called before mGroups is filled?

#Comment by PhiLiP (talk | contribs)   17:28, 19 May 2009

loadTables() called after mGroups is filled. I have tested it on my own MediaWiki server (and passed) before I commit it.

#Comment by Tim Starling (talk | contribs)   14:48, 3 June 2009

Only because of luck, not good design. If any extension calls $wgParser->parse() before the primary wikitext is parsed, this will break. It's broken with memcached enabled, because the current set of group conversion tables is saved into memcached, merged with the default tables, and then used for every page regardless of the groups that that page defines. So it won't work on Wikimedia.

Status & tagging log