r107171 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107170‎ | r107171 | r107172 >
Date:19:03, 23 December 2011
Author:preilly
Status:ok
Tags:
Comment:
small changes from CR
Modified paths:
  • /trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php (added) (history)
  • /trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.i18n.php (modified) (history)
  • /trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.php
@@ -19,7 +19,7 @@
2020 $wgExtensionCredits['other'][] = array(
2121 'path' => __FILE__,
2222 'name' => 'ZeroRatedMobileAccess',
23 - 'version' => ExtZeroRatedMobileAccess::VERSION,
 23+ 'version' => '0.0.1',
2424 'author' => '[http://www.mediawiki.org/wiki/User:Preilly Preilly]',
2525 'descriptionmsg' => 'zero-rated-mobile-access-desc',
2626 'url' => 'https://www.mediawiki.org/wiki/Extension:ZeroRatedMobileAccess',
@@ -31,407 +31,14 @@
3232 // autoload extension classes
3333
3434 $autoloadClasses = array (
35 - 'ZeroRatedMobileAccessTemplate',
 35+ 'ZeroRatedMobileAccessTemplate' => 'ZeroRatedMobileAccessTemplate',
 36+ 'ExtZeroRatedMobileAccess' => 'ZeroRatedMobileAccess.body',
3637 );
3738
38 -foreach ( $autoloadClasses as $class ) {
39 - $wgAutoloadClasses[$class] = $cwd . $class . '.php';
 39+foreach ( $autoloadClasses as $className => $classFilename ) {
 40+ $wgAutoloadClasses[$className] = $cwd . $classFilename . '.php';
4041 }
4142
4243 $wgExtZeroRatedMobileAccess = new ExtZeroRatedMobileAccess();
4344
44 -$wgHooks['BeforePageDisplay'][] = array( &$wgExtZeroRatedMobileAccess, 'beforePageDisplayHTML' );
45 -
46 -class ExtZeroRatedMobileAccess {
47 - const VERSION = '0.0.4';
48 -
49 - public static $renderZeroRatedLandingPage;
50 - private static $debugOutput = array();
51 - private static $displayDebugOutput = false;
52 -
53 - /**
54 - * @param $out OutputPage
55 - * @param $text String
56 - * @return bool
57 - */
58 - public function beforePageDisplayHTML( &$out, &$text ) {
59 - global $wgRequest;
60 - wfProfileIn( __METHOD__ );
61 - self::$renderZeroRatedLandingPage = $wgRequest->getInt( 'renderZeroRatedLandingPage' );
62 - if ( self::$renderZeroRatedLandingPage === 1 ) {
63 - echo wfMsg( 'zero-rated-mobile-access-desc' );
64 - $languageNames = Language::getLanguageNames();
65 - $country = $wgRequest->getVal( 'country' );
66 - $ip = ( $wgRequest->getVal( 'ip') ) ? $wgRequest->getVal( 'ip' ) : wfGetIP();
67 - // Temporary hack to allow for testing on localhost
68 - $countryIps = array(
69 - 'GERMANY' => '80.237.226.75',
70 - 'MEXICO' => '187.184.240.247',
71 - 'THAILAND' => '180.180.150.104',
72 - 'FRANCE' => '90.6.70.28',
73 - );
74 - $ip = ( strpos( $ip, '192.168.' ) === 0 ) ? $countryIps['THAILAND'] : $ip;
75 - if ( IP::isValid( $ip ) ) {
76 - // If no country was passed, try to do GeoIP lookup
77 - // Requires php5-geoip package
78 - if ( !$country && function_exists( 'geoip_country_code_by_name' ) ) {
79 - $country = geoip_country_code_by_name( $ip );
80 - }
81 - self::addDebugOutput( $country );
82 - }
83 - $languageOptions = self::createLanguageOptionsFromWikiText();
84 - //self::$displayDebugOutput = true;
85 - $languagesForCountry = $languageOptions[self::getFullCountryNameFromCode( $country )];
86 - //self::addDebugOutput( $languageOptions );
87 - self::addDebugOutput( self::getFullCountryNameFromCode( $country ) );
88 - self::addDebugOutput( $languagesForCountry );
89 - self::writeDebugOutput();
90 -
91 - if ( is_array( $languagesForCountry ) ) {
92 - foreach( $languagesForCountry as $language ) {
93 - echo Html::element( 'h3',
94 - array( 'id' => 'lang_' . $language['language'] ),
95 - $languageNames[$language['language']] );
96 - echo '<hr/>';
97 - echo self::getSearchFormHtml( $language['language'] );
98 - }
99 - }
100 - $output = Html::openElement( 'select',
101 - array(
102 - 'id' => 'languageselection',
103 - 'onchange' => 'javascript:window.location = this.options[this.selectedIndex].value;',
104 - )
105 - );
106 - foreach ( $languageNames as $languageCode => $languageName ) {
107 - $output .= Html::element( 'option',
108 - array( 'value' => '//' . $languageCode . '.m.wikipedia.org/' ),
109 - $languageName
110 - );
111 - }
112 - $output .='</select>';
113 - echo $output;
114 - exit();
115 - }
116 -
117 - wfProfileOut( __METHOD__ );
118 - return true;
119 - }
120 -
121 - private static function addDebugOutput( $object ) {
122 - wfProfileIn( __METHOD__ );
123 - if ( is_array( self::$debugOutput ) ) {
124 - self::$debugOutput[] = $object;
125 - }
126 - wfProfileOut( __METHOD__ );
127 - return true;
128 - }
129 -
130 - private static function writeDebugOutput() {
131 - wfProfileIn( __METHOD__ );
132 - if ( self::$debugOutput && self::$displayDebugOutput === true ) {
133 - echo "<pre>";
134 - foreach( self::$debugOutput as $debugOutput ) {
135 - var_dump( $debugOutput );
136 - }
137 - echo "</pre>";
138 - }
139 - wfProfileOut( __METHOD__ );
140 - return true;
141 - }
142 -
143 - private static function createLanguageOptionsFromWikiText() {
144 - wfProfileIn( __METHOD__ );
145 - $languageOptions = array();
146 - $title = Title::newFromText( "Language_options", NS_MEDIAWIKI );
147 - // Use the revision directly to prevent other hooks to be called
148 - $rev = Revision::newFromTitle( $title );
149 - if ( $rev ) {
150 - $lines = explode( "\n", $rev->getRawText() );
151 - }
152 - if ( $lines && count( $lines ) > 0 ) {
153 - $sizeOfLines = sizeof( $lines );
154 - for ( $i = 0; $i < $sizeOfLines; $i++ ) {
155 - $line = $lines[$i];
156 - if ( strpos( $line, '*' ) === 0 && strpos( $line, '**' ) !== 0 && $i >= 0 ) {
157 - $countryName = strtoupper( str_replace( '* ', '', $line ) );
158 - $languageOptions[$countryName] = '';
159 - } elseif ( strpos( $line, '**' ) === 0 && $i > 0 ) {
160 - $lineParts = explode('#', $line);
161 - $language = ( isset( $lineParts[0] ) ) ?
162 - trim( str_replace( '** ', '', $lineParts[0] ) ) :
163 - trim( str_replace( '** ', '', $line ) ) ;
164 - if ( $language !== 'portal' && $language !== 'other' ) {
165 - $languageOptions[$countryName][] = ( isset( $lineParts[1] ) ) ?
166 - array( 'language' => $language,
167 - 'percentage' => intval( str_replace( '%', '', trim( $lineParts[1] ) ) ) ) :
168 - $language;
169 - }
170 - }
171 - }
172 - }
173 - wfProfileOut( __METHOD__ );
174 - return $languageOptions;
175 - }
176 -
177 - private static function getFullCountryNameFromCode( $code ) {
178 - wfProfileIn( __METHOD__ );
179 - $countries = array(
180 - 'AF' => 'AFGHANISTAN',
181 - 'AL' => 'ALBANIA',
182 - 'DZ' => 'ALGERIA',
183 - 'AS' => 'AMERICAN SAMOA',
184 - 'AD' => 'ANDORRA',
185 - 'AO' => 'ANGOLA',
186 - 'AI' => 'ANGUILLA',
187 - 'AQ' => 'ANTARCTICA',
188 - 'AG' => 'ANTIGUA AND BARBUDA',
189 - 'AR' => 'ARGENTINA',
190 - 'AM' => 'ARMENIA',
191 - 'AW' => 'ARUBA',
192 - 'AU' => 'AUSTRALIA',
193 - 'AT' => 'AUSTRIA',
194 - 'AZ' => 'AZERBAIJAN',
195 - 'BS' => 'BAHAMAS',
196 - 'BH' => 'BAHRAIN',
197 - 'BD' => 'BANGLADESH',
198 - 'BB' => 'BARBADOS',
199 - 'BY' => 'BELARUS',
200 - 'BE' => 'BELGIUM',
201 - 'BZ' => 'BELIZE',
202 - 'BJ' => 'BENIN',
203 - 'BM' => 'BERMUDA',
204 - 'BT' => 'BHUTAN',
205 - 'BO' => 'BOLIVIA',
206 - 'BA' => 'BOSNIA AND HERZEGOVINA',
207 - 'BW' => 'BOTSWANA',
208 - 'BV' => 'BOUVET ISLAND',
209 - 'BR' => 'BRAZIL',
210 - 'IO' => 'BRITISH INDIAN OCEAN TERRITORY',
211 - 'BN' => 'BRUNEI DARUSSALAM',
212 - 'BG' => 'BULGARIA',
213 - 'BF' => 'BURKINA FASO',
214 - 'BI' => 'BURUNDI',
215 - 'KH' => 'CAMBODIA',
216 - 'CM' => 'CAMEROON',
217 - 'CA' => 'CANADA',
218 - 'CV' => 'CAPE VERDE',
219 - 'KY' => 'CAYMAN ISLANDS',
220 - 'CF' => 'CENTRAL AFRICAN REPUBLIC',
221 - 'TD' => 'CHAD',
222 - 'CL' => 'CHILE',
223 - 'CN' => 'CHINA',
224 - 'CX' => 'CHRISTMAS ISLAND',
225 - 'CC' => 'COCOS (KEELING) ISLANDS',
226 - 'CO' => 'COLOMBIA',
227 - 'KM' => 'COMOROS',
228 - 'CG' => 'CONGO',
229 - 'CD' => 'CONGO, THE DEMOCRATIC REPUBLIC OF THE',
230 - 'CK' => 'COOK ISLANDS',
231 - 'CR' => 'COSTA RICA',
232 - 'CI' => 'COTE D IVOIRE',
233 - 'HR' => 'CROATIA',
234 - 'CU' => 'CUBA',
235 - 'CY' => 'CYPRUS',
236 - 'CZ' => 'CZECH REPUBLIC',
237 - 'DK' => 'DENMARK',
238 - 'DJ' => 'DJIBOUTI',
239 - 'DM' => 'DOMINICA',
240 - 'DO' => 'DOMINICAN REPUBLIC',
241 - 'TP' => 'EAST TIMOR',
242 - 'EC' => 'ECUADOR',
243 - 'EG' => 'EGYPT',
244 - 'SV' => 'EL SALVADOR',
245 - 'GQ' => 'EQUATORIAL GUINEA',
246 - 'ER' => 'ERITREA',
247 - 'EE' => 'ESTONIA',
248 - 'ET' => 'ETHIOPIA',
249 - 'FK' => 'FALKLAND ISLANDS (MALVINAS)',
250 - 'FO' => 'FAROE ISLANDS',
251 - 'FJ' => 'FIJI',
252 - 'FI' => 'FINLAND',
253 - 'FR' => 'FRANCE',
254 - 'GF' => 'FRENCH GUIANA',
255 - 'PF' => 'FRENCH POLYNESIA',
256 - 'TF' => 'FRENCH SOUTHERN TERRITORIES',
257 - 'GA' => 'GABON',
258 - 'GM' => 'GAMBIA',
259 - 'GE' => 'GEORGIA',
260 - 'DE' => 'GERMANY',
261 - 'GH' => 'GHANA',
262 - 'GI' => 'GIBRALTAR',
263 - 'GR' => 'GREECE',
264 - 'GL' => 'GREENLAND',
265 - 'GD' => 'GRENADA',
266 - 'GP' => 'GUADELOUPE',
267 - 'GU' => 'GUAM',
268 - 'GT' => 'GUATEMALA',
269 - 'GN' => 'GUINEA',
270 - 'GW' => 'GUINEA-BISSAU',
271 - 'GY' => 'GUYANA',
272 - 'HT' => 'HAITI',
273 - 'HM' => 'HEARD ISLAND AND MCDONALD ISLANDS',
274 - 'VA' => 'HOLY SEE (VATICAN CITY STATE)',
275 - 'HN' => 'HONDURAS',
276 - 'HK' => 'HONG KONG',
277 - 'HU' => 'HUNGARY',
278 - 'IS' => 'ICELAND',
279 - 'IN' => 'INDIA',
280 - 'ID' => 'INDONESIA',
281 - 'IR' => 'IRAN, ISLAMIC REPUBLIC OF',
282 - 'IQ' => 'IRAQ',
283 - 'IE' => 'IRELAND',
284 - 'IL' => 'ISRAEL',
285 - 'IT' => 'ITALY',
286 - 'JM' => 'JAMAICA',
287 - 'JP' => 'JAPAN',
288 - 'JO' => 'JORDAN',
289 - 'KZ' => 'KAZAKSTAN',
290 - 'KE' => 'KENYA',
291 - 'KI' => 'KIRIBATI',
292 - 'KP' => 'KOREA DEMOCRATIC PEOPLES REPUBLIC OF',
293 - 'KR' => 'KOREA REPUBLIC OF',
294 - 'KW' => 'KUWAIT',
295 - 'KG' => 'KYRGYZSTAN',
296 - 'LA' => 'LAO PEOPLES DEMOCRATIC REPUBLIC',
297 - 'LV' => 'LATVIA',
298 - 'LB' => 'LEBANON',
299 - 'LS' => 'LESOTHO',
300 - 'LR' => 'LIBERIA',
301 - 'LY' => 'LIBYAN ARAB JAMAHIRIYA',
302 - 'LI' => 'LIECHTENSTEIN',
303 - 'LT' => 'LITHUANIA',
304 - 'LU' => 'LUXEMBOURG',
305 - 'MO' => 'MACAU',
306 - 'MK' => 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF',
307 - 'MG' => 'MADAGASCAR',
308 - 'MW' => 'MALAWI',
309 - 'MY' => 'MALAYSIA',
310 - 'MV' => 'MALDIVES',
311 - 'ML' => 'MALI',
312 - 'MT' => 'MALTA',
313 - 'MH' => 'MARSHALL ISLANDS',
314 - 'MQ' => 'MARTINIQUE',
315 - 'MR' => 'MAURITANIA',
316 - 'MU' => 'MAURITIUS',
317 - 'YT' => 'MAYOTTE',
318 - 'MX' => 'MEXICO',
319 - 'FM' => 'MICRONESIA, FEDERATED STATES OF',
320 - 'MD' => 'MOLDOVA, REPUBLIC OF',
321 - 'MC' => 'MONACO',
322 - 'MN' => 'MONGOLIA',
323 - 'MS' => 'MONTSERRAT',
324 - 'MA' => 'MOROCCO',
325 - 'MZ' => 'MOZAMBIQUE',
326 - 'MM' => 'MYANMAR',
327 - 'NA' => 'NAMIBIA',
328 - 'NR' => 'NAURU',
329 - 'NP' => 'NEPAL',
330 - 'NL' => 'NETHERLANDS',
331 - 'AN' => 'NETHERLANDS ANTILLES',
332 - 'NC' => 'NEW CALEDONIA',
333 - 'NZ' => 'NEW ZEALAND',
334 - 'NI' => 'NICARAGUA',
335 - 'NE' => 'NIGER',
336 - 'NG' => 'NIGERIA',
337 - 'NU' => 'NIUE',
338 - 'NF' => 'NORFOLK ISLAND',
339 - 'MP' => 'NORTHERN MARIANA ISLANDS',
340 - 'NO' => 'NORWAY',
341 - 'OM' => 'OMAN',
342 - 'PK' => 'PAKISTAN',
343 - 'PW' => 'PALAU',
344 - 'PS' => 'PALESTINIAN TERRITORY, OCCUPIED',
345 - 'PA' => 'PANAMA',
346 - 'PG' => 'PAPUA NEW GUINEA',
347 - 'PY' => 'PARAGUAY',
348 - 'PE' => 'PERU',
349 - 'PH' => 'PHILIPPINES',
350 - 'PN' => 'PITCAIRN',
351 - 'PL' => 'POLAND',
352 - 'PT' => 'PORTUGAL',
353 - 'PR' => 'PUERTO RICO',
354 - 'QA' => 'QATAR',
355 - 'RE' => 'REUNION',
356 - 'RO' => 'ROMANIA',
357 - 'RU' => 'RUSSIAN FEDERATION',
358 - 'RW' => 'RWANDA',
359 - 'SH' => 'SAINT HELENA',
360 - 'KN' => 'SAINT KITTS AND NEVIS',
361 - 'LC' => 'SAINT LUCIA',
362 - 'PM' => 'SAINT PIERRE AND MIQUELON',
363 - 'VC' => 'SAINT VINCENT AND THE GRENADINES',
364 - 'WS' => 'SAMOA',
365 - 'SM' => 'SAN MARINO',
366 - 'ST' => 'SAO TOME AND PRINCIPE',
367 - 'SA' => 'SAUDI ARABIA',
368 - 'SN' => 'SENEGAL',
369 - 'SC' => 'SEYCHELLES',
370 - 'SL' => 'SIERRA LEONE',
371 - 'SG' => 'SINGAPORE',
372 - 'SK' => 'SLOVAKIA',
373 - 'SI' => 'SLOVENIA',
374 - 'SB' => 'SOLOMON ISLANDS',
375 - 'SO' => 'SOMALIA',
376 - 'ZA' => 'SOUTH AFRICA',
377 - 'GS' => 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS',
378 - 'ES' => 'SPAIN',
379 - 'LK' => 'SRI LANKA',
380 - 'SD' => 'SUDAN',
381 - 'SR' => 'SURINAME',
382 - 'SJ' => 'SVALBARD AND JAN MAYEN',
383 - 'SZ' => 'SWAZILAND',
384 - 'SE' => 'SWEDEN',
385 - 'CH' => 'SWITZERLAND',
386 - 'SY' => 'SYRIAN ARAB REPUBLIC',
387 - 'TW' => 'TAIWAN, PROVINCE OF CHINA',
388 - 'TJ' => 'TAJIKISTAN',
389 - 'TZ' => 'TANZANIA, UNITED REPUBLIC OF',
390 - 'TH' => 'THAILAND',
391 - 'TG' => 'TOGO',
392 - 'TK' => 'TOKELAU',
393 - 'TO' => 'TONGA',
394 - 'TT' => 'TRINIDAD AND TOBAGO',
395 - 'TN' => 'TUNISIA',
396 - 'TR' => 'TURKEY',
397 - 'TM' => 'TURKMENISTAN',
398 - 'TC' => 'TURKS AND CAICOS ISLANDS',
399 - 'TV' => 'TUVALU',
400 - 'UG' => 'UGANDA',
401 - 'UA' => 'UKRAINE',
402 - 'AE' => 'UNITED ARAB EMIRATES',
403 - 'GB' => 'UNITED KINGDOM',
404 - 'US' => 'UNITED STATES',
405 - 'UM' => 'UNITED STATES MINOR OUTLYING ISLANDS',
406 - 'UY' => 'URUGUAY',
407 - 'UZ' => 'UZBEKISTAN',
408 - 'VU' => 'VANUATU',
409 - 'VE' => 'VENEZUELA',
410 - 'VN' => 'VIET NAM',
411 - 'VG' => 'VIRGIN ISLANDS, BRITISH',
412 - 'VI' => 'VIRGIN ISLANDS, U.S.',
413 - 'WF' => 'WALLIS AND FUTUNA',
414 - 'EH' => 'WESTERN SAHARA',
415 - 'YE' => 'YEMEN',
416 - 'YU' => 'YUGOSLAVIA',
417 - 'ZM' => 'ZAMBIA',
418 - 'ZW' => 'ZIMBABWE',
419 - );
420 - wfProfileOut( __METHOD__ );
421 - return ( isset( $countries[strtoupper( $code )] ) ) ? $countries[strtoupper( $code )] : null;
422 - }
423 -
424 - private static function getSearchFormHtml( $langCode ) {
425 - $searchValue = wfMessage( 'zero-rated-mobile-access-search' )->inLanguage( $langCode );
426 - $formHtml = <<<HTML
427 - <form action="//{$langCode}.wikipedia.org/w/index.php" class="search_bar" method="get">
428 - <input type="hidden" value="Special:Search" name="title">
429 - <div id="sq" class="divclearable">
430 - <input type="text" name="search" id="search" size="22" value="" autocorrect="off" autocomplete="off" autocapitalize="off" maxlength="1024">
431 - <div class="clearlink" id="clearsearch" title="Clear"></div>
432 - </div>
433 - <button id="goButton" type="submit">{$searchValue}</button>
434 - </form>
435 -HTML;
436 - return $formHtml;
437 - }
438 -}
\ No newline at end of file
 45+$wgHooks['BeforePageDisplay'][] = array( &$wgExtZeroRatedMobileAccess, 'beforePageDisplayHTML' );
\ No newline at end of file
Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php
@@ -0,0 +1,397 @@
 2+<?php
 3+
 4+class ExtZeroRatedMobileAccess {
 5+ const VERSION = '0.0.5';
 6+
 7+ public static $renderZeroRatedLandingPage;
 8+ private static $debugOutput = array();
 9+ private static $displayDebugOutput = false;
 10+
 11+ /**
 12+ * @param $out OutputPage
 13+ * @param $text String
 14+ * @return bool
 15+ */
 16+ public function beforePageDisplayHTML( &$out, &$text ) {
 17+ global $wgRequest;
 18+ wfProfileIn( __METHOD__ );
 19+ self::$renderZeroRatedLandingPage = $wgRequest->getFuzzyBool( 'renderZeroRatedLandingPage' );
 20+ if ( self::$renderZeroRatedLandingPage === true ) {
 21+ echo wfMsg( 'zero-rated-mobile-access-desc' );
 22+ $languageNames = Language::getLanguageNames();
 23+ $country = $wgRequest->getVal( 'country' );
 24+ $ip = $wgRequest->getVal( 'ip', wfGetIP() );
 25+ // Temporary hack to allow for testing on localhost
 26+ $countryIps = array(
 27+ 'GERMANY' => '80.237.226.75',
 28+ 'MEXICO' => '187.184.240.247',
 29+ 'THAILAND' => '180.180.150.104',
 30+ 'FRANCE' => '90.6.70.28',
 31+ );
 32+ $ip = ( strpos( $ip, '192.168.' ) === 0 ) ? $countryIps['THAILAND'] : $ip;
 33+ if ( IP::isValid( $ip ) ) {
 34+ // If no country was passed, try to do GeoIP lookup
 35+ // Requires php5-geoip package
 36+ if ( !$country && function_exists( 'geoip_country_code_by_name' ) ) {
 37+ $country = geoip_country_code_by_name( $ip );
 38+ }
 39+ self::addDebugOutput( $country );
 40+ }
 41+ $languageOptions = self::createLanguageOptionsFromWikiText();
 42+ //self::$displayDebugOutput = true;
 43+ $languagesForCountry = ( isset( $languageOptions[self::getFullCountryNameFromCode( $country )] ) ) ?
 44+ $languageOptions[self::getFullCountryNameFromCode( $country )] : null;
 45+ //self::addDebugOutput( $languageOptions );
 46+ self::addDebugOutput( self::getFullCountryNameFromCode( $country ) );
 47+ self::addDebugOutput( $languagesForCountry );
 48+ self::writeDebugOutput();
 49+
 50+ if ( is_array( $languagesForCountry ) ) {
 51+ foreach( $languagesForCountry as $language ) {
 52+ echo Html::element( 'h3',
 53+ array( 'id' => 'lang_' . $language['language'],
 54+ ),
 55+ $languageNames[$language['language']]);
 56+ echo Html::element( 'hr',
 57+ array(), '');
 58+ echo self::getSearchFormHtml( $language['language'] );
 59+ }
 60+ }
 61+ $output = Html::openElement( 'select',
 62+ array( 'id' => 'languageselection',
 63+ 'onchange' => 'javascript:window.location = this.options[this.selectedIndex].value;' ) );
 64+ foreach ( $languageNames as $languageCode => $languageName ) {
 65+ $output .= Html::element( 'option',
 66+ array( 'value' => '//' . $languageCode . '.m.wikipedia.org/' ),
 67+ $languageName );
 68+ }
 69+ $output .= Html::closeElement( 'select', array() );
 70+ echo $output;
 71+ exit();
 72+ }
 73+
 74+ wfProfileOut( __METHOD__ );
 75+ return true;
 76+ }
 77+
 78+ private static function addDebugOutput( $object ) {
 79+ wfProfileIn( __METHOD__ );
 80+ if ( is_array( self::$debugOutput ) ) {
 81+ self::$debugOutput[] = $object;
 82+ }
 83+ wfProfileOut( __METHOD__ );
 84+ return true;
 85+ }
 86+
 87+ private static function writeDebugOutput() {
 88+ wfProfileIn( __METHOD__ );
 89+ if ( self::$debugOutput && self::$displayDebugOutput === true ) {
 90+ echo "<pre>";
 91+ foreach( self::$debugOutput as $debugOutput ) {
 92+ var_dump( $debugOutput );
 93+ }
 94+ echo "</pre>";
 95+ }
 96+ wfProfileOut( __METHOD__ );
 97+ return true;
 98+ }
 99+
 100+ private static function createLanguageOptionsFromWikiText() {
 101+ wfProfileIn( __METHOD__ );
 102+ $languageOptions = array();
 103+ $languageOptionsWikiPage = wfMsg( 'zero-rated-mobile-access-language-options-wiki-page' );
 104+ $title = Title::newFromText( $languageOptionsWikiPage, NS_MEDIAWIKI );
 105+ // Use the revision directly to prevent other hooks to be called
 106+ $rev = Revision::newFromTitle( $title );
 107+ $lines = array();
 108+ if ( $rev ) {
 109+ $lines = explode( "\n", $rev->getRawText() );
 110+ }
 111+ if ( $lines && count( $lines ) > 0 ) {
 112+ $sizeOfLines = sizeof( $lines );
 113+ for ( $i = 0; $i < $sizeOfLines; $i++ ) {
 114+ $line = $lines[$i];
 115+ if ( strpos( $line, '*' ) === 0 && strpos( $line, '**' ) !== 0 && $i >= 0 ) {
 116+ $countryName = strtoupper( str_replace( '* ', '', $line ) );
 117+ $languageOptions[$countryName] = '';
 118+ } elseif ( strpos( $line, '**' ) === 0 && $i > 0 ) {
 119+ $lineParts = explode('#', $line);
 120+ $language = ( isset( $lineParts[0] ) ) ?
 121+ trim( str_replace( '** ', '', $lineParts[0] ) ) :
 122+ trim( str_replace( '** ', '', $line ) ) ;
 123+ if ( $language !== 'portal' && $language !== 'other' ) {
 124+ $languageOptions[$countryName][] = ( isset( $lineParts[1] ) ) ?
 125+ array( 'language' => $language,
 126+ 'percentage' => intval( str_replace( '%', '', trim( $lineParts[1] ) ) ) ) :
 127+ $language;
 128+ }
 129+ }
 130+ }
 131+ }
 132+ wfProfileOut( __METHOD__ );
 133+ return $languageOptions;
 134+ }
 135+
 136+ private static function getFullCountryNameFromCode( $code ) {
 137+ wfProfileIn( __METHOD__ );
 138+ $countries = array(
 139+ 'AF' => 'AFGHANISTAN',
 140+ 'AL' => 'ALBANIA',
 141+ 'DZ' => 'ALGERIA',
 142+ 'AS' => 'AMERICAN SAMOA',
 143+ 'AD' => 'ANDORRA',
 144+ 'AO' => 'ANGOLA',
 145+ 'AI' => 'ANGUILLA',
 146+ 'AQ' => 'ANTARCTICA',
 147+ 'AG' => 'ANTIGUA AND BARBUDA',
 148+ 'AR' => 'ARGENTINA',
 149+ 'AM' => 'ARMENIA',
 150+ 'AW' => 'ARUBA',
 151+ 'AU' => 'AUSTRALIA',
 152+ 'AT' => 'AUSTRIA',
 153+ 'AZ' => 'AZERBAIJAN',
 154+ 'BS' => 'BAHAMAS',
 155+ 'BH' => 'BAHRAIN',
 156+ 'BD' => 'BANGLADESH',
 157+ 'BB' => 'BARBADOS',
 158+ 'BY' => 'BELARUS',
 159+ 'BE' => 'BELGIUM',
 160+ 'BZ' => 'BELIZE',
 161+ 'BJ' => 'BENIN',
 162+ 'BM' => 'BERMUDA',
 163+ 'BT' => 'BHUTAN',
 164+ 'BO' => 'BOLIVIA',
 165+ 'BA' => 'BOSNIA AND HERZEGOVINA',
 166+ 'BW' => 'BOTSWANA',
 167+ 'BV' => 'BOUVET ISLAND',
 168+ 'BR' => 'BRAZIL',
 169+ 'IO' => 'BRITISH INDIAN OCEAN TERRITORY',
 170+ 'BN' => 'BRUNEI DARUSSALAM',
 171+ 'BG' => 'BULGARIA',
 172+ 'BF' => 'BURKINA FASO',
 173+ 'BI' => 'BURUNDI',
 174+ 'KH' => 'CAMBODIA',
 175+ 'CM' => 'CAMEROON',
 176+ 'CA' => 'CANADA',
 177+ 'CV' => 'CAPE VERDE',
 178+ 'KY' => 'CAYMAN ISLANDS',
 179+ 'CF' => 'CENTRAL AFRICAN REPUBLIC',
 180+ 'TD' => 'CHAD',
 181+ 'CL' => 'CHILE',
 182+ 'CN' => 'CHINA',
 183+ 'CX' => 'CHRISTMAS ISLAND',
 184+ 'CC' => 'COCOS (KEELING) ISLANDS',
 185+ 'CO' => 'COLOMBIA',
 186+ 'KM' => 'COMOROS',
 187+ 'CG' => 'CONGO',
 188+ 'CD' => 'CONGO, THE DEMOCRATIC REPUBLIC OF THE',
 189+ 'CK' => 'COOK ISLANDS',
 190+ 'CR' => 'COSTA RICA',
 191+ 'CI' => 'COTE D IVOIRE',
 192+ 'HR' => 'CROATIA',
 193+ 'CU' => 'CUBA',
 194+ 'CY' => 'CYPRUS',
 195+ 'CZ' => 'CZECH REPUBLIC',
 196+ 'DK' => 'DENMARK',
 197+ 'DJ' => 'DJIBOUTI',
 198+ 'DM' => 'DOMINICA',
 199+ 'DO' => 'DOMINICAN REPUBLIC',
 200+ 'TP' => 'EAST TIMOR',
 201+ 'EC' => 'ECUADOR',
 202+ 'EG' => 'EGYPT',
 203+ 'SV' => 'EL SALVADOR',
 204+ 'GQ' => 'EQUATORIAL GUINEA',
 205+ 'ER' => 'ERITREA',
 206+ 'EE' => 'ESTONIA',
 207+ 'ET' => 'ETHIOPIA',
 208+ 'FK' => 'FALKLAND ISLANDS (MALVINAS)',
 209+ 'FO' => 'FAROE ISLANDS',
 210+ 'FJ' => 'FIJI',
 211+ 'FI' => 'FINLAND',
 212+ 'FR' => 'FRANCE',
 213+ 'GF' => 'FRENCH GUIANA',
 214+ 'PF' => 'FRENCH POLYNESIA',
 215+ 'TF' => 'FRENCH SOUTHERN TERRITORIES',
 216+ 'GA' => 'GABON',
 217+ 'GM' => 'GAMBIA',
 218+ 'GE' => 'GEORGIA',
 219+ 'DE' => 'GERMANY',
 220+ 'GH' => 'GHANA',
 221+ 'GI' => 'GIBRALTAR',
 222+ 'GR' => 'GREECE',
 223+ 'GL' => 'GREENLAND',
 224+ 'GD' => 'GRENADA',
 225+ 'GP' => 'GUADELOUPE',
 226+ 'GU' => 'GUAM',
 227+ 'GT' => 'GUATEMALA',
 228+ 'GN' => 'GUINEA',
 229+ 'GW' => 'GUINEA-BISSAU',
 230+ 'GY' => 'GUYANA',
 231+ 'HT' => 'HAITI',
 232+ 'HM' => 'HEARD ISLAND AND MCDONALD ISLANDS',
 233+ 'VA' => 'HOLY SEE (VATICAN CITY STATE)',
 234+ 'HN' => 'HONDURAS',
 235+ 'HK' => 'HONG KONG',
 236+ 'HU' => 'HUNGARY',
 237+ 'IS' => 'ICELAND',
 238+ 'IN' => 'INDIA',
 239+ 'ID' => 'INDONESIA',
 240+ 'IR' => 'IRAN, ISLAMIC REPUBLIC OF',
 241+ 'IQ' => 'IRAQ',
 242+ 'IE' => 'IRELAND',
 243+ 'IL' => 'ISRAEL',
 244+ 'IT' => 'ITALY',
 245+ 'JM' => 'JAMAICA',
 246+ 'JP' => 'JAPAN',
 247+ 'JO' => 'JORDAN',
 248+ 'KZ' => 'KAZAKSTAN',
 249+ 'KE' => 'KENYA',
 250+ 'KI' => 'KIRIBATI',
 251+ 'KP' => 'KOREA DEMOCRATIC PEOPLES REPUBLIC OF',
 252+ 'KR' => 'KOREA REPUBLIC OF',
 253+ 'KW' => 'KUWAIT',
 254+ 'KG' => 'KYRGYZSTAN',
 255+ 'LA' => 'LAO PEOPLES DEMOCRATIC REPUBLIC',
 256+ 'LV' => 'LATVIA',
 257+ 'LB' => 'LEBANON',
 258+ 'LS' => 'LESOTHO',
 259+ 'LR' => 'LIBERIA',
 260+ 'LY' => 'LIBYAN ARAB JAMAHIRIYA',
 261+ 'LI' => 'LIECHTENSTEIN',
 262+ 'LT' => 'LITHUANIA',
 263+ 'LU' => 'LUXEMBOURG',
 264+ 'MO' => 'MACAU',
 265+ 'MK' => 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF',
 266+ 'MG' => 'MADAGASCAR',
 267+ 'MW' => 'MALAWI',
 268+ 'MY' => 'MALAYSIA',
 269+ 'MV' => 'MALDIVES',
 270+ 'ML' => 'MALI',
 271+ 'MT' => 'MALTA',
 272+ 'MH' => 'MARSHALL ISLANDS',
 273+ 'MQ' => 'MARTINIQUE',
 274+ 'MR' => 'MAURITANIA',
 275+ 'MU' => 'MAURITIUS',
 276+ 'YT' => 'MAYOTTE',
 277+ 'MX' => 'MEXICO',
 278+ 'FM' => 'MICRONESIA, FEDERATED STATES OF',
 279+ 'MD' => 'MOLDOVA, REPUBLIC OF',
 280+ 'MC' => 'MONACO',
 281+ 'MN' => 'MONGOLIA',
 282+ 'MS' => 'MONTSERRAT',
 283+ 'MA' => 'MOROCCO',
 284+ 'MZ' => 'MOZAMBIQUE',
 285+ 'MM' => 'MYANMAR',
 286+ 'NA' => 'NAMIBIA',
 287+ 'NR' => 'NAURU',
 288+ 'NP' => 'NEPAL',
 289+ 'NL' => 'NETHERLANDS',
 290+ 'AN' => 'NETHERLANDS ANTILLES',
 291+ 'NC' => 'NEW CALEDONIA',
 292+ 'NZ' => 'NEW ZEALAND',
 293+ 'NI' => 'NICARAGUA',
 294+ 'NE' => 'NIGER',
 295+ 'NG' => 'NIGERIA',
 296+ 'NU' => 'NIUE',
 297+ 'NF' => 'NORFOLK ISLAND',
 298+ 'MP' => 'NORTHERN MARIANA ISLANDS',
 299+ 'NO' => 'NORWAY',
 300+ 'OM' => 'OMAN',
 301+ 'PK' => 'PAKISTAN',
 302+ 'PW' => 'PALAU',
 303+ 'PS' => 'PALESTINIAN TERRITORY, OCCUPIED',
 304+ 'PA' => 'PANAMA',
 305+ 'PG' => 'PAPUA NEW GUINEA',
 306+ 'PY' => 'PARAGUAY',
 307+ 'PE' => 'PERU',
 308+ 'PH' => 'PHILIPPINES',
 309+ 'PN' => 'PITCAIRN',
 310+ 'PL' => 'POLAND',
 311+ 'PT' => 'PORTUGAL',
 312+ 'PR' => 'PUERTO RICO',
 313+ 'QA' => 'QATAR',
 314+ 'RE' => 'REUNION',
 315+ 'RO' => 'ROMANIA',
 316+ 'RU' => 'RUSSIAN FEDERATION',
 317+ 'RW' => 'RWANDA',
 318+ 'SH' => 'SAINT HELENA',
 319+ 'KN' => 'SAINT KITTS AND NEVIS',
 320+ 'LC' => 'SAINT LUCIA',
 321+ 'PM' => 'SAINT PIERRE AND MIQUELON',
 322+ 'VC' => 'SAINT VINCENT AND THE GRENADINES',
 323+ 'WS' => 'SAMOA',
 324+ 'SM' => 'SAN MARINO',
 325+ 'ST' => 'SAO TOME AND PRINCIPE',
 326+ 'SA' => 'SAUDI ARABIA',
 327+ 'SN' => 'SENEGAL',
 328+ 'SC' => 'SEYCHELLES',
 329+ 'SL' => 'SIERRA LEONE',
 330+ 'SG' => 'SINGAPORE',
 331+ 'SK' => 'SLOVAKIA',
 332+ 'SI' => 'SLOVENIA',
 333+ 'SB' => 'SOLOMON ISLANDS',
 334+ 'SO' => 'SOMALIA',
 335+ 'ZA' => 'SOUTH AFRICA',
 336+ 'GS' => 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS',
 337+ 'ES' => 'SPAIN',
 338+ 'LK' => 'SRI LANKA',
 339+ 'SD' => 'SUDAN',
 340+ 'SR' => 'SURINAME',
 341+ 'SJ' => 'SVALBARD AND JAN MAYEN',
 342+ 'SZ' => 'SWAZILAND',
 343+ 'SE' => 'SWEDEN',
 344+ 'CH' => 'SWITZERLAND',
 345+ 'SY' => 'SYRIAN ARAB REPUBLIC',
 346+ 'TW' => 'TAIWAN, PROVINCE OF CHINA',
 347+ 'TJ' => 'TAJIKISTAN',
 348+ 'TZ' => 'TANZANIA, UNITED REPUBLIC OF',
 349+ 'TH' => 'THAILAND',
 350+ 'TG' => 'TOGO',
 351+ 'TK' => 'TOKELAU',
 352+ 'TO' => 'TONGA',
 353+ 'TT' => 'TRINIDAD AND TOBAGO',
 354+ 'TN' => 'TUNISIA',
 355+ 'TR' => 'TURKEY',
 356+ 'TM' => 'TURKMENISTAN',
 357+ 'TC' => 'TURKS AND CAICOS ISLANDS',
 358+ 'TV' => 'TUVALU',
 359+ 'UG' => 'UGANDA',
 360+ 'UA' => 'UKRAINE',
 361+ 'AE' => 'UNITED ARAB EMIRATES',
 362+ 'GB' => 'UNITED KINGDOM',
 363+ 'US' => 'UNITED STATES',
 364+ 'UM' => 'UNITED STATES MINOR OUTLYING ISLANDS',
 365+ 'UY' => 'URUGUAY',
 366+ 'UZ' => 'UZBEKISTAN',
 367+ 'VU' => 'VANUATU',
 368+ 'VE' => 'VENEZUELA',
 369+ 'VN' => 'VIET NAM',
 370+ 'VG' => 'VIRGIN ISLANDS, BRITISH',
 371+ 'VI' => 'VIRGIN ISLANDS, U.S.',
 372+ 'WF' => 'WALLIS AND FUTUNA',
 373+ 'EH' => 'WESTERN SAHARA',
 374+ 'YE' => 'YEMEN',
 375+ 'YU' => 'YUGOSLAVIA',
 376+ 'ZM' => 'ZAMBIA',
 377+ 'ZW' => 'ZIMBABWE',
 378+ );
 379+ wfProfileOut( __METHOD__ );
 380+ $code = ( strlen( $code ) === 2 ) ? strtoupper( $code ) : null;
 381+ return ( $code && isset( $countries[$code] ) ) ? $countries[$code] : null;
 382+ }
 383+
 384+ private static function getSearchFormHtml( $langCode ) {
 385+ $searchValue = wfMessage( 'zero-rated-mobile-access-search' )->inLanguage( $langCode );
 386+ $formHtml = <<<HTML
 387+ <form action="//{$langCode}.wikipedia.org/w/index.php" class="search_bar" method="get">
 388+ <input type="hidden" value="Special:Search" name="title">
 389+ <div id="sq" class="divclearable">
 390+ <input type="text" name="search" id="search" size="22" value="" autocorrect="off" autocomplete="off" autocapitalize="off" maxlength="1024">
 391+ <div class="clearlink" id="clearsearch" title="Clear"></div>
 392+ </div>
 393+ <button id="goButton" type="submit">{$searchValue}</button>
 394+ </form>
 395+HTML;
 396+ return $formHtml;
 397+ }
 398+}
\ No newline at end of file
Property changes on: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php
___________________________________________________________________
Added: svn:eol-style
1399 + native
Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.i18n.php
@@ -13,16 +13,19 @@
1414
1515 // en translation
1616 $messages['en'] = array (
17 - 'zero-rated-mobile-access-desc' => 'Zero Rated Mobile Access',
 17+ 'zero-rated-mobile-access-desc' => 'Zero Rated Mobile Access extension provides features for mobile providers that provide free access',
1818 'zero-rated-mobile-access-search' => 'Search',
 19+ 'zero-rated-mobile-access-language-options-wiki-page' => 'Language_options',
1920 );
2021
2122 $messages['ja'] = array (
2223 'zero-rated-mobile-access-desc' => 'ゼロ格モバイルアクセス',
2324 'zero-rated-mobile-access-search' => '検索する',
 25+ 'zero-rated-mobile-access-language-options-wiki-page' => 'Language_options',
2426 );
2527
2628 $messages['qqq'] = array(
2729 'zero-rated-mobile-access-desc' => '{{Identical|Show}}',
2830 'zero-rated-mobile-access-search' => 'Text for search action on the search button',
 31+ 'zero-rated-mobile-access-language-options-wiki-page' => 'The name of the wiki page to store the country language data',
2932 );
\ No newline at end of file

Status & tagging log