r108106 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108105‎ | r108106 | r108107 >
Date:01:31, 5 January 2012
Author:preilly
Status:ok (Comments)
Tags:mobile 
Comment:
move carrier options settings to wiki page
Modified paths:
  • /trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php (modified) (history)
  • /trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php
@@ -199,27 +199,17 @@
200200 */
201201 private function lookupCarrier( $carrier ) {
202202 wfProfileIn( __METHOD__ );
203 - $carrierLink = '';
204 - $carrierLinkData = '';
205 - switch ( $carrier ) {
206 - case 'Verizon':
207 - $carrierLinkData = array( 'name' => 'Verizon Wireless',
208 - 'url' => 'http://www.verizonwireless.com/b2c/index.html',
209 - 'partnerId' => '1006' );
210 - break;
211 - case 'Orange':
212 - $carrierLinkData = array( 'name' => 'Orange Tunisia',
213 - 'url' => 'http://www.orange.tn/',
214 - 'partnerId' => '1007' );
215 - break;
 203+ $carrierLinkData = array();
 204+ $carrier = strtoupper( $carrier );
 205+
 206+ $allCarrierLinkData = $this->createCarrierOptionsFromWikiText();
 207+
 208+ if ( is_array( $allCarrierLinkData ) ) {
 209+ if ( isset( $allCarrierLinkData[$carrier] ) ) {
 210+ $carrierLinkData = $allCarrierLinkData[$carrier];
 211+ }
216212 }
217213
218 - if ( is_array( $carrierLinkData ) ) {
219 - $carrierLink = Html::rawElement( 'a',
220 - array('href' => $carrierLinkData['url'] ),
221 - $carrierLinkData['name'] );
222 - }
223 - $carrierLinkData['link'] = $carrierLink;
224214 wfProfileOut( __METHOD__ );
225215 return $carrierLinkData;
226216 }
@@ -360,7 +350,52 @@
361351 wfProfileOut( __METHOD__ );
362352 return true;
363353 }
 354+
 355+ private static function createCarrierOptionsFromWikiText() {
 356+ global $wgMemc;
 357+ wfProfileIn( __METHOD__ );
 358+ $carrierOptionsWikiPage = wfMsg( 'zero-rated-mobile-access-carrier-options-wiki-page' );
 359+ $title = Title::newFromText( $carrierOptionsWikiPage, NS_MEDIAWIKI );
 360+ // Use the revision directly to prevent other hooks to be called
 361+ $rev = Revision::newFromTitle( $title );
 362+ $sha1OfRev = $rev->getSha1();
 363+ $key = wfMemcKey( 'zero-rated-mobile-access-carrier-options', $sha1OfRev );
 364+ $carrierOptions = $wgMemc->get( $key );
364365
 366+ if ( !$carrierOptions ) {
 367+ $carrierOptions = array();
 368+ $lines = array();
 369+ if ( $rev ) {
 370+ $lines = explode( "\n", $rev->getRawText() );
 371+ }
 372+ if ( $lines && count( $lines ) > 0 ) {
 373+ $sizeOfLines = sizeof( $lines );
 374+ for ( $i = 0; $i < $sizeOfLines; $i++ ) {
 375+ $line = $lines[$i];
 376+ if ( strpos( $line, '*' ) === 0 && strpos( $line, '**' ) !== 0 && $i >= 0 ) {
 377+ $carrierName = strtoupper( str_replace( '* ', '', $line ) );
 378+ $carrierRaw = str_replace( '* ', '', $line );
 379+ $carrierOptions[$carrierName] = '';
 380+ $carrierOptions[$carrierName]['name'] = $carrierRaw;
 381+ } elseif ( strpos( $line, '**' ) === 0 && $i > 0 ) {
 382+ if ( $i % 3 === 1 ) {
 383+ $carrierOptions[$carrierName]['url'] = trim( str_replace( '** ', '', $line ) );
 384+ $carrierLink = Html::rawElement( 'a',
 385+ array('href' => $carrierOptions[$carrierName]['url'] ),
 386+ $carrierOptions[$carrierName]['name'] );
 387+ $carrierOptions[$carrierName]['link'] = $carrierLink;
 388+ } elseif ( $i % 3 === 2 ) {
 389+ $carrierOptions[$carrierName]['partnerId'] = intval( trim( str_replace( '** ', '', $line ) ) );
 390+ }
 391+ }
 392+ }
 393+ }
 394+ $wgMemc->set( $key, $carrierOptions, self::getMaxAge() );
 395+ }
 396+ wfProfileOut( __METHOD__ );
 397+ return $carrierOptions;
 398+ }
 399+
365400 /**
366401 * Returns the language options array parsed from a valid Wiki page
367402 *
@@ -376,7 +411,7 @@
377412 $sha1OfRev = $rev->getSha1();
378413 $key = wfMemcKey( 'zero-rated-mobile-access-language-options', $sha1OfRev );
379414 $languageOptions = $wgMemc->get( $key );
380 -
 415+
381416 if ( !$languageOptions ) {
382417 $languageOptions = array();
383418 $lines = array();
Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.i18n.php
@@ -16,6 +16,7 @@
1717 'zero-rated-mobile-access-desc' => 'Provides features for mobile providers that provide free access',
1818 'zero-rated-mobile-access-search' => 'Search',
1919 'zero-rated-mobile-access-language-options-wiki-page' => 'Language_options',
 20+ 'zero-rated-mobile-access-carrier-options-wiki-page' => 'Carrier_options',
2021 'zero-rated-mobile-access-language-selection' => 'All languages',
2122 'zero-rated-mobile-access-home-page-selection' => '$1 home page',
2223 'zero-rated-mobile-access-home-page-selection-text' => 'Or go to the home page in the following language:',
@@ -35,6 +36,7 @@
3637 'zero-rated-mobile-access-desc' => '{{desc}}',
3738 'zero-rated-mobile-access-search' => 'Text for search action on the search button',
3839 'zero-rated-mobile-access-language-options-wiki-page' => 'The name of the wiki page to store the country language data',
 40+ 'zero-rated-mobile-access-carrier-options-wiki-page' => 'The name of the wiki page to store the carrier data',
3941 'zero-rated-mobile-access-language-selection' => 'Text to show the user when they select a language option',
4042 'zero-rated-mobile-access-home-page-selection' => 'name of language followed by text to show user in local link to Wikipedia',
4143 'zero-rated-mobile-access-home-page-selection-text' => 'Text to show user prior to selection of language option',

Comments

#Comment by MaxSem (talk | contribs)   11:10, 19 January 2012

Swapping check order would allow getting rid of second condition in if ( strpos( $line, '*' ) === 0 && strpos( $line, '**' ) !== 0 && $i >= 0 ), otherwise looks ok.

Status & tagging log