r93405 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93404‎ | r93405 | r93406 >
Date:17:54, 28 July 2011
Author:preilly
Status:ok
Tags:
Comment:
add disable images support and disable caching for trial deployment as well as remove automatic mobile view selection
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -40,18 +40,16 @@
4141 $wgExtensionMessagesFiles['MobileFrontend'] = $cwd . 'MobileFrontend.i18n.php';
4242 //autoload extension classes
4343 $wgAutoloadClasses['DeviceDetection'] = $cwd . 'DeviceDetection.php';
44 -$wgAutoloadClasses['CssDetection'] = $cwd . 'CssDetection.php';
 44+$wgAutoloadClasses['CssDetection'] = $cwd . 'CssDetection.php';
4545
4646 $wgExtMobileFrontend = new ExtMobileFrontend();
4747
48 -$wgHooks['OutputPageBeforeHTML'][] = array( &$wgExtMobileFrontend,
49 - 'onOutputPageBeforeHTML' );
 48+$wgHooks['OutputPageBeforeHTML'][] = array( &$wgExtMobileFrontend, 'onOutputPageBeforeHTML' );
5049
51 -$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend,
52 - 'addMobileFooter' );
 50+$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' );
5351
5452 class ExtMobileFrontend {
55 - const VERSION = '0.5.6';
 53+ const VERSION = '0.5.7';
5654
5755 private $doc;
5856
@@ -70,6 +68,7 @@
7169 public static $search;
7270 public static $callback;
7371 public static $useFormat;
 72+ public static $disableImages;
7473
7574 public $itemsToRemove = array(
7675 '#contentSub', # redirection notice
@@ -125,27 +124,30 @@
126125
127126 // Need to stash the results of the "wfMsg" call before the Output Buffering handler
128127 // because at this point the database connection is shut down, etc.
129 - self::$messages['mobile-frontend-show'] = wfMsg( 'mobile-frontend-show-button' );
130 - self::$messages['mobile-frontend-hide'] = wfMsg( 'mobile-frontend-hide-button' );
131 - self::$messages['mobile-frontend-back-to-top'] = wfMsg( 'mobile-frontend-back-to-top-of-section' );
 128+ self::$messages['mobile-frontend-show'] = wfMsg( 'mobile-frontend-show-button' );
 129+ self::$messages['mobile-frontend-hide'] = wfMsg( 'mobile-frontend-hide-button' );
 130+ self::$messages['mobile-frontend-back-to-top'] = wfMsg( 'mobile-frontend-back-to-top-of-section' );
132131 self::$messages['mobile-frontend-regular-wikipedia'] = wfMsg( 'mobile-frontend-regular-wikipedia' );
133132 self::$messages['mobile-frontend-perm-stop-redirect'] = wfMsg( 'mobile-frontend-perm-stop-redirect' );
134 - self::$messages['mobile-frontend-copyright'] = wfMsg( 'mobile-frontend-copyright' );
135 - self::$messages['mobile-frontend-home-button'] = wfMsg( 'mobile-frontend-home-button' );
136 - self::$messages['mobile-frontend-random-button'] = wfMsg( 'mobile-frontend-random-button' );
137 - self::$messages['mobile-frontend-are-you-sure'] = wfMsg( 'mobile-frontend-are-you-sure' );
138 - self::$messages['mobile-frontend-explain-disable'] = wfMsg( 'mobile-frontend-explain-disable' );
139 - self::$messages['mobile-frontend-disable-button'] = wfMsg( 'mobile-frontend-disable-button' );
140 - self::$messages['mobile-frontend-back-button'] = wfMsg( 'mobile-frontend-back-button' );
 133+ self::$messages['mobile-frontend-copyright'] = wfMsg( 'mobile-frontend-copyright' );
 134+ self::$messages['mobile-frontend-home-button'] = wfMsg( 'mobile-frontend-home-button' );
 135+ self::$messages['mobile-frontend-random-button'] = wfMsg( 'mobile-frontend-random-button' );
 136+ self::$messages['mobile-frontend-are-you-sure'] = wfMsg( 'mobile-frontend-are-you-sure' );
 137+ self::$messages['mobile-frontend-explain-disable'] = wfMsg( 'mobile-frontend-explain-disable' );
 138+ self::$messages['mobile-frontend-disable-button'] = wfMsg( 'mobile-frontend-disable-button' );
 139+ self::$messages['mobile-frontend-back-button'] = wfMsg( 'mobile-frontend-back-button' );
141140
142141 self::$dir = $wgContLang->getDir();
143142 self::$code = $wgContLang->getCode();
144143
 144+ self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
 145+
145146 self::$mainPageUrl = Title::newMainPage()->getFullUrl();
146147 self::$randomPageUrl = SpecialPage::getTitleFor( 'Random' )->getFullUrl();
147 -
 148+
148149 $userAgent = $_SERVER['HTTP_USER_AGENT'];
149150 $uAmd5 = md5($userAgent);
 151+
150152 $key = wfMemcKey( 'mobile', 'ua', $uAmd5 );
151153 try {
152154 $props = $wgMemc->get( $key );
@@ -202,20 +204,37 @@
203205 exit();
204206 }
205207 }
 208+
 209+ // Note: Temporarily disabling this section for trial deployment
 210+ // if ( is_array($props) &&
 211+ // $mAction != 'view_normal_site' &&
 212+ // $props['is_wireless_device'] === 'true' &&
 213+ // $props['is_tablet'] === 'false' ) {
 214+ // $this->disableCaching();
 215+ // ob_start( array( $this, 'DOMParse' ) );
 216+ // } elseif (self::$useFormat === 'mobile' ||
 217+ // self::$useFormat === 'mobile-wap' ) {
 218+ // $this->disableCaching();
 219+ // ob_start( array( $this, 'DOMParse' ) );
 220+ // }
206221
207 - if ( is_array($props) &&
208 - $mAction != 'view_normal_site' &&
209 - $props['is_wireless_device'] === 'true' &&
210 - $props['is_tablet'] === 'false' ) {
211 - ob_start( array( $this, 'DOMParse' ) );
212 - } elseif (self::$useFormat === 'mobile' ||
213 - self::$useFormat === 'mobile-wap') {
214 - ob_start( array( $this, 'DOMParse' ) );
 222+ if (self::$useFormat === 'mobile' ||
 223+ self::$useFormat === 'mobile-wap' ) {
 224+ $this->disableCaching();
 225+ ob_start( array( $this, 'DOMParse' ) );
215226 }
216 -
 227+
217228 return true;
218229 }
219230
 231+ private function disableCaching() {
 232+ if ( isset( $_SERVER['HTTP_VIA'] ) &&
 233+ stripos( $_SERVER['HTTP_VIA'], '.wikimedia.org:' ) !== false ) {
 234+ header( "Cache-Control: no-cache, must-revalidate" ); // HTTP/1.1
 235+ header( "Expires: Sat, 26 Jul 1997 05:00:00 GMT" ); // Date in the past
 236+ }
 237+ }
 238+
220239 private function renderDisableMobileSiteXHTML() {
221240 if ( $this->contentFormat == 'XHTML' ) {
222241 $dir = self::$dir;
@@ -259,7 +278,7 @@
260279 preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches);
261280 }
262281
263 - $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : '';
 282+ $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : '';
264283
265284 static $headings = 0;
266285 $show = self::$messages['mobile-frontend-show'];
@@ -376,6 +395,13 @@
377396 // iterator on the foreach out of wack and results will be quite
378397 // strange. Though, making a queue of items to remove seems to work.
379398 // For example:
 399+
 400+ if ( self::$disableImages == 1 ) {
 401+ $itemToRemoveRecords['TAG'][] = "img";
 402+ $itemToRemoveRecords['CLASS'][] = "thumb tright";
 403+ $itemToRemoveRecords['CLASS'][] = "thumb tleft";
 404+ $itemToRemoveRecords['CLASS'][] = "thumbcaption";
 405+ }
380406
381407 $domElemsToRemove = array();
382408 foreach ( $itemToRemoveRecords['TAG'] as $tagToRemove ) {

Status & tagging log