r6882 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r6881‎ | r6882 | r6883 >
Date:02:47, 29 December 2004
Author:zhengzhu
Status:old
Tags:
Comment:
Added magic word MAG_NOTITLECONVERT to indicate that the title of the page do not need to be converted. Useful in zh:
Modified paths:
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageZh.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MagicWord.php
@@ -45,6 +45,7 @@
4646 define('MAG_NAMESPACE', 32);
4747 define('MAG_TOC', 33);
4848 define('MAG_GRAMMAR', 34);
 49+define('MAG_NOTITLECONVERT', 35);
4950
5051 $wgVariableIDs = array(
5152 MAG_CURRENTMONTH,
Index: trunk/phase3/languages/Language.php
@@ -235,7 +235,8 @@
236236 MAG_LOCALURL => array( 0, 'LOCALURL:' ),
237237 MAG_LOCALURLE => array( 0, 'LOCALURLE:' ),
238238 MAG_SERVER => array( 0, 'SERVER' ),
239 - MAG_GRAMMAR => array( 0, 'GRAMMAR:' )
 239+ MAG_GRAMMAR => array( 0, 'GRAMMAR:' ),
 240+ MAG_NOTITLECONVERT => array( 0, '__NOTITLECONVERT__', '__NOTC__'),
240241 );
241242
242243 #-------------------------------------------------------------------
Index: trunk/phase3/languages/LanguageZh.php
@@ -37,6 +37,7 @@
3838 var $mTables=false; //the mapping tables
3939 var $mTablesLoaded = false;
4040 var $mCacheKey;
 41+ var $mDoTitleConvert = true;
4142 function LanguageZh() {
4243 global $wgDBname;
4344 $this->mCacheKey = $wgDBname . ":zhtables";
@@ -76,6 +77,7 @@
7778
7879 $cached = $this->parseCachedTable( $wgMessageCache->get( 'zhconversiontable/zh-hk', true, true, true ) );
7980 $this->mTables['zh-hk'] = array_merge($this->mTables['zh-hk'], $cached);
 81+
8082 }
8183 $wgMemc->set($this->mCacheKey, $this->mTables, 43200);
8284 }
@@ -204,16 +206,22 @@
205207 # -{text}- in which case no conversion should take place for text
206208 function convert( $text , $isTitle=false) {
207209 global $wgDisableLangConversion;
208 -
209210 if($wgDisableLangConversion)
210211 return $text;
211 -
 212+
 213+ $mw =& MagicWord::get( MAG_NOTITLECONVERT );
 214+ if( $mw->matchAndRemove( $text ) )
 215+ $this->mDoTitleConvert = false;
 216+
212217 // no conversion if redirecting
213 - if(strtolower( substr( $text,0,9 ) ) == "#redirect") {
 218+ $mw =& MagicWord::get( MAG_REDIRECT );
 219+ if( $mw->matchStart( $text ))
214220 return $text;
215 - }
216221
217222 if( $isTitle ) {
 223+ if( !$this->mDoTitleConvert )
 224+ return $text;
 225+
218226 global $wgRequest;
219227 $isredir = $wgRequest->getText( 'redirect', 'yes' );
220228 $action = $wgRequest->getText( 'action' );
@@ -221,8 +229,7 @@
222230 return $text;
223231 }
224232 else {
225 - $text = $this->convertTitle($text);
226 - return $text;
 233+ return $this->autoConvert($text);
227234 }
228235 }
229236
@@ -272,18 +279,6 @@
273280 }
274281
275282
276 - # only convert titles having more than one character
277 - function convertTitle($text) {
278 - $len=0;
279 - if( function_exists( 'mb_strlen' ) )
280 - $len = mb_strlen($text);
281 - else
282 - $len = strlen($text)/3;
283 - if($len>1)
284 - return $this->autoConvert( $text);
285 - return $text;
286 - }
287 -
288283 function getVariants() {
289284 return array("zh", "zh-cn", "zh-tw", "zh-sg", "zh-hk");
290285 }

Status & tagging log