r108477 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108476‎ | r108477 | r108478 >
Date:23:39, 9 January 2012
Author:preilly
Status:ok
Tags:mobile 
Comment:
add force click to view image option and make sure to only run for mobile view
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
@@ -13,6 +13,8 @@
1414 private static $acceptBilling;
1515 private static $carrier;
1616 private static $renderZeroRatedRedirect;
 17+ private static $forceClickToViewImages;
 18+ public static $useFormat;
1719
1820 /**
1921 * Handler for the BeforePageDisplay hook
@@ -24,6 +26,15 @@
2527 public function beforePageDisplayHTML( &$out, &$text ) {
2628 global $wgRequest;
2729 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+ }
2839
2940 $output = Html::openElement( 'div',
3041 array( 'id' => 'zero-landing-page' ) );
@@ -31,8 +42,14 @@
3243 self::$renderZeroRatedLandingPage = $wgRequest->getFuzzyBool( 'renderZeroRatedLandingPage' );
3344 self::$renderZeroRatedBanner = $wgRequest->getFuzzyBool( 'renderZeroRatedBanner' );
3445 self::$renderZeroRatedRedirect = $wgRequest->getFuzzyBool( 'renderZeroRatedRedirect' );
 46+ self::$forceClickToViewImages = $wgRequest->getFuzzyBool( 'forceClickToViewImages' );
3547 self::$acceptBilling = $wgRequest->getVal( 'acceptbilling' );
3648 self::$title = $out->getTitle();
 49+
 50+ $carrier = $wgRequest->getHeader( 'HTTP_CARRIER' );
 51+ if ( $carrier !== '(null)') {
 52+ self::$renderZeroRatedBanner = true;
 53+ }
3754
3855 if ( self::$title->getNamespace() == NS_FILE ) {
3956 self::$isFilePage = true;
@@ -93,7 +110,6 @@
94111 $out->setPageTitle( null );
95112 } elseif ( self::$renderZeroRatedBanner === true ) {
96113 // a2enmod headers >>> .htaccess >>> RequestHeader set HTTP_CARRIER Verizon
97 - $carrier = $wgRequest->getHeader( 'HTTP_CARRIER' );
98114 self::$carrier = $this->lookupCarrier( $carrier );
99115 $html = $out->getHTML();
100116 $parsedHtml = $this->parseLinksForZeroQueryString( $html );
@@ -234,6 +250,22 @@
235251
236252 $xpath = new DOMXpath( $doc );
237253
 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+
238270 $zeroRatedLinks = $xpath->query( "//a[not(contains(@class,'external'))]" );
239271 foreach ( $zeroRatedLinks as $zeroRatedLink ) {
240272 $zeroRatedLinkHref = $zeroRatedLink->getAttribute( 'href' );
Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.i18n.php
@@ -26,6 +26,7 @@
2727 'zero-rated-mobile-access-banner-text-data-charges' => 'Data charges may apply continue: $1 or $2',
2828 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Yes',
2929 '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"...',
3031 );
3132
3233 /** Message documentation (Message documentation)
@@ -44,6 +45,7 @@
4546 * $2 = {{Msg-mw|zero-rated-mobile-access-banner-text-data-charges-no}}',
4647 'zero-rated-mobile-access-banner-text-data-charges-yes' => 'Text for accepting charges',
4748 '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',
4850 );
4951
5052 /** Japanese (日本語)

Status & tagging log