MediaWiki
REL1_22
|
00001 <?php 00024 require_once __DIR__ . '/../LanguageConverter.php'; 00025 00038 class ShiConverter extends LanguageConverter { 00039 00040 protected $mDoContentConvert; 00041 00042 public $mToLatin = array( 00043 'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e', 00044 'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x', 00045 'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n', 00046 'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵖ' => 'γ', 'ⵙ' => 's', 'ⵚ' => 'ṣ', 00047 'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z', 00048 'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ', 'ⵖ' => 'ɣ', 'ⵠ' => 'v', 'ⵒ' => 'p', 00049 ); 00050 00051 public $mUpperToLowerCaseLatin = array( 00052 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e', 00053 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j', 00054 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o', 00055 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't', 00056 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y', 00057 'Z' => 'z', 'Ɣ' => 'ɣ', 00058 ); 00059 00060 public $mToTifinagh = array( 00061 'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ', 00062 'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ', 00063 'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ', 00064 'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ', 00065 'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ', 00066 'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ', 'ɣ' => 'ⵖ', 'v' => 'ⵠ', 'p' => 'ⵒ', 00067 ); 00068 00069 function loadDefaultTables() { 00070 $this->mTables = array( 00071 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ), 00072 'shi-tfng' => new ReplacementArray( $this->mToTifinagh ), 00073 'shi-latn' => new ReplacementArray( $this->mToLatin ), 00074 'shi' => new ReplacementArray() 00075 ); 00076 } 00077 00088 function parseManualRule( $rule, $flags = array() ) { 00089 if ( in_array( 'T', $flags ) ) { 00090 return parent::parseManualRule( $rule, $flags ); 00091 } 00092 00093 $carray = array(); 00094 // otherwise ignore all formatting 00095 foreach ( $this->mVariants as $v ) { 00096 $carray[$v] = $rule; 00097 } 00098 00099 return $carray; 00100 } 00101 00109 function parserConvert( $text, &$parser ) { 00110 $this->mDoContentConvert = !( is_object( $parser->getTitle() ) && $parser->getTitle()->isTalkPage() ); 00111 00112 return parent::parserConvert( $text, $parser ); 00113 } 00114 00125 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) { 00126 // check for user namespace 00127 if ( is_object( $nt ) ) { 00128 $ns = $nt->getNamespace(); 00129 if ( $ns == NS_USER || $ns == NS_USER_TALK ) { 00130 return; 00131 } 00132 } 00133 00134 $oldlink = $link; 00135 parent::findVariantLink( $link, $nt, $ignoreOtherCond ); 00136 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) { 00137 $link = $oldlink; 00138 } 00139 } 00140 00150 function autoConvert( $text, $toVariant = false ) { 00151 global $wgTitle; 00152 if ( is_object( $wgTitle ) && $wgTitle->getNamespace() == NS_FILE ) { 00153 $imagename = $wgTitle->getNsText(); 00154 if ( preg_match( "/^$imagename:/", $text ) ) { 00155 return $text; 00156 } 00157 } 00158 return parent::autoConvert( $text, $toVariant ); 00159 } 00160 00169 function translate( $text, $toVariant ) { 00170 // If $text is empty or only includes spaces, do nothing 00171 // Otherwise translate it 00172 if ( trim( $text ) ) { 00173 $this->loadTables(); 00174 // To Tifinagh, first translate uppercase to lowercase Latin 00175 if ( $toVariant == 'shi-tfng' ) { 00176 $text = $this->mTables['lowercase']->replace( $text ); 00177 } 00178 $text = $this->mTables[$toVariant]->replace( $text ); 00179 } 00180 return $text; 00181 } 00182 } 00183 00189 class LanguageShi extends Language { 00190 function __construct() { 00191 global $wgHooks; 00192 00193 parent::__construct(); 00194 00195 $variants = array( 'shi', 'shi-tfng', 'shi-latn' ); 00196 $variantfallbacks = array( 00197 'shi' => 'shi-tfng', 00198 'shi-tfng' => 'shi', 00199 'shi-latn' => 'shi', 00200 ); 00201 00202 $flags = array(); 00203 $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags ); 00204 $wgHooks['PageContentSaveComplete'][] = $this->mConverter; 00205 } 00206 }