* prepare manual conversion table
* @private
*/
- function prepareManualConv($convRule){
+ function prepareManualConv( $convRule ){
// use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title
$title = $convRule->getTitle();
- if($title){
+ if( $title ){
$this->mTitleFromFlag = true;
$this->mTitleDisplay = $title;
}
//apply manual conversion table to global table
$convTable = $convRule->getConvTable();
$action = $convRule->getRulesAction();
- foreach($convTable as $v=>$t) {
- if( !in_array($v,$this->mVariants) )continue;
+ foreach( $convTable as $v => $t ) {
+ if( !in_array( $v, $this->mVariants ) )continue;
if( $action=="add" ) {
- foreach($t as $from=>$to) {
+ foreach( $t as $from => $to ) {
// to ensure that $from and $to not be left blank
// so $this->translate() could always return a string
- if ($from || $to)
+ if ( $from || $to )
// more efficient than array_merge(), about 2.5 times.
$this->mManualAddTables[$v][$from] = $to;
}
}
- elseif ( $action=="remove" ) {
- foreach($t as $from=>$to) {
- if ($from || $to)
+ elseif ( $action == "remove" ) {
+ foreach ( $t as $from=>$to ) {
+ if ( $from || $to )
$this->mManualRemoveTables[$v][$from] = $to;
}
}
return $text;
}
- if($wgDisableLangConversion)
+ if ( $wgDisableLangConversion )
return $text;
$text = $this->convert( $text );
- $parser->mOutput->setTitleText( $this->mTitleDisplay );
+
+ if ( $this->mTitleFromFlag )
+ $parser->mOutput->setTitleText( $this->mTitleDisplay );
return $text;
}
* convert title
* @private
*/
- function convertTitle($text){
+ function convertTitle( $text ){
global $wgDisableTitleConversion, $wgUser;
// check for global param and __NOTC__ tag
}
// use the title from the T flag if any
- if($this->mTitleFromFlag){
+ if( $this->mTitleFromFlag ){
$this->mTitleFromFlag = false;
return $this->mTitleDisplay;
}
* @return string converted text
* @public
*/
- function convert( $text , $isTitle=false) {
+ function convert( $text, $isTitle = false ) {
$mw =& MagicWord::get( 'notitleconvert' );
if( $mw->matchAndRemove( $text ) )
// no conversion if redirecting
$mw =& MagicWord::get( 'redirect' );
- if( $mw->matchStart( $text ))
+ if( $mw->matchStart( $text ) )
return $text;
// for title convertion
- if ($isTitle) return $this->convertTitle($text);
+ if ( $isTitle ) return $this->convertTitle( $text );
$plang = $this->getPreferredVariant();
- $tarray = StringUtils::explode($this->mMarkup['end'], $text);
+ $tarray = StringUtils::explode( $this->mMarkup['end'], $text );
$text = '';
$marks = array();
- foreach($tarray as $txt) {
- $marked = explode($this->mMarkup['begin'], $txt, 2);
- if (array_key_exists(1, $marked)) {
+ foreach ( $tarray as $txt ) {
+ $marked = explode( $this->mMarkup['begin'], $txt, 2 );
+ if ( array_key_exists( 1, $marked ) ) {
$crule = new ConverterRule($marked[1], $this);
- $crule->parse($plang);
+ $crule->parse( $plang );
$marked[1] = $crule->getDisplay();
- $this->prepareManualConv($crule);
+ $this->prepareManualConv( $crule );
}
else
$marked[0] .= $this->mMarkup['end'];
- array_push($marks, $marked);
+ array_push( $marks, $marked );
}
$this->applyManualConv();
- foreach ($marks as $marked) {
+ foreach ( $marks as $marked ) {
if( $this->mDoContentConvert )
- $text .= $this->autoConvert($marked[0],$plang);
+ $text .= $this->autoConvert( $marked[0], $plang );
else
$text .= $marked[0];
- if( array_key_exists(1, $marked) )
+ if( array_key_exists( 1, $marked ) )
$text .= $marked[1];
}
// Remove the last delimiter (wasn't real)