r96712 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96711‎ | r96712 | r96713 >
Date:04:09, 10 September 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
Conversion script between Tifinagh and Latin for the Tachelhit language
Preferences: made getLanguageNames include those that don't have a Messages file
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/Preferences.php (modified) (history)
  • /trunk/phase3/languages/Names.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageShi.deps.php (added) (history)
  • /trunk/phase3/languages/classes/LanguageShi.php (added) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesShi.php (modified) (history)
  • /trunk/phase3/maintenance/language/messageTypes.inc (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -2680,6 +2680,11 @@
26812681 'variantname-ike-latn',
26822682 'variantname-iu',
26832683 ),
 2684+ 'variantname-shi' => array(
 2685+ 'variantname-shi-tfng',
 2686+ 'variantname-shi-latn',
 2687+ 'variantname-shi',
 2688+ ),
26842689 'metadata' => array(
26852690 'metadata',
26862691 'metadata-help',
@@ -3658,6 +3663,7 @@
36593664 'variantname-ku' => 'Variants for Kurdish language',
36603665 'variantname-tg' => 'Variants for Tajiki language',
36613666 'variantname-iu' => 'Variants for Inuktitut language',
 3667+ 'variantname-shi' => 'Variants for Tachelhit language',
36623668 'media-info' => 'Media information',
36633669 'metadata' => 'Metadata',
36643670 'exif' => 'EXIF tags',
Index: trunk/phase3/maintenance/language/messageTypes.inc
@@ -231,6 +231,9 @@
232232 'variantname-ike-cans',
233233 'variantname-ike-latn',
234234 'variantname-iu',
 235+ 'variantname-shi-tfng',
 236+ 'variantname-shi-latn',
 237+ 'variantname-shi',
235238 'rc-change-size',
236239 'resetpass_text',
237240 'image_sample',
Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -56,6 +56,7 @@
5757 * (bug 26470) Add checkered background image on hover on files pages.
5858 * (bug 30774) mediawiki.html: Add support for numbers and booleans in the
5959 attribute values and element contents.
 60+* Conversion script between Tifinagh and Latin for the Tachelhit language
6061
6162 === Bug fixes in 1.19 ===
6263 * $wgUploadNavigationUrl should be used for file redlinks if
Index: trunk/phase3/includes/Preferences.php
@@ -276,7 +276,7 @@
277277 if ( !$wgDisableLangConversion ) {
278278 $variants = $wgContLang->getVariants();
279279
280 - $languages = Language::getLanguageNames( true );
 280+ $languages = Language::getLanguageNames();
281281 foreach ( $variants as $v ) {
282282 $v = str_replace( '_', '-', strtolower( $v ) );
283283 if ( array_key_exists( $v, $languages ) ) {
Index: trunk/phase3/languages/messages/MessagesShi.php
@@ -1173,6 +1173,11 @@
11741174
11751175 ghir lhwayj n lista (stour libdounin s *) karaytyo7asab',
11761176
 1177+# Variants for Tachelhit language
 1178+'variantname-shi-tfng' => 'ᑎᑎᕋᐅᓯᖅ ᓄᑖᖅ',
 1179+'variantname-shi-latn' => 'Tašlḥiyt',
 1180+'variantname-shi' => 'disable',
 1181+
11771182 # Metadata
11781183 'metadata' => 'isfka n mita',
11791184 'metadata-help' => 'Asdaw ad llan gis inɣmisn yaḍnin lli tfl lkamira tuṭunit niɣd aṣfḍ n uxddam lliɣ ay sgadda asdaw ad',
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -3735,6 +3735,12 @@
37363736 'variantname-ike-latn' => 'ike-Latn', # only translate this message to other languages if you have to change it
37373737 'variantname-iu' => 'iu', # only translate this message to other languages if you have to change it
37383738
 3739+# Variants for Tachelhit language
 3740+'variantname-shi-tfng' => 'shi-Tfng', # only translate this message to other languages if you have to change it
 3741+'variantname-shi-latn' => 'shi-Latn', # only translate this message to other languages if you have to change it
 3742+'variantname-shi' => 'shi', # only translate this message to other languages if you have to change it
 3743+
 3744+
37393745 # Metadata
37403746 'metadata' => 'Metadata',
37413747 'metadata-help' => 'This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
Index: trunk/phase3/languages/Names.php
@@ -301,7 +301,9 @@
302302 'sg' => 'Sängö', # Sango/Sangho
303303 'sgs' => 'Žemaitėška', # Samogitian
304304 'sh' => 'Srpskohrvatski / Српскохрватски', # Serbocroatian
305 - 'shi' => 'Tašlḥiyt', # Tachelhit
 305+ 'shi' => 'Tašlḥiyt/ⵜⴰⵛⵍⵃⵉⵜ', # Tachelhit (multiple scripts - defaults to Latin)
 306+ 'shi-tfng' => 'ⵜⴰⵛⵍⵃⵉⵜ', # Tachelhit (Tifinagh script)
 307+ 'shi-latn' => 'Tašlḥiyt', # Tachelhit (Latin script)
306308 'si' => 'සිංහල', # Sinhalese
307309 'simple' => 'Simple English', # Simple English
308310 'sk' => 'Slovenčina', # Slovak
Index: trunk/phase3/languages/classes/LanguageShi.php
@@ -0,0 +1,202 @@
 2+<?php
 3+/**
 4+ * @addtogroup Language
 5+ */
 6+
 7+/*
 8+* Conversion script between Latin and Tifinagh for Tachelhit.
 9+* - Tifinagh -> lowercase Latin
 10+* - lowercase/uppercase Latin -> Tifinagh
 11+*
 12+*
 13+* Based on:
 14+* - http://en.wikipedia.org/wiki/Shilha_language
 15+* - LanguageSr.php
 16+*
 17+* @ingroup Language
 18+*/
 19+require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
 20+
 21+/**
 22+ *
 23+ */
 24+class ShiConverter extends LanguageConverter {
 25+ var $mToLatin = array(
 26+ 'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e',
 27+ 'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x',
 28+ 'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n',
 29+ 'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵖ' => 'γ', 'ⵙ' => 's', 'ⵚ' => 'ṣ',
 30+ 'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z',
 31+ 'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ',
 32+ );
 33+
 34+ var $mUpperToLowerCaseLatin = array(
 35+ 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
 36+ 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
 37+ 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
 38+ 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
 39+ 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
 40+ 'Z' => 'z',
 41+ );
 42+
 43+ var $mToTifinagh = array(
 44+ 'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ',
 45+ 'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ',
 46+ 'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ',
 47+ 'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ',
 48+ 'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ',
 49+ 'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ',
 50+ );
 51+
 52+ function loadDefaultTables() {
 53+ $this->mTables = array(
 54+ 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
 55+ 'shi-tfng' => new ReplacementArray( $this->mToTifinagh ),
 56+ 'shi-latn' => new ReplacementArray( $this->mToLatin ),
 57+ 'shi' => new ReplacementArray()
 58+ );
 59+ }
 60+
 61+ /**
 62+ * rules should be defined as -{Tifinagh | Latin-} -or-
 63+ * -{code:text | code:text | ...}-
 64+ * update: delete all rule parsing because it's not used
 65+ * currently, and just produces a couple of bugs
 66+ *
 67+ * @param $rule string
 68+ * @param $flags array
 69+ * @return array
 70+ */
 71+ function parseManualRule( $rule, $flags = array() ) {
 72+ if ( in_array( 'T', $flags ) ) {
 73+ return parent::parseManualRule( $rule, $flags );
 74+ }
 75+
 76+ $carray = array();
 77+ // otherwise ignore all formatting
 78+ foreach ( $this->mVariants as $v ) {
 79+ $carray[$v] = $rule;
 80+ }
 81+
 82+ return $carray;
 83+ }
 84+
 85+ /**
 86+ * Do not convert content on talk pages
 87+ *
 88+ * @param $text string
 89+ * @param $parser Parser
 90+ * @return string
 91+ */
 92+ function parserConvert( $text, &$parser ) {
 93+ if ( is_object( $parser->getTitle() ) && $parser->getTitle()->isTalkPage() )
 94+ $this->mDoContentConvert = false;
 95+ else
 96+ $this->mDoContentConvert = true;
 97+
 98+ return parent::parserConvert( $text, $parser );
 99+ }
 100+
 101+ /**
 102+ * A function wrapper:
 103+ * - if there is no selected variant, leave the link
 104+ * names as they were
 105+ * - do not try to find variants for usernames
 106+ *
 107+ * @param $link string
 108+ * @param $nt Title
 109+ * @param $ignoreOtherCond bool
 110+ */
 111+ function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
 112+ // check for user namespace
 113+ if ( is_object( $nt ) ) {
 114+ $ns = $nt->getNamespace();
 115+ if ( $ns == NS_USER || $ns == NS_USER_TALK )
 116+ return;
 117+ }
 118+
 119+ $oldlink = $link;
 120+ parent::findVariantLink( $link, $nt, $ignoreOtherCond );
 121+ if ( $this->getPreferredVariant() == $this->mMainLanguageCode )
 122+ $link = $oldlink;
 123+ }
 124+
 125+ /**
 126+ * We want our external link captions to be converted in variants,
 127+ * so we return the original text instead -{$text}-, except for URLs
 128+ *
 129+ * @param $text string
 130+ * @param $noParse bool
 131+ *
 132+ * @return string
 133+ */
 134+ function markNoConversion( $text, $noParse = false ) {
 135+ if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
 136+ return parent::markNoConversion( $text );
 137+ return $text;
 138+ }
 139+
 140+ /**
 141+ * An ugly function wrapper for parsing Image titles
 142+ * (to prevent image name conversion)
 143+ *
 144+ * @param $text string
 145+ * @param $toVariant bool
 146+ *
 147+ * @return string
 148+ */
 149+ function autoConvert( $text, $toVariant = false ) {
 150+ global $wgTitle;
 151+ if ( is_object( $wgTitle ) && $wgTitle->getNameSpace() == NS_FILE ) {
 152+ $imagename = $wgTitle->getNsText();
 153+ if ( preg_match( "/^$imagename:/", $text ) ) return $text;
 154+ }
 155+ return parent::autoConvert( $text, $toVariant );
 156+ }
 157+
 158+ /**
 159+ * It translates text into variant
 160+ *
 161+ * @param $text string
 162+ * @param $toVariant string
 163+ *
 164+ * @return string
 165+ */
 166+ function translate( $text, $toVariant ) {
 167+ // If $text is empty or only includes spaces, do nothing
 168+ // Otherwise translate it
 169+ if ( trim( $text ) ) {
 170+ $this->loadTables();
 171+ // To Tifinagh, first translate uppercase to lowercase Latin
 172+ if( $toVariant == 'shi-tfng' ) {
 173+ $text = $this->mTables['lowercase']->replace( $text );
 174+ }
 175+ $text = $this->mTables[$toVariant]->replace( $text );
 176+ }
 177+ return $text;
 178+ }
 179+}
 180+
 181+/**
 182+ * Tachelhit
 183+ *
 184+ * @ingroup Language
 185+ */
 186+class LanguageShi extends Language {
 187+ function __construct() {
 188+ global $wgHooks;
 189+
 190+ parent::__construct();
 191+
 192+ $variants = array( 'shi', 'shi-tfng', 'shi-latn' );
 193+ $variantfallbacks = array(
 194+ 'shi' => 'shi-tfng',
 195+ 'shi-tfng' => 'shi',
 196+ 'shi-latn' => 'shi',
 197+ );
 198+
 199+ $flags = array();
 200+ $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags );
 201+ $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
 202+ }
 203+}
Property changes on: trunk/phase3/languages/classes/LanguageShi.php
___________________________________________________________________
Added: svn:eol-style
1204 + native
Index: trunk/phase3/languages/classes/LanguageShi.deps.php
@@ -0,0 +1,8 @@
 2+<?php
 3+// This file exists to ensure that base classes are preloaded before
 4+// LanguageIu.php is compiled, working around a bug in the APC opcode
 5+// cache on PHP 5, where cached code can break if the include order
 6+// changed on a subsequent page view.
 7+// see http://mail.wikipedia.org/pipermail/wikitech-l/2006-January/033660.html
 8+
 9+require_once( dirname(__FILE__).'/../LanguageConverter.php' );
Property changes on: trunk/phase3/languages/classes/LanguageShi.deps.php
___________________________________________________________________
Added: svn:eol-style
110 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r96782fix r96712 copy paste error :(robin14:52, 11 September 2011
r102466Readd Names.php and other files removed in r102465...platonides23:35, 8 November 2011

Comments

#Comment by Nikerabbit (talk | contribs)   14:32, 10 September 2011
Preferences: made getLanguageNames include those that don't have a Messages file

Why and why embedded in a big commit?

$wgHooks['ArticleSaveComplete'][] = $this->mConverter;

Having that in class constructor looks very suspicious.

#Comment by SPQRobin (talk | contribs)   14:51, 10 September 2011

1: Because it is needed to make the variants appear on special:preferences. Don't see a reason to commit it separately as long as I mention it in the summary.

2: This is the way it is done in other language classes... The LanguageConverter needs improvement.

#Comment by SPQRobin (talk | contribs)   14:55, 11 September 2011

To be clear (I explained it to Nikerabbit on IRC): the change in Preferences is *only* for the variants dropdown and not for the interface language dropdown.

Status & tagging log