Index: branches/wmf/1.18wmf1/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class ExtZeroRatedMobileAccess { |
5 | | - const VERSION = '0.0.7'; |
| 5 | + const VERSION = '0.0.8'; |
6 | 6 | |
7 | 7 | public static $renderZeroRatedLandingPage; |
8 | 8 | public static $renderZeroRatedBanner; |
— | — | @@ -24,10 +24,13 @@ |
25 | 25 | * @return bool |
26 | 26 | */ |
27 | 27 | public function beforePageDisplayHTML( &$out, &$text ) { |
28 | | - global $wgRequest, $wgConf, $wgDBname, $wgEnableZeroRatedMobileAccessTesting; |
| 28 | + global $wgRequest, $wgConf, $wgEnableZeroRatedMobileAccessTesting; |
29 | 29 | wfProfileIn( __METHOD__ ); |
30 | 30 | |
31 | | - list( $site, $lang ) = $wgConf->siteFromDB( $wgDBname ); |
| 31 | + $DB = wfGetDB( DB_MASTER ); |
| 32 | + $DBName = $DB->getDBname(); |
| 33 | + |
| 34 | + list( $site, $lang ) = $wgConf->siteFromDB( $DBName ); |
32 | 35 | if ( $site == 'wikipedia' || $wgEnableZeroRatedMobileAccessTesting ) { |
33 | 36 | |
34 | 37 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
— | — | @@ -39,8 +42,7 @@ |
40 | 43 | return true; |
41 | 44 | } |
42 | 45 | |
43 | | - $output = Html::openElement( 'div', |
44 | | - array( 'id' => 'zero-landing-page' ) ); |
| 46 | + $output = ''; |
45 | 47 | |
46 | 48 | self::$renderZeroRatedLandingPage = $wgRequest->getFuzzyBool( 'renderZeroRatedLandingPage' ); |
47 | 49 | self::$renderZeroRatedBanner = $wgRequest->getFuzzyBool( 'renderZeroRatedBanner' ); |
— | — | @@ -48,7 +50,7 @@ |
49 | 51 | self::$forceClickToViewImages = $wgRequest->getFuzzyBool( 'forceClickToViewImages' ); |
50 | 52 | self::$acceptBilling = $wgRequest->getVal( 'acceptbilling' ); |
51 | 53 | self::$title = $out->getTitle(); |
52 | | - |
| 54 | + |
53 | 55 | $carrier = $wgRequest->getHeader( 'HTTP_X_CARRIER' ); |
54 | 56 | if ( $carrier !== '(null)' && $carrier ) { |
55 | 57 | self::$renderZeroRatedBanner = true; |
— | — | @@ -74,45 +76,38 @@ |
75 | 77 | |
76 | 78 | if ( self::$isFilePage && self::$acceptBilling !== 'yes' ) { |
77 | 79 | $acceptBillingYes = Html::rawElement( 'a', |
78 | | - array('href' => $wgRequest->appendQuery( 'renderZeroRatedBanner=true&acceptbilling=yes' ) ), |
| 80 | + array( 'href' => $wgRequest->appendQuery( 'renderZeroRatedBanner=true&acceptbilling=yes' ) ), |
79 | 81 | wfMsg( 'zero-rated-mobile-access-banner-text-data-charges-yes' ) ); |
80 | 82 | $referrer = $wgRequest->getHeader( 'referer' ); |
81 | 83 | $acceptBillingNo = Html::rawElement( 'a', |
82 | | - array('href' => $wgRequest->appendQuery( 'acceptbilling=no&returnto=' . urlencode( $referrer ) ) ), |
| 84 | + array( 'href' => $wgRequest->appendQuery( 'acceptbilling=no&returnto=' . urlencode( $referrer ) ) ), |
83 | 85 | wfMsg( 'zero-rated-mobile-access-banner-text-data-charges-no' ) ); |
84 | 86 | $bannerText = Html::rawElement( 'h3', |
85 | 87 | array( 'id' => 'zero-rated-banner-text' ), |
86 | 88 | wfMsg( 'zero-rated-mobile-access-banner-text-data-charges', $acceptBillingYes, $acceptBillingNo ) ); |
87 | 89 | $banner = Html::rawElement( 'div', |
88 | | - array( 'style' => 'display:none;', |
89 | | - 'id' => 'zero-rated-banner-red' ), |
90 | | - $bannerText |
91 | | - ); |
| 90 | + array( 'style' => 'display:none;', 'id' => 'zero-rated-banner-red' ), $bannerText ); |
92 | 91 | $output .= $banner; |
93 | 92 | $out->clearHTML(); |
94 | 93 | $out->setPageTitle( null ); |
95 | 94 | } elseif ( self::$renderZeroRatedRedirect === true ) { |
96 | 95 | $returnto = $wgRequest->getVal( 'returnto' ); |
97 | 96 | $acceptBillingYes = Html::rawElement( 'a', |
98 | | - array('href' => $wgRequest->appendQuery( 'renderZeroRatedBanner=true&acceptbilling=yes&returnto=' . urlencode( $returnto ) ) ), |
| 97 | + array( 'href' => $wgRequest->appendQuery( 'renderZeroRatedBanner=true&acceptbilling=yes&returnto=' . urlencode( $returnto ) ) ), |
99 | 98 | wfMsg( 'zero-rated-mobile-access-banner-text-data-charges-yes' ) ); |
100 | 99 | $referrer = $wgRequest->getHeader( 'referer' ); |
101 | 100 | $acceptBillingNo = Html::rawElement( 'a', |
102 | | - array('href' => $wgRequest->appendQuery( 'acceptbilling=no&returnto=' . urlencode( $referrer ) ) ), |
| 101 | + array( 'href' => $wgRequest->appendQuery( 'acceptbilling=no&returnto=' . urlencode( $referrer ) ) ), |
103 | 102 | wfMsg( 'zero-rated-mobile-access-banner-text-data-charges-no' ) ); |
104 | 103 | $bannerText = Html::rawElement( 'h3', |
105 | 104 | array( 'id' => 'zero-rated-banner-text' ), |
106 | 105 | wfMsg( 'zero-rated-mobile-access-banner-text-data-charges', $acceptBillingYes, $acceptBillingNo ) ); |
107 | 106 | $banner = Html::rawElement( 'div', |
108 | | - array( 'style' => 'display:none;', |
109 | | - 'id' => 'zero-rated-banner-red' ), |
110 | | - $bannerText |
111 | | - ); |
| 107 | + array( 'style' => 'display:none;', 'id' => 'zero-rated-banner-red' ), $bannerText ); |
112 | 108 | $output .= $banner; |
113 | 109 | $out->clearHTML(); |
114 | 110 | $out->setPageTitle( null ); |
115 | 111 | } elseif ( self::$renderZeroRatedBanner === true ) { |
116 | | - // a2enmod headers >>> .htaccess >>> RequestHeader set HTTP_CARRIER Verizon |
117 | 112 | self::$carrier = $this->lookupCarrier( $carrier ); |
118 | 113 | if ( isset( self::$carrier['name'] ) ) { |
119 | 114 | $html = $out->getHTML(); |
— | — | @@ -120,14 +115,11 @@ |
121 | 116 | $out->clearHTML(); |
122 | 117 | $out->addHTML( $parsedHtml ); |
123 | 118 | $carrierLink = ( isset( self::$carrier['link'] ) ) ? self::$carrier['link'] : ''; |
124 | | - $bannerText = Html::rawElement( 'h3', |
| 119 | + $bannerText = Html::rawElement( 'span', |
125 | 120 | array( 'id' => 'zero-rated-banner-text' ), |
126 | 121 | wfMsg( 'zero-rated-mobile-access-banner-text', $carrierLink ) ); |
127 | 122 | $banner = Html::rawElement( 'div', |
128 | | - array( 'style' => 'display:none;', |
129 | | - 'id' => 'zero-rated-banner' ), |
130 | | - $bannerText |
131 | | - ); |
| 123 | + array( 'style' => 'display:none;', 'id' => 'zero-rated-banner' ), $bannerText ); |
132 | 124 | $output .= $banner; |
133 | 125 | } |
134 | 126 | } |
— | — | @@ -146,19 +138,18 @@ |
147 | 139 | 'FRANCE' => '90.6.70.28', |
148 | 140 | ); |
149 | 141 | $ip = ( strpos( $ip, '192.168.' ) === 0 ) ? $countryIps['THAILAND'] : $ip; |
150 | | - if ( IP::isValid( $ip ) ) { |
151 | | - // If no country was passed, try to do GeoIP lookup |
152 | | - // Requires php5-geoip package |
| 142 | + if ( IP::isValid( $ip ) ) { |
| 143 | + // If no country was passed, try to do GeoIP lookup |
| 144 | + // Requires php5-geoip package |
153 | 145 | if ( !$country && function_exists( 'geoip_country_code_by_name' ) ) { |
154 | 146 | $country = geoip_country_code_by_name( $ip ); |
155 | 147 | } |
156 | 148 | self::addDebugOutput( $country ); |
157 | 149 | } |
158 | 150 | $languageOptions = self::createLanguageOptionsFromWikiText(); |
159 | | - //self::$displayDebugOutput = true; |
| 151 | + // self::$displayDebugOutput = true; |
160 | 152 | $languagesForCountry = ( isset( $languageOptions[self::getFullCountryNameFromCode( $country )] ) ) ? |
161 | 153 | $languageOptions[self::getFullCountryNameFromCode( $country )] : null; |
162 | | - //self::addDebugOutput( $languageOptions ); |
163 | 154 | self::addDebugOutput( self::getFullCountryNameFromCode( $country ) ); |
164 | 155 | self::addDebugOutput( $languagesForCountry ); |
165 | 156 | self::writeDebugOutput(); |
— | — | @@ -169,10 +160,7 @@ |
170 | 161 | $languageName = $languageNames[$languagesForCountry[$i]['language']]; |
171 | 162 | $languageCode = $languagesForCountry[$i]['language']; |
172 | 163 | $output .= Html::element( 'hr' ); |
173 | | - $output .= Html::element( 'h3', |
174 | | - array( 'id' => 'lang_' . $languageCode ), |
175 | | - $languageName |
176 | | - ); |
| 164 | + $output .= Html::element( 'h3', array( 'id' => 'lang_' . $languageCode ), $languageName ); |
177 | 165 | if ( $i == 0 ) { |
178 | 166 | $output .= self::getSearchFormHtml( $languageCode ); |
179 | 167 | } else { |
— | — | @@ -207,8 +195,8 @@ |
208 | 196 | $output .= Html::closeElement( 'select' ); |
209 | 197 | } |
210 | 198 | |
211 | | - $output .= Html::closeElement( 'div' ); |
212 | | - if ( $output != '<div id="zero-landing-page"></div>' ) { |
| 199 | + if ( $output ) { |
| 200 | + $output = Html::openElement( 'div', array( 'id' => 'zero-landing-page' ) ) . $output . Html::closeElement( 'div' ); |
213 | 201 | $out->addHTML( $output ); |
214 | 202 | } |
215 | 203 | } |
— | — | @@ -218,7 +206,7 @@ |
219 | 207 | |
220 | 208 | /** |
221 | 209 | * Returns information about carrier |
222 | | - * |
| 210 | + * |
223 | 211 | * @param String $carrier: Name of carrier e.g., "Verizon Wireless" |
224 | 212 | * @return Array |
225 | 213 | */ |
— | — | @@ -241,7 +229,7 @@ |
242 | 230 | |
243 | 231 | /** |
244 | 232 | * Returns the Html of a page with the various links appended with zeropartner parameter |
245 | | - * |
| 233 | + * |
246 | 234 | * @param String $html: Html of current page |
247 | 235 | * @return String |
248 | 236 | */ |
— | — | @@ -278,11 +266,9 @@ |
279 | 267 | foreach ( $zeroRatedLinks as $zeroRatedLink ) { |
280 | 268 | $zeroRatedLinkHref = $zeroRatedLink->getAttribute( 'href' ); |
281 | 269 | if ( $zeroRatedLinkHref && substr( $zeroRatedLinkHref, 0, 1 ) !== '#' ) { |
282 | | - $zeroPartnerUrl = $this->appendQueryString( $zeroRatedLinkHref, |
283 | | - array( array( 'name' => 'zeropartner', |
284 | | - 'value' => ( isset( self::$carrier['partnerId'] ) ) ? self::$carrier['partnerId'] : 0 ), |
285 | | - array('name' => 'renderZeroRatedBanner', |
286 | | - 'value' => 'true') ) ); |
| 270 | + $partnerId = isset( self::$carrier['partnerId'] ) ? self::$carrier['partnerId'] : 0; |
| 271 | + $zeroPartnerUrl = wfAppendQuery( $zeroRatedLinkHref, |
| 272 | + array( 'zeropartner' => $partnerId, 'renderZeroRatedBanner' => 'true' ) ); |
287 | 273 | if ( $zeroPartnerUrl ) { |
288 | 274 | $zeroRatedLink->setAttribute( 'href', $zeroPartnerUrl ); |
289 | 275 | } |
— | — | @@ -293,13 +279,11 @@ |
294 | 280 | foreach ( $zeroRatedExternalLinks as $zeroRatedExternalLink ) { |
295 | 281 | $zeroRatedExternalLinkHref = $zeroRatedExternalLink->getAttribute( 'href' ); |
296 | 282 | if ( $zeroRatedExternalLinkHref && substr( $zeroRatedExternalLinkHref, 0, 1 ) !== '#' ) { |
297 | | - $zeroPartnerUrl = $this->appendQueryString( $zeroRatedLinkHref, |
298 | | - array( array( 'name' => 'zeropartner', |
299 | | - 'value' => ( isset( self::$carrier['partnerId'] ) ) ? self::$carrier['partnerId'] : 0 ), |
300 | | - array('name' => 'renderZeroRatedBanner', |
301 | | - 'value' => 'true') ) ); |
| 283 | + $partnerId = isset( self::$carrier['partnerId'] ) ? self::$carrier['partnerId'] : 0; |
| 284 | + $zeroPartnerUrl = wfAppendQuery( $zeroRatedLinkHref, |
| 285 | + array( 'zeropartner' => $partnerId, 'renderZeroRatedBanner' => 'true' ) ); |
302 | 286 | if ( $zeroPartnerUrl ) { |
303 | | - $zeroRatedExternalLink->setAttribute( 'href', '?renderZeroRatedRedirect=true&returnto=' . urlencode($zeroRatedExternalLinkHref) ); |
| 287 | + $zeroRatedExternalLink->setAttribute( 'href', '?renderZeroRatedRedirect=true&returnto=' . urlencode( $zeroRatedExternalLinkHref ) ); |
304 | 288 | } |
305 | 289 | } |
306 | 290 | } |
— | — | @@ -310,58 +294,8 @@ |
311 | 295 | } |
312 | 296 | |
313 | 297 | /** |
314 | | - * Returns the url with querystring parameters appended |
315 | | - * |
316 | | - * @param String $url: valid url to append querystring |
317 | | - * @param Array $queryStringParameters: array of parameters to add to querystring |
318 | | - * @return String |
319 | | - */ |
320 | | - private function appendQueryString( $url, $queryStringParameters ) { |
321 | | - wfProfileIn( __METHOD__ ); |
322 | | - $parsedUrl = parse_url( $url ); |
323 | | - if ( isset( $parsedUrl['query'] ) ) { |
324 | | - parse_str( $parsedUrl['query'], $queryString ); |
325 | | - foreach ( $queryStringParameters as $queryStringParameter ) { |
326 | | - $queryString[$queryStringParameter['name']] = $queryStringParameter['value']; |
327 | | - } |
328 | | - $parsedUrl['query'] = http_build_query( $queryString ); |
329 | | - } else { |
330 | | - $parsedUrl['query'] = ''; |
331 | | - foreach ( $queryStringParameters as $queryStringParameter ) { |
332 | | - $parsedUrl['query'] .= "{$queryStringParameter['name']}={$queryStringParameter['value']}&"; |
333 | | - } |
334 | | - if ( substr( $parsedUrl['query'], -1, 1 ) === '&' ) { |
335 | | - $parsedUrl['query'] = substr( $parsedUrl['query'], 0, -1 ); |
336 | | - } |
337 | | - } |
338 | | - wfProfileOut( __METHOD__ ); |
339 | | - return $this->unParseUrl( $parsedUrl ); |
340 | | - } |
341 | | - |
342 | | - /** |
343 | | - * Returns the full url |
344 | | - * |
345 | | - * @param Array $parsedUrl: the array returned from parse_url |
346 | | - * @return String |
347 | | - */ |
348 | | - private function unParseUrl( $parsedUrl ) { |
349 | | - wfProfileIn( __METHOD__ ); |
350 | | - $scheme = isset( $parsedUrl['scheme'] ) ? $parsedUrl['scheme'] . '://' : ''; |
351 | | - $host = isset( $parsedUrl['host'] ) ? $parsedUrl['host'] : ''; |
352 | | - $port = isset( $parsedUrl['port'] ) ? ':' . $parsedUrl['port'] : ''; |
353 | | - $user = isset( $parsedUrl['user'] ) ? $parsedUrl['user'] : ''; |
354 | | - $pass = isset( $parsedUrl['pass'] ) ? ':' . $parsedUrl['pass'] : ''; |
355 | | - $pass = ( $user || $pass ) ? "$pass@" : ''; |
356 | | - $path = isset( $parsedUrl['path'] ) ? $parsedUrl['path'] : ''; |
357 | | - $query = isset( $parsedUrl['query'] ) ? '?' . $parsedUrl['query'] : ''; |
358 | | - $fragment = isset( $parsedUrl['fragment'] ) ? '#' . $parsedUrl['fragment'] : ''; |
359 | | - wfProfileOut( __METHOD__ ); |
360 | | - return "$scheme$user$pass$host$port$path$query$fragment"; |
361 | | - } |
362 | | - |
363 | | - /** |
364 | 298 | * Adds object to debugOutput Array |
365 | | - * |
| 299 | + * |
366 | 300 | * @param Object $object: any valid PHP object |
367 | 301 | * @return bool |
368 | 302 | */ |
— | — | @@ -376,14 +310,14 @@ |
377 | 311 | |
378 | 312 | /** |
379 | 313 | * Writes objects from the debugOutput Array to buffer |
380 | | - * |
| 314 | + * |
381 | 315 | * @return bool |
382 | 316 | */ |
383 | 317 | private static function writeDebugOutput() { |
384 | 318 | wfProfileIn( __METHOD__ ); |
385 | 319 | if ( self::$debugOutput && self::$displayDebugOutput === true ) { |
386 | 320 | echo "<pre>"; |
387 | | - foreach( self::$debugOutput as $debugOutput ) { |
| 321 | + foreach ( self::$debugOutput as $debugOutput ) { |
388 | 322 | var_dump( $debugOutput ); |
389 | 323 | } |
390 | 324 | echo "</pre>"; |
— | — | @@ -392,16 +326,21 @@ |
393 | 327 | return true; |
394 | 328 | } |
395 | 329 | |
| 330 | + /** |
| 331 | + * Returns the carrier options array parsed from a valid wiki page |
| 332 | + * |
| 333 | + * @return Array |
| 334 | + */ |
396 | 335 | private static function createCarrierOptionsFromWikiText() { |
397 | 336 | global $wgMemc; |
398 | 337 | wfProfileIn( __METHOD__ ); |
399 | | - $carrierOptionsWikiPage = wfMsg( 'zero-rated-mobile-access-carrier-options-wiki-page' ); |
400 | | - $title = Title::newFromText( $carrierOptionsWikiPage, NS_MEDIAWIKI ); |
401 | | - // Use the revision directly to prevent other hooks to be called |
402 | | - $rev = Revision::newFromTitle( $title ); |
| 338 | + |
| 339 | + $carrierOptionsWikiPage = wfMsgForContent( 'zero-rated-mobile-access-carrier-options-wiki-page' ); |
| 340 | + |
| 341 | + list( $revId, $rev ) = self::getOptionsFromForeignWiki( $carrierOptionsWikiPage ); |
| 342 | + |
403 | 343 | if ( $rev ) { |
404 | | - $sha1OfRev = $rev->getSize(); |
405 | | - $key = wfMemcKey( 'zero-rated-mobile-access-carrier-options', $sha1OfRev ); |
| 344 | + $key = wfMemcKey( 'zero-rated-mobile-access-carrier-options', $revId ); |
406 | 345 | $carrierOptions = $wgMemc->get( $key ); |
407 | 346 | } else { |
408 | 347 | $carrierOptions = null; |
— | — | @@ -411,7 +350,7 @@ |
412 | 351 | $carrierOptions = array(); |
413 | 352 | $lines = array(); |
414 | 353 | if ( $rev ) { |
415 | | - $lines = explode( "\n", $rev->getRawText() ); |
| 354 | + $lines = explode( "\n", $rev ); |
416 | 355 | } |
417 | 356 | if ( $lines && count( $lines ) > 0 ) { |
418 | 357 | $sizeOfLines = sizeof( $lines ); |
— | — | @@ -426,7 +365,7 @@ |
427 | 366 | if ( $i % 3 === 1 ) { |
428 | 367 | $carrierOptions[$carrierName]['url'] = trim( str_replace( '** ', '', $line ) ); |
429 | 368 | $carrierLink = Html::rawElement( 'a', |
430 | | - array('href' => $carrierOptions[$carrierName]['url'] ), |
| 369 | + array( 'href' => $carrierOptions[$carrierName]['url'] ), |
431 | 370 | $carrierOptions[$carrierName]['name'] ); |
432 | 371 | $carrierOptions[$carrierName]['link'] = $carrierLink; |
433 | 372 | } elseif ( $i % 3 === 2 ) { |
— | — | @@ -442,20 +381,79 @@ |
443 | 382 | } |
444 | 383 | |
445 | 384 | /** |
446 | | - * Returns the language options array parsed from a valid Wiki page |
447 | | - * |
| 385 | + * Returns the foreign wiki options array from a valid wiki page |
| 386 | + * |
448 | 387 | * @return Array |
449 | 388 | */ |
| 389 | + private static function getOptionsFromForeignWiki( $pageName ) { |
| 390 | + global $wgMemc; |
| 391 | + wfProfileIn( __METHOD__ ); |
| 392 | + |
| 393 | + $key = null; |
| 394 | + $rev = null; |
| 395 | + |
| 396 | + if ( $pageName ) { |
| 397 | + |
| 398 | + $memcKey = wfMemcKey( 'zero-rated-mobile-access-foreign-options-', md5( $pageName ) ); |
| 399 | + $foreignOptions = $wgMemc->get( $memcKey ); |
| 400 | + |
| 401 | + if ( !$foreignOptions ) { |
| 402 | + $options = array(); |
| 403 | + $options['method'] = 'GET'; |
| 404 | + $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&&rvlimit=1&rvprop=content&format=json&titles=MediaWiki:' . $pageName; |
| 405 | + $req = ( class_exists( 'MWHttpRequest' ) ) ? MWHttpRequest::factory( $url, $options ) : HttpRequest::factory( $url, $options ); |
| 406 | + |
| 407 | + $status = $req->execute(); |
| 408 | + |
| 409 | + if ( !$status->isOK() ) { |
| 410 | + $error = $req->getContent(); |
| 411 | + wfProfileOut( __METHOD__ ); |
| 412 | + return array( $key, $rev ); |
| 413 | + } |
| 414 | + |
| 415 | + $ret = $req->getContent(); |
| 416 | + |
| 417 | + $jsonData = FormatJson::decode( $ret, true ); |
| 418 | + |
| 419 | + if ( isset( $jsonData['query']['pages'] ) ) { |
| 420 | + $key = key( $jsonData['query']['pages'] ); |
| 421 | + if ( !is_int( $key ) ) { |
| 422 | + $key = null; |
| 423 | + } |
| 424 | + |
| 425 | + foreach ( $jsonData['query']['pages'] as $pages ) { |
| 426 | + if ( isset( $pages['revisions'][0]['*'] ) ) { |
| 427 | + $rev = $pages['revisions'][0]['*']; |
| 428 | + } |
| 429 | + } |
| 430 | + } |
| 431 | + |
| 432 | + if ( $key && $rev ) { |
| 433 | + $wgMemc->set( $memcKey, array( $key, $rev ), self::getMaxAge() ); |
| 434 | + } |
| 435 | + } else { |
| 436 | + list ( $key, $rev ) = $foreignOptions; |
| 437 | + } |
| 438 | + } |
| 439 | + |
| 440 | + wfProfileOut( __METHOD__ ); |
| 441 | + return array( $key, $rev ); |
| 442 | + } |
| 443 | + |
| 444 | + /** |
| 445 | + * Returns the language options array parsed from a valid wiki page |
| 446 | + * |
| 447 | + * @return Array |
| 448 | + */ |
450 | 449 | private static function createLanguageOptionsFromWikiText() { |
451 | 450 | global $wgMemc; |
452 | 451 | wfProfileIn( __METHOD__ ); |
453 | 452 | $languageOptionsWikiPage = wfMsgForContent( 'zero-rated-mobile-access-language-options-wiki-page' ); |
454 | | - $title = Title::newFromText( $languageOptionsWikiPage, NS_MEDIAWIKI ); |
455 | | - // Use the revision directly to prevent other hooks to be called |
456 | | - $rev = Revision::newFromTitle( $title ); |
| 453 | + |
| 454 | + list( $revId, $rev ) = self::getOptionsFromForeignWiki( $languageOptionsWikiPage ); |
| 455 | + |
457 | 456 | if ( $rev ) { |
458 | | - $sha1OfRev = $rev->getSize(); |
459 | | - $key = wfMemcKey( 'zero-rated-mobile-access-language-options', $sha1OfRev ); |
| 457 | + $key = wfMemcKey( 'zero-rated-mobile-access-language-options', $revId ); |
460 | 458 | $languageOptions = $wgMemc->get( $key ); |
461 | 459 | } else { |
462 | 460 | $languageOptions = null; |
— | — | @@ -465,7 +463,7 @@ |
466 | 464 | $languageOptions = array(); |
467 | 465 | $lines = array(); |
468 | 466 | if ( $rev ) { |
469 | | - $lines = explode( "\n", $rev->getRawText() ); |
| 467 | + $lines = explode( "\n", $rev ); |
470 | 468 | } |
471 | 469 | if ( $lines && count( $lines ) > 0 ) { |
472 | 470 | $sizeOfLines = sizeof( $lines ); |
— | — | @@ -475,13 +473,13 @@ |
476 | 474 | $countryName = strtoupper( str_replace( '* ', '', $line ) ); |
477 | 475 | $languageOptions[$countryName] = ''; |
478 | 476 | } elseif ( strpos( $line, '**' ) === 0 && $i > 0 ) { |
479 | | - $lineParts = explode('#', $line); |
480 | | - $language = ( isset( $lineParts[0] ) ) ? |
| 477 | + $lineParts = explode( '#', $line ); |
| 478 | + $language = ( isset( $lineParts[0] ) ) ? |
481 | 479 | trim( str_replace( '** ', '', $lineParts[0] ) ) : |
482 | 480 | trim( str_replace( '** ', '', $line ) ) ; |
483 | 481 | if ( $language !== 'portal' && $language !== 'other' ) { |
484 | 482 | $languageOptions[$countryName][] = ( isset( $lineParts[1] ) ) ? |
485 | | - array( 'language' => $language, |
| 483 | + array( 'language' => $language, |
486 | 484 | 'percentage' => intval( str_replace( '%', '', trim( $lineParts[1] ) ) ) ) : |
487 | 485 | $language; |
488 | 486 | } |
— | — | @@ -496,7 +494,7 @@ |
497 | 495 | |
498 | 496 | /** |
499 | 497 | * Returns the Unix timestamp of current day's first second |
500 | | - * |
| 498 | + * |
501 | 499 | * @return int: Timestamp |
502 | 500 | */ |
503 | 501 | private static function todaysStart() { |
— | — | @@ -519,7 +517,7 @@ |
520 | 518 | |
521 | 519 | /** |
522 | 520 | * Returns the number of seconds an item should stay in cache |
523 | | - * |
| 521 | + * |
524 | 522 | * @return int: Time in seconds |
525 | 523 | */ |
526 | 524 | private static function getMaxAge() { |
— | — | @@ -532,7 +530,7 @@ |
533 | 531 | |
534 | 532 | /** |
535 | 533 | * Get full country name from code |
536 | | - * |
| 534 | + * |
537 | 535 | * @param string $code: alpha-2 code ISO 3166 country code |
538 | 536 | * @return String |
539 | 537 | */ |
— | — | @@ -786,7 +784,7 @@ |
787 | 785 | |
788 | 786 | /** |
789 | 787 | * Search form for various languages |
790 | | - * |
| 788 | + * |
791 | 789 | * @param string $langCode: alpha-2 code for language |
792 | 790 | * @return String |
793 | 791 | */ |
— | — | @@ -799,7 +797,7 @@ |
800 | 798 | <div id="sq" class="divclearable"> |
801 | 799 | <input type="text" name="search" id="search" size="22" value="" autocorrect="off" autocomplete="off" autocapitalize="off" maxlength="1024"> |
802 | 800 | <div class="clearlink" id="clearsearch" title="Clear"></div> |
803 | | - </div> |
| 801 | + </div> |
804 | 802 | <button id="goButton" type="submit">{$searchValue}</button> |
805 | 803 | </form> |
806 | 804 | HTML; |
Index: branches/wmf/1.18wmf1/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccessTemplate.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | * @param $options array |
26 | 26 | */ |
27 | 27 | public function setByArray( $options ) { |
28 | | - foreach ($options as $name => $value ) { |
| 28 | + foreach ( $options as $name => $value ) { |
29 | 29 | $this->set( $name, $value ); |
30 | 30 | } |
31 | 31 | } |
Index: branches/wmf/1.18wmf1/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.i18n.php |
— | — | @@ -35,7 +35,6 @@ |
36 | 36 | $messages['qqq'] = array( |
37 | 37 | 'zero-rated-mobile-access-desc' => '{{desc}}', |
38 | 38 | 'zero-rated-mobile-access-search' => 'Text for search action on the search button', |
39 | | - 'zero-rated-mobile-access-language-options-wiki-page' => 'The name of the wiki page in the MediaWiki namespace to store the country language data', |
40 | 39 | 'zero-rated-mobile-access-language-selection' => 'Text to show the user when they select a language option', |
41 | 40 | 'zero-rated-mobile-access-home-page-selection' => 'Name of language followed by text to show user in local link to Wikipedia', |
42 | 41 | 'zero-rated-mobile-access-home-page-selection-text' => 'Text to show user prior to selection of language option', |
— | — | @@ -48,11 +47,135 @@ |
49 | 48 | 'zero-rated-mobile-access-click-to-view-image' => 'Text for viewing an image link', |
50 | 49 | ); |
51 | 50 | |
| 51 | +/** German (Deutsch) |
| 52 | + * @author Kghbln |
| 53 | + */ |
| 54 | +$messages['de'] = array( |
| 55 | + 'zero-rated-mobile-access-desc' => 'Stellt Mobilfunkanbietern Funktionen bereit, mit denen diese kostenfreien Zugriff auf das Wiki ermöglichen können', |
| 56 | + 'zero-rated-mobile-access-search' => 'Suche', |
| 57 | + 'zero-rated-mobile-access-language-selection' => 'Alle Sprachen', |
| 58 | + 'zero-rated-mobile-access-home-page-selection' => '$1 Startseite', |
| 59 | + 'zero-rated-mobile-access-home-page-selection-text' => 'Oder besuche die Startseite in der folgenden Sprache:', |
| 60 | + 'zero-rated-mobile-access-banner-text' => 'Kostenloser Zugriff auf Wikipedia über $1', |
| 61 | + 'zero-rated-mobile-access-banner-text-data-charges' => 'Datenübertragungsgebühren können anwendbar sein: $1 oder $2', |
| 62 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Ja', |
| 63 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'Nein', |
| 64 | + 'zero-rated-mobile-access-click-to-view-image' => 'Hier klicken, um das Bild von „$1“ zu sehen …', |
| 65 | +); |
| 66 | + |
| 67 | +/** German (formal address) (Deutsch (Sie-Form)) |
| 68 | + * @author Kghbln |
| 69 | + */ |
| 70 | +$messages['de-formal'] = array( |
| 71 | + 'zero-rated-mobile-access-home-page-selection-text' => 'Oder besuchen Sie die Startseite in der folgenden Sprache:', |
| 72 | +); |
| 73 | + |
| 74 | +/** Lower Sorbian (Dolnoserbski) |
| 75 | + * @author Michawiki |
| 76 | + */ |
| 77 | +$messages['dsb'] = array( |
| 78 | + 'zero-rated-mobile-access-desc' => 'Staja póbitowarjam mobilneje telefonije funkcije k dispoziciji, kótarež zmóžnjaju dermotny pśistup', |
| 79 | + 'zero-rated-mobile-access-search' => 'Pytaś', |
| 80 | + 'zero-rated-mobile-access-language-selection' => 'Wšykne rěcy', |
| 81 | + 'zero-rated-mobile-access-home-page-selection' => '$1 startowy bok', |
| 82 | + 'zero-rated-mobile-access-home-page-selection-text' => 'Abo źi k startowemu bokoju w slědujucej rěcy:', |
| 83 | + 'zero-rated-mobile-access-banner-text' => 'Lichotna Wikipedija wót $1', |
| 84 | + 'zero-rated-mobile-access-banner-text-data-charges' => 'Pśi pśenjasenju datow mógu se płaśonki wuběraś: $1 abo $2', |
| 85 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Jo', |
| 86 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'Ně', |
| 87 | + 'zero-rated-mobile-access-click-to-view-image' => 'Klikni how, aby wobraz wót "$1" wiźeł...', |
| 88 | +); |
| 89 | + |
| 90 | +/** French (Français) |
| 91 | + * @author Gomoko |
| 92 | + */ |
| 93 | +$messages['fr'] = array( |
| 94 | + 'zero-rated-mobile-access-desc' => 'Fournit les fonctionnalités pour les fournisseurs de mobile qui proposent un accès libre', |
| 95 | + 'zero-rated-mobile-access-search' => 'Rechercher', |
| 96 | + 'zero-rated-mobile-access-language-selection' => 'Toutes les langues', |
| 97 | + 'zero-rated-mobile-access-home-page-selection' => "page d'accueil $1", |
| 98 | + 'zero-rated-mobile-access-home-page-selection-text' => "Ou allez à la page d'accueil dans la langue suivante:", |
| 99 | + 'zero-rated-mobile-access-banner-text' => 'Wikipedia libre depuis $1', |
| 100 | + 'zero-rated-mobile-access-banner-text-data-charges' => "Les frais de données peuvent s'appliquer de façon permanente: $1 ou $2", |
| 101 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Oui', |
| 102 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'Non', |
| 103 | + 'zero-rated-mobile-access-click-to-view-image' => 'Cliquez pour voir l\'image de, "$1"...', |
| 104 | +); |
| 105 | + |
| 106 | +/** Upper Sorbian (Hornjoserbsce) |
| 107 | + * @author Michawiki |
| 108 | + */ |
| 109 | +$messages['hsb'] = array( |
| 110 | + 'zero-rated-mobile-access-desc' => 'Staja poskićowarjam mobilneho škričkowanja funkcije k dispoziciji, kotrež darmotny přistup zmóžnjeja', |
| 111 | + 'zero-rated-mobile-access-search' => 'Pytać', |
| 112 | + 'zero-rated-mobile-access-language-selection' => 'Wšě rěče', |
| 113 | + 'zero-rated-mobile-access-home-page-selection' => '$1 startowa strona', |
| 114 | + 'zero-rated-mobile-access-home-page-selection-text' => 'Abo wopytaj startowu stronu w slědowacej rěči:', |
| 115 | + 'zero-rated-mobile-access-banner-text' => 'Swobodna Wikipedija wot $1', |
| 116 | + 'zero-rated-mobile-access-banner-text-data-charges' => 'Při přenjesenju datow móža so popłatki zběrać: $1 abo $2', |
| 117 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Haj', |
| 118 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'Ně', |
| 119 | + 'zero-rated-mobile-access-click-to-view-image' => 'Klikń tu, zo by wobraz wot "$1" widźał...', |
| 120 | +); |
| 121 | + |
| 122 | +/** Interlingua (Interlingua) |
| 123 | + * @author McDutchie |
| 124 | + */ |
| 125 | +$messages['ia'] = array( |
| 126 | + 'zero-rated-mobile-access-desc' => 'Provide functionalitate pro fornitores mobile que offere accesso libere', |
| 127 | + 'zero-rated-mobile-access-search' => 'Cercar', |
| 128 | + 'zero-rated-mobile-access-language-selection' => 'Tote le linguas', |
| 129 | + 'zero-rated-mobile-access-home-page-selection' => 'Pagina principal in $1', |
| 130 | + 'zero-rated-mobile-access-home-page-selection-text' => 'O va al pagina principal in lingua:', |
| 131 | + 'zero-rated-mobile-access-banner-text' => 'Wikipedia gratuite de $1', |
| 132 | + 'zero-rated-mobile-access-banner-text-data-charges' => 'Costos de datos pote esser applicate. Continuar ($1 o $2)?', |
| 133 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Si', |
| 134 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'No', |
| 135 | + 'zero-rated-mobile-access-click-to-view-image' => 'Clicca pro vider le imagine de "$1"...', |
| 136 | +); |
| 137 | + |
52 | 138 | /** Japanese (日本語) |
53 | 139 | * @author Patrick Reilly |
54 | 140 | */ |
55 | | -$messages['ja'] = array ( |
| 141 | +$messages['ja'] = array( |
56 | 142 | 'zero-rated-mobile-access-desc' => 'ゼロ格モバイルアクセス', |
57 | 143 | 'zero-rated-mobile-access-search' => '検索する', |
58 | 144 | ); |
59 | 145 | |
| 146 | +/** Macedonian (Македонски) |
| 147 | + * @author Bjankuloski06 |
| 148 | + */ |
| 149 | +$messages['mk'] = array( |
| 150 | + 'zero-rated-mobile-access-desc' => 'Овозможува функции за мобилни оператори што даваат бесплатен пристап', |
| 151 | + 'zero-rated-mobile-access-search' => 'Пребарај', |
| 152 | + 'zero-rated-mobile-access-language-selection' => 'Сите јазици', |
| 153 | + 'zero-rated-mobile-access-home-page-selection' => 'Главна страница на $1', |
| 154 | + 'zero-rated-mobile-access-home-page-selection-text' => 'Или пак посетете ја главната страница на следниов јазик:', |
| 155 | + 'zero-rated-mobile-access-banner-text' => 'Бесплатна Википедија од $1', |
| 156 | + 'zero-rated-mobile-access-banner-text-data-charges' => 'Може да ви биде побарана доплата за податоците. Сакате да продолжите? $1 / $2', |
| 157 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Да', |
| 158 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'Не', |
| 159 | + 'zero-rated-mobile-access-click-to-view-image' => 'Стиснете за да ја погледате сликата на „$1“...', |
| 160 | +); |
| 161 | + |
| 162 | +/** Dutch (Nederlands) |
| 163 | + * @author Siebrand |
| 164 | + */ |
| 165 | +$messages['nl'] = array( |
| 166 | + 'zero-rated-mobile-access-search' => 'Zoeken', |
| 167 | + 'zero-rated-mobile-access-language-selection' => 'Alle talen', |
| 168 | + 'zero-rated-mobile-access-banner-text' => 'Gratis Wikipedia van $1', |
| 169 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Ja', |
| 170 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'Nee', |
| 171 | +); |
| 172 | + |
| 173 | +/** Telugu (తెలుగు) |
| 174 | + * @author Veeven |
| 175 | + */ |
| 176 | +$messages['te'] = array( |
| 177 | + 'zero-rated-mobile-access-search' => 'వెతుకు', |
| 178 | + 'zero-rated-mobile-access-language-selection' => 'అన్ని భాషలు', |
| 179 | + 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'అవును', |
| 180 | + 'zero-rated-mobile-access-banner-text-data-charges-no' => 'కాదు', |
| 181 | +); |
| 182 | + |