Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.php |
— | — | @@ -60,16 +60,17 @@ |
61 | 61 | self::$renderZeroRatedLandingPage = $wgRequest->getInt( 'renderZeroRatedLandingPage' ); |
62 | 62 | if ( self::$renderZeroRatedLandingPage === 1 ) { |
63 | 63 | echo wfMsg( 'zero-rated-mobile-access-desc' ); |
| 64 | + $languageNames = Language::getLanguageNames(); |
64 | 65 | $country = $wgRequest->getVal( 'country' ); |
65 | 66 | $ip = ( $wgRequest->getVal( 'ip') ) ? $wgRequest->getVal( 'ip' ) : wfGetIP(); |
66 | 67 | // Temporary hack to allow for testing on localhost |
67 | 68 | $countryIps = array( |
68 | | - 'GERMANY' => '80.237.226.75', |
69 | | - 'MEXICO' => '187.184.240.247', |
70 | | - 'THAILAND' => '180.180.150.104', |
71 | | - 'FRANCE' => '90.6.70.28', |
| 69 | + 'GERMANY' => '80.237.226.75', |
| 70 | + 'MEXICO' => '187.184.240.247', |
| 71 | + 'THAILAND' => '180.180.150.104', |
| 72 | + 'FRANCE' => '90.6.70.28', |
72 | 73 | ); |
73 | | - $ip = ( strpos( $ip, '192.168.' ) === 0 ) ? $countryIps['FRANCE'] : $ip; |
| 74 | + $ip = ( strpos( $ip, '192.168.' ) === 0 ) ? $countryIps['THAILAND'] : $ip; |
74 | 75 | if ( IP::isValid( $ip ) ) { |
75 | 76 | // If no country was passed, try to do GeoIP lookup |
76 | 77 | // Requires php5-geoip package |
— | — | @@ -80,11 +81,35 @@ |
81 | 82 | } |
82 | 83 | $languageOptions = self::createLanguageOptionsFromWikiText(); |
83 | 84 | //self::$displayDebugOutput = true; |
| 85 | + $languagesForCountry = $languageOptions[self::getFullCountryNameFromCode( $country )]; |
84 | 86 | //self::addDebugOutput( $languageOptions ); |
85 | 87 | self::addDebugOutput( self::getFullCountryNameFromCode( $country ) ); |
86 | | - self::addDebugOutput( $languageOptions[self::getFullCountryNameFromCode( $country )] ); |
| 88 | + self::addDebugOutput( $languagesForCountry ); |
87 | 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 | + ), |
| 96 | + $languageNames[$language['language']]); |
| 97 | + echo Html::element( 'hr', |
| 98 | + array(), ''); |
| 99 | + echo self::getSearchFormHtml( $language['language'] ); |
| 100 | + } |
| 101 | + } |
88 | 102 | } |
| 103 | + $output = Html::openElement( 'select', |
| 104 | + array( 'id' => 'languageselection', |
| 105 | + 'onchange' => 'javascript:window.location = this.options[this.selectedIndex].value;' ) ); |
| 106 | + foreach ( $languageNames as $languageCode => $languageName ) { |
| 107 | + $output .= Html::element( 'option', |
| 108 | + array( 'value' => '//' . $languageCode . '.m.wikipedia.org/' ), |
| 109 | + $languageName ); |
| 110 | + } |
| 111 | + $output .= Html::closeElement( 'select', array() ); |
| 112 | + echo $output; |
| 113 | + |
89 | 114 | wfProfileOut( __METHOD__ ); |
90 | 115 | exit(); |
91 | 116 | return true; |
— | — | @@ -92,7 +117,9 @@ |
93 | 118 | |
94 | 119 | private static function addDebugOutput( $object ) { |
95 | 120 | wfProfileIn( __METHOD__ ); |
96 | | - self::$debugOutput[] = $object; |
| 121 | + if ( is_array( self::$debugOutput ) ) { |
| 122 | + self::$debugOutput[] = $object; |
| 123 | + } |
97 | 124 | wfProfileOut( __METHOD__ ); |
98 | 125 | return true; |
99 | 126 | } |
— | — | @@ -390,4 +417,18 @@ |
391 | 418 | wfProfileOut( __METHOD__ ); |
392 | 419 | return ( isset( $countries[strtoupper( $code )] ) ) ? $countries[strtoupper( $code )] : null; |
393 | 420 | } |
| 421 | + |
| 422 | + private static function getSearchFormHtml( $langCode ) { |
| 423 | + $formHtml = <<<HTML |
| 424 | + <form action="//{$langCode}.wikipedia.org/w/index.php" class="search_bar" method="get"> |
| 425 | + <input type="hidden" value="Special:Search" name="title"> |
| 426 | + <div id="sq" class="divclearable"> |
| 427 | + <input type="text" name="search" id="search" size="22" value="" autocorrect="off" autocomplete="off" autocapitalize="off" maxlength="1024"> |
| 428 | + <div class="clearlink" id="clearsearch" title="Clear"></div> |
| 429 | + </div> |
| 430 | + <button id="goButton" type="submit">Search</button> |
| 431 | + </form> |
| 432 | +HTML; |
| 433 | + return $formHtml; |
| 434 | + } |
394 | 435 | } |
\ No newline at end of file |