r45742 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45741‎ | r45742 | r45743 >
Date:19:14, 14 January 2009
Author:brion
Status:ok
Tags:
Comment:
Revert r45642 "* Fixing the caching issue by using -{T|xxx}- syntax (only applies on wiki with LanguageConverter class) * Improving the efficiency by using -{A|xxx}- syntax (only applies on wiki with LanguageConverter class) patches by PhiLiP"
Causes parser test regression and other problems noted in code review.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesZh_hans.php (modified) (history)
  • /trunk/phase3/maintenance/updateRestrictions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updateRestrictions.php
@@ -82,7 +82,7 @@
8383 // Kill any broken rows from previous imports
8484 $db->delete( 'page_restrictions', array( 'pr_level' => '' ) );
8585 // Kill other invalid rows
86 - $db->deleteJoin( 'page_restrictions', 'page', 'pr_page', 'page_id', array('page_namespace' => NS_MEDIAWIKI) );
 86+ #$db->deleteJoin( 'page_restrictions', 'page', 'pr_page', 'page_id', array('page_namespace' => NS_MEDIAWIKI) );
8787 echo "...Done!\n";
8888 }
8989
Index: trunk/phase3/includes/parser/Parser.php
@@ -3310,7 +3310,6 @@
33113311 throw new MWException( '<html> extension tag encountered unexpectedly' );
33123312 }
33133313 case 'nowiki':
3314 - $content = strtr($content, array('-{' => '-&#123;', '}-' => '&#125;-'));
33153314 $output = Xml::escapeTagsOnly( $content );
33163315 break;
33173316 case 'math':
Index: trunk/phase3/languages/LanguageConverter.php
@@ -13,7 +13,7 @@
1414 * @ingroup Language
1515 *
1616 * @author Zhengzhu Feng <zhengzhu@gmail.com>
17 - * @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com>, PhiLiP <philip.npc@gmail.com>
 17+ * @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com>
1818 */
1919 class LanguageConverter {
2020 var $mPreferredVariant='';
@@ -21,8 +21,6 @@
2222 var $mVariants, $mVariantFallbacks, $mVariantNames;
2323 var $mTablesLoaded = false;
2424 var $mTables;
25 - var $mManualAddTables;
26 - var $mManualRemoveTables;
2725 var $mTitleDisplay='';
2826 var $mDoTitleConvert=true, $mDoContentConvert=true;
2927 var $mManualLevel; // 'bidirectional' 'unidirectional' 'disable' for each variants
@@ -83,13 +81,10 @@
8482 'N'=>'N' // current variant name
8583 );
8684 $this->mFlags = array_merge($f, $flags);
87 - foreach( $this->mVariants as $v) {
 85+ foreach( $this->mVariants as $v)
8886 $this->mManualLevel[$v]=array_key_exists($v,$manualLevel)
8987 ?$manualLevel[$v]
9088 :'bidirectional';
91 - $this->mManualAddTables[$v] = array();
92 - $this->mManualRemoveTables[$v] = array();
93 - }
9489 }
9590
9691 /**
@@ -328,12 +323,13 @@
329324
330325 return $ret;
331326 }
332 -
 327+
 328+
333329 /**
334 - * prepare manual conversion table
 330+ * apply manual conversion
335331 * @private
336332 */
337 - function prepareManualConv($convRule){
 333+ function applyManualConv($convRule){
338334 // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title
339335 $title = $convRule->getTitle();
340336 if($title){
@@ -346,33 +342,14 @@
347343 $action = $convRule->getRulesAction();
348344 foreach($convTable as $v=>$t) {
349345 if( !in_array($v,$this->mVariants) )continue;
350 - if( $action=="add" ) {
351 - foreach($t as $from=>$to) {
352 - // more efficient than array_merge(), about 2.5 times.
353 - $this->mManualAddTables[$v][$from] = $to;
354 - }
355 - }
 346+ if( $action=="add" )
 347+ $this->mTables[$v]->mergeArray($t);
356348 elseif ( $action=="remove" )
357 - $this->mManualRemoveTables[$v] = array_merge($this->mManualRemoveTables[$v], $t);
 349+ $this->mTables[$v]->removeArray($t);
358350 }
359351 }
360352
361353 /**
362 - * apply manual conversion from $this->mManualAddTables and $this->mManualRemoveTables
363 - * @private
364 - */
365 - function applyManualConv(){
366 - //apply manual conversion table to global table
367 - foreach($this->mVariants as $v) {
368 - if (count($this->mManualAddTables[$v]) > 0) {
369 - $this->mTables[$v]->mergeArray($this->mManualAddTables[$v]);
370 - }
371 - if (count($this->mManualRemoveTables[$v]) > 0)
372 - $this->mTables[$v]->removeArray($this->mManualRemoveTables[$v]);
373 - }
374 - }
375 -
376 - /**
377354 * Convert text using a parser object for context
378355 * @public
379356 */
@@ -461,27 +438,33 @@
462439 $plang = $this->getPreferredVariant();
463440 $tarray = StringUtils::explode($this->mMarkup['end'], $text);
464441 $text = '';
465 -
466 - $marks = array();
 442+ $lastDelim = false;
467443 foreach($tarray as $txt) {
468444 $marked = explode($this->mMarkup['begin'], $txt, 2);
469 - if (array_key_exists(1, $marked)) {
470 - $crule = new ConverterRule($marked[1], $this);
471 - $crule->parse($plang);
472 - $marked[1] = $crule->getDisplay();
473 - $this->prepareManualConv($crule);
474 - }
475 - array_push($marks, $marked);
476 - }
477 - $this->applyManualConv();
478 - foreach ($marks as $marked) {
 445+
479446 if( $this->mDoContentConvert )
480447 $text .= $this->autoConvert($marked[0],$plang);
481448 else
482449 $text .= $marked[0];
483 - if( array_key_exists(1, $marked) )
484 - $text .= $marked[1];
 450+
 451+ if(array_key_exists(1, $marked)){
 452+ // strip the flags from syntax like -{T| ... }-
 453+ $crule = new ConverterRule($marked[1], $this);
 454+ $crule->parse($plang);
 455+
 456+ $text .= $crule->getDisplay();
 457+ $this->applyManualConv($crule);
 458+ $lastDelim = false;
 459+ } else {
 460+ // Reinsert the }- which wasn't part of anything
 461+ $text .= $this->mMarkup['end'];
 462+ $lastDelim = true;
 463+ }
485464 }
 465+ if ( $lastDelim ) {
 466+ // Remove the last delimiter (wasn't real)
 467+ $text = substr( $text, 0, -strlen( $this->mMarkup['end'] ) );
 468+ }
486469
487470 return $text;
488471 }
@@ -817,7 +800,6 @@
818801 * @ingroup Language
819802 * @author fdcn <fdcn64@gmail.com>
820803 */
821 -
822804 class ConverterRule {
823805 var $mText; // original text in -{text}-
824806 var $mConverter; // LanguageConverter object
Index: trunk/phase3/languages/messages/MessagesZh_hans.php
@@ -67,7 +67,6 @@
6868 'Preferences' => array( '参数设置' ),
6969 'Watchlist' => array( '监视列表' ),
7070 'Recentchanges' => array( '最近更改' ),
71 - 'Recentchangeslinked' => array( '链出更改' ),
7271 'Upload' => array( '上传文件' ),
7372 'Listfiles' => array( '文件列表' ),
7473 'Newimages' => array( '新建文件' ),
@@ -80,7 +79,7 @@
8180 'Uncategorizedcategories' => array( '未归类分类' ),
8281 'Uncategorizedimages' => array( '未归类文件' ),
8382 'Uncategorizedtemplates' => array( '未归类模版' ),
84 - 'Unusedcategories' => array( '未使用分类' ),
 83+ 'Unusedcategories' => array( '未使用的模板' ),
8584 'Unusedimages' => array( '未使用文件' ),
8685 'Wantedpages' => array( '待撰页面' ),
8786 'Wantedcategories' => array( '待撰分类' ),
Index: trunk/phase3/RELEASE-NOTES
@@ -39,10 +39,6 @@
4040 * (bug 16852) padleft and padright now accept multiletter pad characters
4141
4242 === Bug fixes in 1.15 ===
43 -* Fixing the caching issue by using -{T|xxx}- syntax (only applies on wiki with
44 - LanguageConverter class)
45 -* Improving the efficiency by using -{A|xxx}- syntax (only applies on wiki with
46 - LanguageConverter class)
4743 * (bug 16968) Special:Upload no longer throws useless warnings.
4844 * (bug 15470) Special:Upload no longer force-capitalizes titles
4945 * (bug 17000) Special:RevisionDelete now checks if the database is locked before

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r45642* Fixing the caching issue by using -{T|xxx}- syntax (only applies on wiki wi...shinjiman16:13, 10 January 2009

Status & tagging log