Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php |
— | — | @@ -13,6 +13,8 @@ |
14 | 14 | private static $acceptBilling; |
15 | 15 | private static $carrier; |
16 | 16 | private static $renderZeroRatedRedirect; |
| 17 | + private static $forceClickToViewImages; |
| 18 | + public static $useFormat; |
17 | 19 | |
18 | 20 | /** |
19 | 21 | * Handler for the BeforePageDisplay hook |
— | — | @@ -24,6 +26,15 @@ |
25 | 27 | public function beforePageDisplayHTML( &$out, &$text ) { |
26 | 28 | global $wgRequest; |
27 | 29 | wfProfileIn( __METHOD__ ); |
| 30 | + |
| 31 | + $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
| 32 | + self::$useFormat = $wgRequest->getText( 'useformat' ); |
| 33 | + |
| 34 | + if ( self::$useFormat !== 'mobile' && self::$useFormat !== 'mobile-wap' && |
| 35 | + !$xDevice ) { |
| 36 | + wfProfileOut( __METHOD__ ); |
| 37 | + return true; |
| 38 | + } |
28 | 39 | |
29 | 40 | $output = Html::openElement( 'div', |
30 | 41 | array( 'id' => 'zero-landing-page' ) ); |
— | — | @@ -31,8 +42,14 @@ |
32 | 43 | self::$renderZeroRatedLandingPage = $wgRequest->getFuzzyBool( 'renderZeroRatedLandingPage' ); |
33 | 44 | self::$renderZeroRatedBanner = $wgRequest->getFuzzyBool( 'renderZeroRatedBanner' ); |
34 | 45 | self::$renderZeroRatedRedirect = $wgRequest->getFuzzyBool( 'renderZeroRatedRedirect' ); |
| 46 | + self::$forceClickToViewImages = $wgRequest->getFuzzyBool( 'forceClickToViewImages' ); |
35 | 47 | self::$acceptBilling = $wgRequest->getVal( 'acceptbilling' ); |
36 | 48 | self::$title = $out->getTitle(); |
| 49 | + |
| 50 | + $carrier = $wgRequest->getHeader( 'HTTP_CARRIER' ); |
| 51 | + if ( $carrier !== '(null)') { |
| 52 | + self::$renderZeroRatedBanner = true; |
| 53 | + } |
37 | 54 | |
38 | 55 | if ( self::$title->getNamespace() == NS_FILE ) { |
39 | 56 | self::$isFilePage = true; |
— | — | @@ -93,7 +110,6 @@ |
94 | 111 | $out->setPageTitle( null ); |
95 | 112 | } elseif ( self::$renderZeroRatedBanner === true ) { |
96 | 113 | // a2enmod headers >>> .htaccess >>> RequestHeader set HTTP_CARRIER Verizon |
97 | | - $carrier = $wgRequest->getHeader( 'HTTP_CARRIER' ); |
98 | 114 | self::$carrier = $this->lookupCarrier( $carrier ); |
99 | 115 | $html = $out->getHTML(); |
100 | 116 | $parsedHtml = $this->parseLinksForZeroQueryString( $html ); |
— | — | @@ -234,6 +250,22 @@ |
235 | 251 | |
236 | 252 | $xpath = new DOMXpath( $doc ); |
237 | 253 | |
| 254 | + if ( !self::$isFilePage && self::$forceClickToViewImages ) { |
| 255 | + $tagToReplace = 'img'; |
| 256 | + $tagToReplaceNodes = $doc->getElementsByTagName( $tagToReplace ); |
| 257 | + foreach ( $tagToReplaceNodes as $tagToReplaceNode ) { |
| 258 | + if ( $tagToReplaceNode ) { |
| 259 | + $alt = $tagToReplaceNode->getAttribute( 'alt' ); |
| 260 | + $spanNodeText = wfMsg( 'zero-rated-mobile-access-click-to-view-image', lcfirst( substr( $alt, 0, 40 ) ) ); |
| 261 | + $spanNode = $doc->createElement( "span", str_replace( "&", "&", $spanNodeText ) ); |
| 262 | + if ( $alt ) { |
| 263 | + $spanNode->setAttribute( 'title', $alt ); |
| 264 | + } |
| 265 | + $tagToReplaceNode->parentNode->replaceChild( $spanNode, $tagToReplaceNode ); |
| 266 | + } |
| 267 | + } |
| 268 | + } |
| 269 | + |
238 | 270 | $zeroRatedLinks = $xpath->query( "//a[not(contains(@class,'external'))]" ); |
239 | 271 | foreach ( $zeroRatedLinks as $zeroRatedLink ) { |
240 | 272 | $zeroRatedLinkHref = $zeroRatedLink->getAttribute( 'href' ); |
Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.i18n.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | 'zero-rated-mobile-access-banner-text-data-charges' => 'Data charges may apply continue: $1 or $2', |
28 | 28 | 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Yes', |
29 | 29 | 'zero-rated-mobile-access-banner-text-data-charges-no' => 'No', |
| 30 | + 'zero-rated-mobile-access-click-to-view-image' => 'Click to view image of, "$1"...', |
30 | 31 | ); |
31 | 32 | |
32 | 33 | /** Message documentation (Message documentation) |
— | — | @@ -44,6 +45,7 @@ |
45 | 46 | * $2 = {{Msg-mw|zero-rated-mobile-access-banner-text-data-charges-no}}', |
46 | 47 | 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Text for accepting charges', |
47 | 48 | 'zero-rated-mobile-access-banner-text-data-charges-no' => 'Text for rejecting charges', |
| 49 | + 'zero-rated-mobile-access-click-to-view-image' => 'Text for viewing an image link', |
48 | 50 | ); |
49 | 51 | |
50 | 52 | /** Japanese (日本語) |