r7880 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7879‎ | r7880 | r7881 >
Date:05:50, 26 March 2005
Author:zhengzhu
Status:old
Tags:
Comment:
Support for manually converting article title to different Chinese variants (for language zh)
Modified paths:
  • /branches/REL1_4/phase3/RELEASE-NOTES (modified) (history)
  • /branches/REL1_4/phase3/languages/LanguageZh.php (modified) (history)

Diff [purge]

Index: branches/REL1_4/phase3/RELEASE-NOTES
@@ -451,7 +451,10 @@
452452 * (bug 1736) typo in SpecialValidate.php
453453 * (bug 73) Upload doesn't run edit updates on description page (links,
454454 search index and categories)
 455+* Support for manually converting article title to different Chinese
 456+ variants (for zh)
455457
 458+
456459 === Caveats ===
457460
458461 Some output, particularly involving user-supplied inline HTML, may not
Index: branches/REL1_4/phase3/languages/LanguageZh.php
@@ -40,6 +40,7 @@
4141 var $mTablesLoaded = false;
4242 var $mCacheKey;
4343 var $mDoTitleConvert = true, $mDoContentConvert = true;
 44+ var $mTitleDisplay=false;
4445 function LanguageZh() {
4546 global $wgDBname;
4647 $this->mCacheKey = $wgDBname . ":zhtables";
@@ -320,6 +321,8 @@
321322 if( $isTitle ) {
322323 if( !$this->mDoTitleConvert )
323324 return $text;
 325+ if( $this->mTitleDisplay!=false )
 326+ return $this->mTitleDisplay;
324327
325328 global $wgRequest;
326329 $isredir = $wgRequest->getText( 'redirect', 'yes' );
@@ -343,11 +346,28 @@
344347 $text = $this->autoConvert($tfirst);
345348 foreach($tarray as $txt) {
346349 $marked = explode("}-", $txt);
347 -
348 - $choice = explode(";", $marked{0});
 350+
 351+ //strip   since it interferes with the parsing, plus,
 352+ //all spaces should be stripped in this tag anyway.
 353+ $marked[0] = str_replace(' ', '', $marked[0]);
 354+
 355+ /* see if this conversion is specifically for the
 356+ article title. the format is
 357+ -{T|zh-cn:foo; zh-tw:bar}-
 358+ */
 359+ $fortitle = false;
 360+ $tt = explode("|", $marked[0], 2);
 361+ if(sizeof($tt) == 2 && trim($tt[0]) == 'T') {
 362+ $choice = explode(";", $tt[1]);
 363+ $fortitle = true;
 364+ }
 365+ else {
 366+ $choice = explode(";", $marked[0]);
 367+ }
 368+ $disp = '';
349369 if(!array_key_exists(1, $choice)) {
350370 /* a single choice */
351 - $text .= $choice{0};
 371+ $disp = $choice[0];
352372 } else {
353373 $choice1=false;
354374 $choice2=false;
@@ -357,8 +377,8 @@
358378 //syntax error in the markup, give up
359379 break;
360380 }
361 - $code = trim($v{0});
362 - $content = trim($v{1});
 381+ $code = trim($v[0]);
 382+ $content = trim($v[1]);
363383 if($code == $plang) {
364384 $choice1 = $content;
365385 break;
@@ -367,14 +387,18 @@
368388 $choice2 = $content;
369389 }
370390 if ( $choice1 )
371 - $text .= $choice1;
 391+ $disp = $choice1;
372392 elseif ( $choice2 )
373 - $text .= $choice2;
 393+ $disp = $choice2;
374394 else
375 - $text .= $marked{0};
 395+ $disp = $marked[0];
376396 }
 397+ if($fortitle)
 398+ $this->mTitleDisplay = $disp;
 399+ else
 400+ $text .= $disp;
377401 if(array_key_exists(1, $marked))
378 - $text .= $this->autoConvert($marked{1});
 402+ $text .= $this->autoConvert($marked[1]);
379403 }
380404
381405 return $text;

Status & tagging log