Index: trunk/extensions/Translate/TranslateUtils.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | if ( !isset( $cache[$message] ) ) { |
28 | 28 | $cache[$message] = $wgContLang->ucfirst( $message ); |
29 | 29 | } |
| 30 | + |
30 | 31 | if ( $code ) { |
31 | 32 | return $cache[$message] . '/' . $code; |
32 | 33 | } else { |
— | — | @@ -37,6 +38,7 @@ |
38 | 39 | $pos = strrpos( $text, '/' ); |
39 | 40 | $code = substr( $text, $pos + 1 ); |
40 | 41 | $key = substr( $text, 0, $pos ); |
| 42 | + |
41 | 43 | return array( $key, $code ); |
42 | 44 | } |
43 | 45 | |
— | — | @@ -45,6 +47,7 @@ |
46 | 48 | |
47 | 49 | $title = self::title( $key, $language ); |
48 | 50 | $data = self::getContents( array( $title ), $namespace ); |
| 51 | + |
49 | 52 | return isset( $data[$title][0] ) ? $data[$title][0] : null; |
50 | 53 | } |
51 | 54 | |
— | — | @@ -115,6 +118,7 @@ |
116 | 119 | $rows[] = $row; |
117 | 120 | } |
118 | 121 | $dbr->freeResult( $res ); |
| 122 | + |
119 | 123 | return $rows; |
120 | 124 | } |
121 | 125 | |
— | — | @@ -126,10 +130,12 @@ |
127 | 131 | |
128 | 132 | public static function simpleSelector( $name, $items, $selected ) { |
129 | 133 | $options = array(); |
| 134 | + |
130 | 135 | foreach ( $items as $item ) { |
131 | 136 | $item = strval( $item ); |
132 | 137 | $options[] = Xml::option( $item, $item, $item == $selected ); |
133 | 138 | } |
| 139 | + |
134 | 140 | return self::selector( $name, implode( "\n", $options ) ); |
135 | 141 | } |
136 | 142 | |
— | — | @@ -156,11 +162,13 @@ |
157 | 163 | break; |
158 | 164 | } |
159 | 165 | $code = implode( '-', $parts ); |
| 166 | + |
160 | 167 | return isset( $languages[$code] ) ? $languages[$code] . $suffix : false; |
161 | 168 | } |
162 | 169 | |
163 | 170 | public static function languageSelector( $language, $selectedId ) { |
164 | 171 | global $wgLang; |
| 172 | + |
165 | 173 | if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) { |
166 | 174 | $languages = LanguageNames::getNames( $language, |
167 | 175 | LanguageNames::FALLBACK_NORMAL, |
— | — | @@ -176,25 +184,33 @@ |
177 | 185 | foreach ( $languages as $code => $name ) { |
178 | 186 | $selector->addOption( "$code - $name", $code ); |
179 | 187 | } |
| 188 | + |
180 | 189 | return $selector->getHTML(); |
181 | 190 | } |
182 | 191 | |
183 | 192 | static $mi = null; |
184 | 193 | |
185 | 194 | public static function messageKeyToGroup( $namespace, $key ) { |
186 | | - if ( self::$mi === null ) self::messageIndex(); |
| 195 | + if ( self::$mi === null ) { |
| 196 | + self::messageIndex(); |
| 197 | + } |
187 | 198 | |
188 | 199 | # Performance hotspot |
189 | 200 | # $normkey = self::normaliseKey( $namespace, $key ); |
190 | 201 | $normkey = str_replace( " ", "_", strtolower( "$namespace:$key" ) ); |
191 | 202 | |
192 | 203 | $group = @self::$mi[$normkey]; |
193 | | - if ( is_array( $group ) ) $group = $group[0]; |
| 204 | + if ( is_array( $group ) ) { |
| 205 | + $group = $group[0]; |
| 206 | + } |
| 207 | + |
194 | 208 | return $group; |
195 | 209 | } |
196 | 210 | |
197 | 211 | public static function messageKeyToGroups( $namespace, $key ) { |
198 | | - if ( self::$mi === null ) self::messageIndex(); |
| 212 | + if ( self::$mi === null ) { |
| 213 | + self::messageIndex(); |
| 214 | + } |
199 | 215 | |
200 | 216 | # Performance hotspot |
201 | 217 | # $normkey = self::normaliseKey( $namespace, $key ); |
— | — | @@ -225,9 +241,8 @@ |
226 | 242 | } |
227 | 243 | |
228 | 244 | public static function fieldset( $legend, $contents, $attributes = array() ) { |
229 | | - return |
230 | | - Xml::openElement( 'fieldset', $attributes ) . |
231 | | - Xml::tags( 'legend', null, $legend ) . $contents . |
| 245 | + return Xml::openElement( 'fieldset', $attributes ) . |
| 246 | + Xml::tags( 'legend', null, $legend ) . $contents . |
232 | 247 | Xml::closeElement( 'fieldset' ); |
233 | 248 | } |
234 | 249 | |
— | — | @@ -251,10 +266,15 @@ |
252 | 267 | |
253 | 268 | public static function injectCSS() { |
254 | 269 | static $done = false; |
255 | | - if ( $done ) return; |
| 270 | + |
| 271 | + if ( $done ) { |
| 272 | + return; |
| 273 | + } |
| 274 | + |
256 | 275 | $done = true; |
257 | 276 | |
258 | 277 | global $wgOut; |
| 278 | + |
259 | 279 | $wgOut->addExtensionStyle( self::assetPath( 'Translate.css' ) ); |
260 | 280 | } |
261 | 281 | |
— | — | @@ -265,6 +285,7 @@ |
266 | 286 | */ |
267 | 287 | public static function assetPath( $path ) { |
268 | 288 | global $wgExtensionAssetsPath, $wgScriptPath, $wgVersion; |
| 289 | + |
269 | 290 | if ( version_compare( $wgVersion, '1.16', '>=' ) ) { |
270 | 291 | return "$wgExtensionAssetsPath/Translate/$path"; |
271 | 292 | } else { |
— | — | @@ -274,13 +295,14 @@ |
275 | 296 | |
276 | 297 | public static function snippet( &$text, $length = 10 ) { |
277 | 298 | global $wgLegalTitleChars, $wgContLang; |
| 299 | + |
278 | 300 | $snippet = preg_replace( "/[^\p{L}]/u", ' ', $text ); |
279 | 301 | $snippet = preg_replace( "/ {2,}/u", ' ', $snippet ); |
280 | 302 | $snippet = $wgContLang->truncate( $snippet, $length, '' ); |
281 | 303 | $snippet = str_replace( ' ', '_', trim( $snippet ) ); |
| 304 | + |
282 | 305 | return $snippet; |
283 | 306 | } |
284 | | - |
285 | 307 | } |
286 | 308 | |
287 | 309 | class HTMLSelector { |
— | — | @@ -289,9 +311,17 @@ |
290 | 312 | private $attributes = array(); |
291 | 313 | |
292 | 314 | public function __construct( $name = false, $id = false, $selected = false ) { |
293 | | - if ( $name ) $this->setAttribute( 'name', $name ); |
294 | | - if ( $id ) $this->setAttribute( 'id', $id ); |
295 | | - if ( $selected ) $this->selected = $selected; |
| 315 | + if ( $name ) { |
| 316 | + $this->setAttribute( 'name', $name ); |
| 317 | + } |
| 318 | + |
| 319 | + if ( $id ) { |
| 320 | + $this->setAttribute( 'id', $id ); |
| 321 | + } |
| 322 | + |
| 323 | + if ( $selected ) { |
| 324 | + $this->selected = $selected; |
| 325 | + } |
296 | 326 | } |
297 | 327 | |
298 | 328 | public function setSelected( $selected ) { |