r85125 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85124‎ | r85125 | r85126 >
Date:14:53, 1 April 2011
Author:krinkle
Status:deferred
Tags:
Comment:
Using new methods introduced in r85123 + fixing typo (sanatized > sanitized)
Modified paths:
  • /trunk/extensions/Translate/groups/Toolserver/README (modified) (history)
  • /trunk/extensions/Translate/groups/Toolserver/ToolserverTextdomains.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/Toolserver/ToolserverTextdomains.php
@@ -29,119 +29,31 @@
3030 $this->path = "$wgTranslateGroupRoot/ToolserverI18N/language/messages/";
3131 }
3232
33 - /// Initialisation function
34 - public function init() {
35 - if ( $this->groups !== null ) return;
36 -
37 - global $wgAutoloadClasses, $IP, $wgTranslateExtensionDirectory;
38 -
39 - $postfix = 'Configure/load_txt_def/TxtDef.php';
40 - if ( file_exists( "$IP/extensions/$postfix" ) ) {
41 - $prefix = "$IP/extensions";
42 - } elseif( file_exists( "$wgTranslateExtensionDirectory/$postfix" ) ) {
43 - $prefix = $wgTranslateExtensionDirectory;
44 - } else {
45 - $prefix = false;
46 - }
47 -
48 - if ( $this->useConfigure && $prefix ) {
49 - $wgAutoloadClasses['TxtDef'] = "$prefix/$postfix";
50 - $tmp = TxtDef::loadFromFile( "$prefix/Configure/settings/Settings-ext.txt" );
51 - $configureData = array_combine( array_map( array( __CLASS__, 'foldId' ), array_keys( $tmp ) ), array_values( $tmp ) );
52 - } else {
53 - $configureData = array();
54 - }
55 -
56 - $defines = file_get_contents( $this->definitionFile );
57 -
58 - $linefeed = '(\r\n|\n)';
59 -
60 - $sections = array_map( 'trim', preg_split( "/$linefeed{2,}/", $defines, - 1, PREG_SPLIT_NO_EMPTY ) );
61 -
62 - $groups = $fixedGroups = array();
63 -
64 - foreach ( $sections as $section ) {
65 - $lines = array_map( 'trim', preg_split( "/$linefeed/", $section ) );
66 - $newgroup = array();
67 -
68 - foreach ( $lines as $line ) {
69 - if ( $line === '' || $line[0] === '#' ) continue;
70 -
71 - if ( strpos( $line, '=' ) === false ) {
72 - if ( empty( $newgroup['name'] ) ) {
73 - $newgroup['name'] = $line;
74 - } else {
75 - throw new MWException( "Trying to define name twice: " . $line );
76 - }
77 - } else {
78 - list( $key, $value ) = array_map( 'trim', explode( '=', $line, 2 ) );
79 - switch ( $key ) {
80 - case 'file':
81 - case 'var':
82 - case 'id':
83 - case 'descmsg':
84 - case 'desc':
85 - case 'magicfile':
86 - case 'aliasfile':
87 - $newgroup[$key] = $value;
88 - break;
89 - case 'optional':
90 - case 'ignored':
91 - $values = array_map( 'trim', explode( ',', $value ) );
92 - if ( !isset( $newgroup[$key] ) ) {
93 - $newgroup[$key] = array();
94 - }
95 - $newgroup[$key] = array_merge( $newgroup[$key], $values );
96 - break;
97 - case 'prefix':
98 - list( $prefix, $messages ) = array_map( 'trim', explode( '|', $value, 2 ) );
99 - if ( isset( $newgroup['prefix'] ) && $newgroup['prefix'] !== $prefix ) {
100 - throw new MWException( "Only one prefix supported: {$newgroup['prefix']} !== $prefix" );
101 - }
102 - $newgroup['prefix'] = $prefix;
103 -
104 - if ( !isset( $newgroup['mangle'] ) ) $newgroup['mangle'] = array();
105 -
106 - $messages = array_map( 'trim', explode( ',', $messages ) );
107 - $newgroup['mangle'] = array_merge( $newgroup['mangle'], $messages );
108 - break;
109 - default:
110 - throw new MWException( "Unknown key:" . $key );
111 - }
112 - }
113 - }
114 -
115 - if ( count( $newgroup ) ) {
116 - if ( empty( $newgroup['name'] ) ) {
117 - throw new MWException( "Name missing\n" . print_r( $newgroup, true ) );
118 - }
119 - $groups[] = $newgroup;
120 - }
121 - }
122 -
123 -
 33+ protected function processGroups( $groups ) {
 34+ $configureData = $this->loadConfigureExtensionData();
 35+ $fixedGroups = array();
12436 foreach ( $groups as $g ) {
12537 if ( !is_array( $g ) ) {
12638 $g = array( $g );
12739 }
12840
12941 $name = $g['name'];
130 - $sanatizedName = preg_replace( '/\s+/', '', strtolower( $name ) );
 42+ $sanitizedName = preg_replace( '/\s+/', '', strtolower( $name ) );
13143
13244 if ( isset( $g['id'] ) ) {
13345 $id = $g['id'];
13446 } else {
135 - $id = $this->idPrefix . $sanatizedName;
 47+ $id = $this->idPrefix . $sanitizedName;
13648 }
13749
13850 if ( isset( $g['file'] ) ) {
13951 $file = $g['file'];
14052 } else {
141 - // TsIntuition text-domains are case-insensitive and internally
 53+ // Toolserver Intuition text-domains are case-insensitive and internally
14254 // converts to lowercase names starting with a capital letter.
143 - // eg. "My Tool" -> "Mytool.i18n.php"
 55+ // eg. "MyTool" -> "Mytool.i18n.php"
14456 // No subdirectories!
145 - $file = ucfirst( $sanatizedName ) . '.i18n.php';
 57+ $file = ucfirst( $sanitizedName ) . '.i18n.php';
14658 }
14759
14860 if ( isset( $g['descmsg'] ) ) {
@@ -163,10 +75,11 @@
16476 'url' => $url,
16577 );
16678
167 - // Allow a custom prefix if needed
 79+ // Prefix is required, if not customized use the sanitized name
16880 if ( !isset( $g['prefix'] ) ) {
169 - $g['prefix'] = "$sanatizedName-";
 81+ $g['prefix'] = "$sanitizedName-";
17082 }
 83+
17184 // All messages are prefixed with their groupname
17285 $g['mangle'] = array( '*' );
17386
@@ -184,7 +97,6 @@
18598
18699 $fixedGroups[$id] = $newgroup;
187100 }
188 -
189 - $this->groups = $fixedGroups;
 101+ return $fixedGroups;
190102 }
191103 }
Index: trunk/extensions/Translate/groups/Toolserver/README
@@ -3,7 +3,7 @@
44 svn co http://svn.wikimedia.org/svnroot/mediawiki/trunk/tools/ToolserverI18N/ ToolserverI18N
55
66 # Add following code to LocalSettings.php or a file included by it:
7 -$wgHooks['TranslatePostInitGroups'] = array( 'setupToolserverI18N' );
 7+$wgHooks['TranslatePostInitGroups'][] = array( 'setupToolserverI18N' );
88 function setupToolserverI18N() {
99 $foo = new PremadeToolserverTextdomains();
1010 $foo->addAll();

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85123Split init() into smaller methodsnikerabbit14:35, 1 April 2011

Status & tagging log