Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -40,18 +40,16 @@ |
41 | 41 | $wgExtensionMessagesFiles['MobileFrontend'] = $cwd . 'MobileFrontend.i18n.php'; |
42 | 42 | //autoload extension classes |
43 | 43 | $wgAutoloadClasses['DeviceDetection'] = $cwd . 'DeviceDetection.php'; |
44 | | -$wgAutoloadClasses['CssDetection'] = $cwd . 'CssDetection.php'; |
| 44 | +$wgAutoloadClasses['CssDetection'] = $cwd . 'CssDetection.php'; |
45 | 45 | |
46 | 46 | $wgExtMobileFrontend = new ExtMobileFrontend(); |
47 | 47 | |
48 | | -$wgHooks['OutputPageBeforeHTML'][] = array( &$wgExtMobileFrontend, |
49 | | - 'onOutputPageBeforeHTML' ); |
| 48 | +$wgHooks['OutputPageBeforeHTML'][] = array( &$wgExtMobileFrontend, 'onOutputPageBeforeHTML' ); |
50 | 49 | |
51 | | -$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, |
52 | | - 'addMobileFooter' ); |
| 50 | +$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' ); |
53 | 51 | |
54 | 52 | class ExtMobileFrontend { |
55 | | - const VERSION = '0.5.6'; |
| 53 | + const VERSION = '0.5.7'; |
56 | 54 | |
57 | 55 | private $doc; |
58 | 56 | |
— | — | @@ -70,6 +68,7 @@ |
71 | 69 | public static $search; |
72 | 70 | public static $callback; |
73 | 71 | public static $useFormat; |
| 72 | + public static $disableImages; |
74 | 73 | |
75 | 74 | public $itemsToRemove = array( |
76 | 75 | '#contentSub', # redirection notice |
— | — | @@ -125,27 +124,30 @@ |
126 | 125 | |
127 | 126 | // Need to stash the results of the "wfMsg" call before the Output Buffering handler |
128 | 127 | // 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' ); |
132 | 131 | self::$messages['mobile-frontend-regular-wikipedia'] = wfMsg( 'mobile-frontend-regular-wikipedia' ); |
133 | 132 | 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' ); |
141 | 140 | |
142 | 141 | self::$dir = $wgContLang->getDir(); |
143 | 142 | self::$code = $wgContLang->getCode(); |
144 | 143 | |
| 144 | + self::$disableImages = $wgRequest->getText( 'disableImages', 0 ); |
| 145 | + |
145 | 146 | self::$mainPageUrl = Title::newMainPage()->getFullUrl(); |
146 | 147 | self::$randomPageUrl = SpecialPage::getTitleFor( 'Random' )->getFullUrl(); |
147 | | - |
| 148 | + |
148 | 149 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
149 | 150 | $uAmd5 = md5($userAgent); |
| 151 | + |
150 | 152 | $key = wfMemcKey( 'mobile', 'ua', $uAmd5 ); |
151 | 153 | try { |
152 | 154 | $props = $wgMemc->get( $key ); |
— | — | @@ -202,20 +204,37 @@ |
203 | 205 | exit(); |
204 | 206 | } |
205 | 207 | } |
| 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 | + // } |
206 | 221 | |
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' ) ); |
215 | 226 | } |
216 | | - |
| 227 | + |
217 | 228 | return true; |
218 | 229 | } |
219 | 230 | |
| 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 | + |
220 | 239 | private function renderDisableMobileSiteXHTML() { |
221 | 240 | if ( $this->contentFormat == 'XHTML' ) { |
222 | 241 | $dir = self::$dir; |
— | — | @@ -259,7 +278,7 @@ |
260 | 279 | preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches); |
261 | 280 | } |
262 | 281 | |
263 | | - $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : ''; |
| 282 | + $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : ''; |
264 | 283 | |
265 | 284 | static $headings = 0; |
266 | 285 | $show = self::$messages['mobile-frontend-show']; |
— | — | @@ -376,6 +395,13 @@ |
377 | 396 | // iterator on the foreach out of wack and results will be quite |
378 | 397 | // strange. Though, making a queue of items to remove seems to work. |
379 | 398 | // 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 | + } |
380 | 406 | |
381 | 407 | $domElemsToRemove = array(); |
382 | 408 | foreach ( $itemToRemoveRecords['TAG'] as $tagToRemove ) { |