Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/skins/SkinMobile.php |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | public $extMobileFrontend; |
9 | 9 | |
10 | 10 | public function __construct( ExtMobileFrontend &$extMobileFrontend ) { |
| 11 | + $this->setContext( $extMobileFrontend ); |
11 | 12 | $this->extMobileFrontend = $extMobileFrontend; |
12 | 13 | } |
13 | 14 | |
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -1,14 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class ExtMobileFrontend { |
| 4 | +class ExtMobileFrontend extends ContextSource { |
5 | 5 | |
6 | 6 | public $contentFormat = ''; |
7 | 7 | |
8 | | - /** |
9 | | - * @var Title |
10 | | - */ |
11 | | - public static $title; |
12 | | - public static $htmlTitle; |
13 | 8 | public static $randomPageUrl; |
14 | 9 | public static $format; |
15 | 10 | public static $search; |
— | — | @@ -53,12 +48,24 @@ |
54 | 49 | private $contentTransformations = true; |
55 | 50 | private $device; |
56 | 51 | |
57 | | - public function __construct() { |
| 52 | + public function __construct( IContextSource $context ) { |
58 | 53 | global $wgMFConfigProperties; |
| 54 | + $this->setContext( $context ); |
59 | 55 | $this->wmlContext = new WmlContext(); |
60 | 56 | $this->setPropertiesFromArray( $wgMFConfigProperties ); |
61 | 57 | } |
62 | 58 | |
| 59 | + public function attachHooks() { |
| 60 | + global $wgHooks; |
| 61 | + $wgHooks['RequestContextCreateSkin'][] = array( &$this, 'requestContextCreateSkin' ); |
| 62 | + $wgHooks['BeforePageRedirect'][] = array( &$this, 'beforePageRedirect' ); |
| 63 | + $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$this, 'addMobileFooter' ); |
| 64 | + $wgHooks['TestCanonicalRedirect'][] = array( &$this, 'testCanonicalRedirect' ); |
| 65 | + $wgHooks['ResourceLoaderTestModules'][] = array( &$this, 'addTestModules' ); |
| 66 | + $wgHooks['GetCacheVaryCookies'][] = array( &$this, 'getCacheVaryCookies' ); |
| 67 | + $wgHooks['ResourceLoaderRegisterModules'][] = array( &$this, 'resourceLoaderRegisterModules' ); |
| 68 | + } |
| 69 | + |
63 | 70 | public function requestContextCreateSkin( $context, &$skin ) { |
64 | 71 | // check whether or not the user has requested to toggle their view |
65 | 72 | $mobileAction = $this->getMobileAction(); |
— | — | @@ -193,7 +200,7 @@ |
194 | 201 | * @return bool |
195 | 202 | */ |
196 | 203 | public function addMobileFooter( &$obj, &$tpl ) { |
197 | | - global $wgRequest, $wgServer; |
| 204 | + global $wgServer; |
198 | 205 | wfProfileIn( __METHOD__ ); |
199 | 206 | |
200 | 207 | $title = $obj->getTitle(); |
— | — | @@ -201,7 +208,7 @@ |
202 | 209 | |
203 | 210 | if ( ! $isSpecial ) { |
204 | 211 | $footerlinks = $tpl->data['footerlinks']; |
205 | | - $mobileViewUrl = $wgRequest->escapeAppendQuery( 'mobileaction=toggle_view_mobile' ); |
| 212 | + $mobileViewUrl = $this->getRequest()->escapeAppendQuery( 'mobileaction=toggle_view_mobile' ); |
206 | 213 | |
207 | 214 | $mobileViewUrl = $this->getMobileUrl( $wgServer . $mobileViewUrl ); |
208 | 215 | $tpl->set( 'mobileview', "<a href='{$mobileViewUrl}' class='noprint'>" . wfMsg( 'mobile-frontend-view' ) . "</a>" ); |
— | — | @@ -226,10 +233,12 @@ |
227 | 234 | } |
228 | 235 | |
229 | 236 | public function getMsg() { |
230 | | - global $wgRequest, $wgServer, $wgMobileRedirectFormAction; |
| 237 | + global $wgServer, $wgMobileRedirectFormAction; |
231 | 238 | wfProfileIn( __METHOD__ ); |
232 | 239 | |
233 | | - self::$viewNormalSiteURL = $this->getDesktopUrl( wfExpandUrl( $wgRequest->escapeAppendQuery( 'mobileaction=toggle_view_desktop' ) ) ); |
| 240 | + self::$viewNormalSiteURL = $this->getDesktopUrl( wfExpandUrl( |
| 241 | + $this->getRequest()->escapeAppendQuery( 'mobileaction=toggle_view_desktop' ) ) |
| 242 | + ); |
234 | 243 | |
235 | 244 | self::$mobileRedirectFormAction = ( $wgMobileRedirectFormAction !== false ) |
236 | 245 | ? $wgMobileRedirectFormAction |
— | — | @@ -272,19 +281,15 @@ |
273 | 282 | |
274 | 283 | /** |
275 | 284 | * @param $out OutputPage |
276 | | - * @param $text String |
277 | 285 | * @return bool |
278 | 286 | */ |
279 | | - public function beforePageDisplayHTML( &$out ) { |
280 | | - global $wgRequest; |
| 287 | + public function beforePageDisplayHTML( $out ) { |
281 | 288 | wfProfileIn( __METHOD__ ); |
282 | 289 | |
283 | | - // Note: The WebRequest Class calls are made in this block because |
284 | | - // since PHP 5.1.x, all objects have their destructors called |
285 | | - // before the output buffer callback function executes. |
286 | | - // Thus, globalized objects will not be available as expected in the function. |
287 | | - // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104] |
| 290 | + if ( wfRunHooks( 'BeforePageDisplayMobile', array( &$out ) ) ) { |
| 291 | + } |
288 | 292 | |
| 293 | + $request = $this->getRequest(); |
289 | 294 | $xDevice = $this->getXDevice(); |
290 | 295 | $this->setWmlContextFormat(); |
291 | 296 | $mobileAction = $this->getMobileAction(); |
— | — | @@ -295,7 +300,7 @@ |
296 | 301 | ); |
297 | 302 | if ( isset( $bcRedirects[$mobileAction] ) ) { |
298 | 303 | $location = SpecialMobileOptions::getUrl( $bcRedirects[$mobileAction], null, true ); |
299 | | - $wgRequest->response()->header( 'Location: ' . wfExpandUrl( $location ) ); |
| 304 | + $request->response()->header( 'Location: ' . wfExpandUrl( $location ) ); |
300 | 305 | exit; |
301 | 306 | } |
302 | 307 | |
— | — | @@ -305,16 +310,14 @@ |
306 | 311 | |
307 | 312 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
308 | 313 | $acceptHeader = isset( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : ''; |
309 | | - self::$title = $out->getTitle(); |
310 | 314 | |
311 | | - self::$htmlTitle = $out->getHTMLTitle(); |
312 | | - $this->disableImages = $wgRequest->getCookie( 'disableImages' ); |
313 | | - self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' ); |
| 315 | + $this->disableImages = $request->getCookie( 'disableImages' ); |
| 316 | + self::$displayNoticeId = $request->getText( 'noticeid', '' ); |
314 | 317 | |
315 | | - self::$format = $wgRequest->getText( 'format' ); |
316 | | - $this->wmlContext->setRequestedSegment( $wgRequest->getInt( 'seg', 0 ) ); |
317 | | - self::$search = $wgRequest->getText( 'search' ); |
318 | | - self::$searchField = $wgRequest->getText( 'search', '' ); |
| 318 | + self::$format = $request->getText( 'format' ); |
| 319 | + $this->wmlContext->setRequestedSegment( $request->getInt( 'seg', 0 ) ); |
| 320 | + self::$search = $request->getText( 'search' ); |
| 321 | + self::$searchField = $request->getText( 'search', '' ); |
319 | 322 | |
320 | 323 | $detector = new DeviceDetection(); |
321 | 324 | |
— | — | @@ -338,16 +341,16 @@ |
339 | 342 | $this->sendApplicationVersionVaryHeader(); |
340 | 343 | $this->checkUserLoggedIn(); |
341 | 344 | |
342 | | - if ( self::$title->isSpecial( 'Userlogin' ) ) { |
343 | | - self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' ); |
| 345 | + if ( $this->getTitle()->isSpecial( 'Userlogin' ) ) { |
| 346 | + self::$wsLoginToken = $request->getSessionData( 'wsLoginToken' ); |
344 | 347 | $q = array( 'action' => 'submitlogin', 'type' => 'login' ); |
345 | | - $returnToVal = $wgRequest->getVal( 'returnto' ); |
| 348 | + $returnToVal = $request->getVal( 'returnto' ); |
346 | 349 | |
347 | 350 | if ( $returnToVal ) { |
348 | 351 | $q['returnto'] = $returnToVal; |
349 | 352 | } |
350 | 353 | |
351 | | - self::$wsLoginFormAction = self::$title->getLocalURL( $q ); |
| 354 | + self::$wsLoginFormAction = $this->getTitle()->getLocalURL( $q ); |
352 | 355 | } |
353 | 356 | |
354 | 357 | wfProfileOut( __METHOD__ ); |
— | — | @@ -377,19 +380,20 @@ |
378 | 381 | * @return bool |
379 | 382 | */ |
380 | 383 | private function checkUserLoggedIn() { |
381 | | - global $wgUser, $wgCookieDomain, $wgRequest, $wgCookiePrefix; |
| 384 | + global $wgCookieDomain, $wgCookiePrefix; |
382 | 385 | wfProfileIn( __METHOD__ ); |
383 | 386 | $tempWgCookieDomain = $wgCookieDomain; |
384 | 387 | $wgCookieDomain = $this->getBaseDomain(); |
385 | 388 | $tempWgCookiePrefix = $wgCookiePrefix; |
386 | 389 | $wgCookiePrefix = ''; |
387 | 390 | |
388 | | - if ( $wgUser->isLoggedIn() ) { |
389 | | - $wgRequest->response()->setcookie( 'mfsecure', '1', 0, '' ); |
| 391 | + $request = $this->getRequest(); |
| 392 | + if ( $this->getUser()->isLoggedIn() ) { |
| 393 | + $request->response()->setcookie( 'mfsecure', '1', 0, '' ); |
390 | 394 | } else { |
391 | | - $mfSecure = $wgRequest->getCookie( 'mfsecure', '' ); |
| 395 | + $mfSecure = $request->getCookie( 'mfsecure', '' ); |
392 | 396 | if ( $mfSecure && $mfSecure == '1' ) { |
393 | | - $wgRequest->response()->setcookie( 'mfsecure', '', 0, '' ); |
| 397 | + $request->response()->setcookie( 'mfsecure', '', 0, '' ); |
394 | 398 | } |
395 | 399 | } |
396 | 400 | |
— | — | @@ -400,16 +404,15 @@ |
401 | 405 | } |
402 | 406 | |
403 | 407 | private function checkUserStatus() { |
404 | | - global $wgRequest; |
405 | 408 | wfProfileIn( __METHOD__ ); |
406 | 409 | |
407 | | - $hideSearchBox = $wgRequest->getInt( 'hidesearchbox' ); |
| 410 | + $hideSearchBox = $this->getRequest()->getInt( 'hidesearchbox' ); |
408 | 411 | |
409 | 412 | if ( $hideSearchBox === 1 ) { |
410 | 413 | self::$hideSearchBox = true; |
411 | 414 | } |
412 | 415 | |
413 | | - $hideLogo = $wgRequest->getInt( 'hidelogo' ); |
| 416 | + $hideLogo = $this->getRequest()->getInt( 'hidelogo' ); |
414 | 417 | |
415 | 418 | if ( $hideLogo === 1 ) { |
416 | 419 | self::$hideLogo = true; |
— | — | @@ -441,7 +444,7 @@ |
442 | 445 | * @return bool |
443 | 446 | */ |
444 | 447 | public function setOptInOutCookie( $value ) { |
445 | | - global $wgCookieDomain, $wgRequest, $wgCookiePrefix; |
| 448 | + global $wgCookieDomain, $wgCookiePrefix; |
446 | 449 | wfProfileIn( __METHOD__ ); |
447 | 450 | if ( $value ) { |
448 | 451 | wfIncrStats( 'mobile.opt_in_cookie_set' ); |
— | — | @@ -450,7 +453,7 @@ |
451 | 454 | $wgCookieDomain = $this->getBaseDomain(); |
452 | 455 | $tempWgCookiePrefix = $wgCookiePrefix; |
453 | 456 | $wgCookiePrefix = ''; |
454 | | - $wgRequest->response()->setcookie( 'optin', $value, 0, '' ); |
| 457 | + $this->getRequest()->response()->setcookie( 'optin', $value, 0, '' ); |
455 | 458 | $wgCookieDomain = $tempWgCookieDomain; |
456 | 459 | $wgCookiePrefix = $tempWgCookiePrefix; |
457 | 460 | wfProfileOut( __METHOD__ ); |
— | — | @@ -458,20 +461,21 @@ |
459 | 462 | } |
460 | 463 | |
461 | 464 | private function getLanguageUrls() { |
462 | | - global $wgRequest, $wgContLang, $wgLanguageCode, $wgOut; |
| 465 | + global $wgContLang, $wgLanguageCode; |
463 | 466 | |
464 | 467 | wfProfileIn( __METHOD__ ); |
465 | 468 | $languageUrls = array(); |
466 | 469 | |
| 470 | + $out = $this->getOutput(); |
467 | 471 | $languageUrls[] = array( |
468 | | - 'href' => $wgRequest->getFullRequestURL(), |
469 | | - 'text' => self::$htmlTitle, |
| 472 | + 'href' => $this->getRequest()->getFullRequestURL(), |
| 473 | + 'text' => $out->getHTMLTitle(), |
470 | 474 | 'language' => $wgContLang->getLanguageName( $wgLanguageCode ), |
471 | 475 | 'class' => 'interwiki-' . $wgLanguageCode, |
472 | 476 | 'lang' => $wgLanguageCode, |
473 | 477 | ); |
474 | 478 | |
475 | | - foreach ( $wgOut->getLanguageLinks() as $l ) { |
| 479 | + foreach ( $out->getLanguageLinks() as $l ) { |
476 | 480 | $tmp = explode( ':', $l, 2 ); |
477 | 481 | $class = 'interwiki-' . $tmp[0]; |
478 | 482 | $lang = $tmp[0]; |
— | — | @@ -499,9 +503,8 @@ |
500 | 504 | * @return Mixed |
501 | 505 | */ |
502 | 506 | private function getOptInOutCookie() { |
503 | | - global $wgRequest; |
504 | 507 | wfProfileIn( __METHOD__ ); |
505 | | - $optInCookie = $wgRequest->getCookie( 'optin', '' ); |
| 508 | + $optInCookie = $this->getRequest()->getCookie( 'optin', '' ); |
506 | 509 | wfProfileOut( __METHOD__ ); |
507 | 510 | return $optInCookie; |
508 | 511 | } |
— | — | @@ -528,7 +531,6 @@ |
529 | 532 | * @return bool |
530 | 533 | */ |
531 | 534 | private function disableCaching() { |
532 | | - global $wgRequest; |
533 | 535 | wfProfileIn( __METHOD__ ); |
534 | 536 | |
535 | 537 | // Fetch the REMOTE_ADDR and check if it's a trusted proxy. |
— | — | @@ -550,10 +552,11 @@ |
551 | 553 | * care about. |
552 | 554 | */ |
553 | 555 | $trustedProxyCheckFunction = ( function_exists( 'wfIsConfiguredProxy' ) ) ? 'wfIsConfiguredProxy' : 'wfIsTrustedProxy'; |
| 556 | + $request = $this->getRequest(); |
554 | 557 | if ( $trustedProxyCheckFunction( $ip ) ) { |
555 | | - $wgRequest->response()->header( 'Cache-Control: no-cache, must-revalidate' ); |
556 | | - $wgRequest->response()->header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); |
557 | | - $wgRequest->response()->header( 'Pragma: no-cache' ); |
| 558 | + $request->response()->header( 'Cache-Control: no-cache, must-revalidate' ); |
| 559 | + $request->response()->header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); |
| 560 | + $request->response()->header( 'Pragma: no-cache' ); |
558 | 561 | } |
559 | 562 | |
560 | 563 | wfProfileOut( __METHOD__ ); |
— | — | @@ -561,30 +564,29 @@ |
562 | 565 | } |
563 | 566 | |
564 | 567 | private function sendXDeviceVaryHeader() { |
565 | | - global $wgOut, $wgRequest; |
566 | 568 | wfProfileIn( __METHOD__ ); |
| 569 | + $out = $this->getOutput(); |
567 | 570 | if ( isset( $_SERVER['HTTP_X_DEVICE'] ) ) { |
568 | | - $wgRequest->response()->header( 'X-Device: ' . $_SERVER['HTTP_X_DEVICE'] ); |
569 | | - $wgOut->addVaryHeader( 'X-Device' ); |
| 571 | + $this->getRequest()->response()->header( 'X-Device: ' . $_SERVER['HTTP_X_DEVICE'] ); |
| 572 | + $out->addVaryHeader( 'X-Device' ); |
570 | 573 | } |
571 | | - $wgOut->addVaryHeader( 'Cookie' ); |
572 | | - $wgOut->addVaryHeader( 'X-Carrier' ); |
573 | | - $wgOut->addVaryHeader( 'X-Images' ); |
| 574 | + $out->addVaryHeader( 'Cookie' ); |
| 575 | + $out->addVaryHeader( 'X-Carrier' ); |
| 576 | + $out->addVaryHeader( 'X-Images' ); |
574 | 577 | wfProfileOut( __METHOD__ ); |
575 | 578 | return true; |
576 | 579 | } |
577 | 580 | |
578 | 581 | private function sendApplicationVersionVaryHeader() { |
579 | | - global $wgOut, $wgRequest; |
580 | 582 | wfProfileIn( __METHOD__ ); |
581 | | - $wgOut->addVaryHeader( 'Application_Version' ); |
| 583 | + $this->getOutput()->addVaryHeader( 'Application_Version' ); |
582 | 584 | if ( isset( $_SERVER['HTTP_APPLICATION_VERSION'] ) ) { |
583 | | - $wgRequest->response()->header( 'Application_Version: ' . $_SERVER['HTTP_APPLICATION_VERSION'] ); |
| 585 | + $this->getRequest()->response()->header( 'Application_Version: ' . $_SERVER['HTTP_APPLICATION_VERSION'] ); |
584 | 586 | } else { |
585 | 587 | if ( isset( $_SERVER['HTTP_X_DEVICE'] ) ) { |
586 | 588 | if ( stripos( $_SERVER['HTTP_X_DEVICE'], 'iphone' ) !== false || |
587 | 589 | stripos( $_SERVER['HTTP_X_DEVICE'], 'android' ) !== false ) { |
588 | | - $wgRequest->response()->header( 'Application_Version: ' . $_SERVER['HTTP_X_DEVICE'] ); |
| 590 | + $this->getRequest()->response()->header( 'Application_Version: ' . $_SERVER['HTTP_X_DEVICE'] ); |
589 | 591 | } |
590 | 592 | } |
591 | 593 | } |
— | — | @@ -703,19 +705,17 @@ |
704 | 706 | } |
705 | 707 | |
706 | 708 | private function getLoginLinks() { |
707 | | - global $wgRequest, $wgUser; |
708 | | - |
709 | 709 | wfProfileIn( __METHOD__ ); |
710 | 710 | $login = $logout = ''; |
711 | | - $query = array( 'returnto' => self::$title->getPrefixedText() ); |
712 | | - if ( !$wgRequest->wasPosted() ) { |
713 | | - $returntoquery = $wgRequest->getValues(); |
| 711 | + $query = array( 'returnto' => $this->getTitle()->getPrefixedText() ); |
| 712 | + if ( !$this->getRequest()->wasPosted() ) { |
| 713 | + $returntoquery = $this->getRequest()->getValues(); |
714 | 714 | unset( $returntoquery['title'] ); |
715 | 715 | unset( $returntoquery['returnto'] ); |
716 | 716 | unset( $returntoquery['returntoquery'] ); |
717 | 717 | $query['returntoquery'] = wfArrayToCGI( $returntoquery ); |
718 | 718 | } |
719 | | - if ( $wgUser->isLoggedIn() ) { |
| 719 | + if ( $this->getUser()->isLoggedIn() ) { |
720 | 720 | $login = Linker::link( SpecialPage::getTitleFor( 'UserLogin' ), |
721 | 721 | wfMessage( 'mobile-frontend-login' )->escaped(), |
722 | 722 | array(), |
— | — | @@ -737,13 +737,13 @@ |
738 | 738 | * @return string |
739 | 739 | */ |
740 | 740 | public function DOMParse( OutputPage $out ) { |
741 | | - global $wgScript, $wgContLang, $wgRequest; |
| 741 | + global $wgScript, $wgContLang; |
742 | 742 | wfProfileIn( __METHOD__ ); |
743 | 743 | |
744 | 744 | $html = $out->getHTML(); |
745 | 745 | |
746 | 746 | wfProfileIn( __METHOD__ . '-formatter-init' ); |
747 | | - $formatter = new MobileFormatter( MobileFormatter::wrapHTML( $html ), self::$title, $this->contentFormat, $this->wmlContext ); |
| 747 | + $formatter = new MobileFormatter( MobileFormatter::wrapHTML( $html ), $this->getTitle(), $this->contentFormat, $this->wmlContext ); |
748 | 748 | $doc = $formatter->getDoc(); |
749 | 749 | wfProfileOut( __METHOD__ . '-formatter-init' ); |
750 | 750 | |
— | — | @@ -760,7 +760,7 @@ |
761 | 761 | wfProfileOut( __METHOD__ . '-zero' ); |
762 | 762 | |
763 | 763 | wfProfileIn( __METHOD__ . '-beta' ); |
764 | | - if ( self::$title->isSpecial( 'Userlogin' ) ) { |
| 764 | + if ( $this->getTitle()->isSpecial( 'Userlogin' ) ) { |
765 | 765 | $userlogin = $doc->getElementById( 'userloginForm' ); |
766 | 766 | |
767 | 767 | if ( $userlogin && get_class( $userlogin ) === 'DOMElement' ) { |
— | — | @@ -781,7 +781,7 @@ |
782 | 782 | } |
783 | 783 | |
784 | 784 | wfProfileIn( __METHOD__ . '-userlogin' ); |
785 | | - if ( self::$title->isSpecial( 'Userlogin' ) ) { |
| 785 | + if ( $this->getTitle()->isSpecial( 'Userlogin' ) ) { |
786 | 786 | if ( $userlogin && get_class( $userlogin ) === 'DOMElement' ) { |
787 | 787 | $login = $this->renderLogin(); |
788 | 788 | $loginNode = $doc->importNode( $login, true ); |
— | — | @@ -791,7 +791,7 @@ |
792 | 792 | wfProfileOut( __METHOD__ . '-userlogin' ); |
793 | 793 | |
794 | 794 | wfProfileIn( __METHOD__ . '-getText' ); |
795 | | - $formatter->setIsMainPage( self::$title->isMainPage() ); |
| 795 | + $formatter->setIsMainPage( $this->getTitle()->isMainPage() ); |
796 | 796 | if ( $this->contentFormat == 'XHTML' |
797 | 797 | && $this->device['supports_javascript'] === true |
798 | 798 | && empty( self::$search ) ) |
— | — | @@ -802,7 +802,6 @@ |
803 | 803 | wfProfileOut( __METHOD__ . '-getText' ); |
804 | 804 | |
805 | 805 | wfProfileIn( __METHOD__ . '-templates' ); |
806 | | - $htmlTitle = htmlspecialchars( self::$htmlTitle ); |
807 | 806 | if ( $this->contentFormat == 'WML' ) { |
808 | 807 | header( 'Content-Type: text/vnd.wap.wml' ); |
809 | 808 | |
— | — | @@ -843,7 +842,7 @@ |
844 | 843 | $applicationTemplate = $this->getApplicationTemplate(); |
845 | 844 | $options = array( |
846 | 845 | 'noticeHtml' => $noticeHtml, |
847 | | - 'htmlTitle' => $htmlTitle, |
| 846 | + 'htmlTitle' => $out->getHTMLTitle(), |
848 | 847 | 'searchWebkitHtml' => $searchWebkitHtml, |
849 | 848 | 'contentHtml' => $contentHtml, |
850 | 849 | 'footerHtml' => $footerHtml, |
— | — | @@ -859,12 +858,12 @@ |
860 | 859 | header( 'Content-Type: application/javascript' ); |
861 | 860 | header( 'Content-Disposition: attachment; filename="data.js";' ); |
862 | 861 | $json_data = array(); |
863 | | - $json_data['title'] = htmlspecialchars ( self::$title->getText() ); |
| 862 | + $json_data['title'] = htmlspecialchars ( $this->getTitle()->getText() ); |
864 | 863 | $json_data['html'] = $contentHtml; |
865 | 864 | |
866 | 865 | $json = FormatJson::encode( $json_data ); |
867 | 866 | |
868 | | - $callback = $wgRequest->getText( 'callback' ); |
| 867 | + $callback = $this->getRequest()->getText( 'callback' ); |
869 | 868 | if ( !empty( $callback ) ) { |
870 | 869 | $json = urlencode( htmlspecialchars( $callback ) ) . '(' . $json . ')'; |
871 | 870 | } |
— | — | @@ -889,11 +888,11 @@ |
890 | 889 | $footerTemplate = new FooterTemplate(); |
891 | 890 | $options = array( |
892 | 891 | 'leaveFeedbackURL' => SpecialPage::getTitleFor( 'MobileFeedback' ) |
893 | | - ->getLocalURL( array( 'returnto' => self::$title->getPrefixedText() ) ), |
| 892 | + ->getLocalURL( array( 'returnto' => $this->getTitle()->getPrefixedText() ) ), |
894 | 893 | 'viewNormalSiteURL' => self::$viewNormalSiteURL, |
895 | 894 | 'disableImages' => $this->disableImages, |
896 | | - 'disableImagesURL' => SpecialMobileOptions::getURL( 'DisableImages', self::$title ), |
897 | | - 'enableImagesURL' => SpecialMobileOptions::getURL( 'EnableImages', self::$title ), |
| 895 | + 'disableImagesURL' => SpecialMobileOptions::getURL( 'DisableImages', $this->getTitle() ), |
| 896 | + 'enableImagesURL' => SpecialMobileOptions::getURL( 'EnableImages', $this->getTitle() ), |
898 | 897 | 'logoutHtml' => $logoutHtml, |
899 | 898 | 'loginHtml' => $loginHtml, |
900 | 899 | 'code' => $wgContLang->getCode(), |
— | — | @@ -931,25 +930,26 @@ |
932 | 931 | } |
933 | 932 | |
934 | 933 | public function getApplicationTemplate() { |
935 | | - global $wgAppleTouchIcon, $wgExtensionAssetsPath, $wgScriptPath, $wgCookiePath, $wgOut, $wgContLang; |
| 934 | + global $wgAppleTouchIcon, $wgExtensionAssetsPath, $wgScriptPath, $wgCookiePath, $wgContLang; |
936 | 935 | wfProfileIn( __METHOD__ ); |
| 936 | + $out = $this->getOutput(); |
937 | 937 | if ( self::$isBetaGroupMember ) { |
938 | | - $wgOut->addModuleStyles( 'ext.mobileFrontendBeta' ); |
| 938 | + $out->addModuleStyles( 'ext.mobileFrontendBeta' ); |
939 | 939 | } else { |
940 | | - $wgOut->addModuleStyles( 'ext.mobileFrontend' ); |
| 940 | + $out->addModuleStyles( 'ext.mobileFrontend' ); |
941 | 941 | } |
942 | | - $wgOut->addModuleStyles( "ext.mobileFrontend.{$this->device['css_file_name']}" ); |
943 | | - $isFilePage = self::$title->getNamespace() == NS_FILE; |
| 942 | + $out->addModuleStyles( "ext.mobileFrontend.{$this->device['css_file_name']}" ); |
| 943 | + $isFilePage = $this->getTitle()->getNamespace() == NS_FILE; |
944 | 944 | if ( $isFilePage ) { |
945 | | - $wgOut->addModuleStyles( 'ext.mobileFrontend.filePage' ); |
| 945 | + $out->addModuleStyles( 'ext.mobileFrontend.filePage' ); |
946 | 946 | } |
947 | | - $cssLinks = $wgOut->buildCssLinks(); |
| 947 | + $cssLinks = $out->buildCssLinks(); |
948 | 948 | $applicationTemplate = new ApplicationTemplate(); |
949 | 949 | $options = array( |
950 | 950 | 'dir' => $wgContLang->getDir(), |
951 | 951 | 'code' => $wgContLang->getCode(), |
952 | | - 'title' => self::$title, |
953 | | - 'pageTitle' => $wgOut->getPageTitle(), |
| 952 | + 'title' => $this->getTitle(), |
| 953 | + 'pageTitle' => $out->getPageTitle(), |
954 | 954 | 'placeholder' => wfMsg( 'mobile-frontend-placeholder' ), |
955 | 955 | 'dismissNotification' => wfMsg( 'mobile-frontend-dismiss-notification' ), |
956 | 956 | 'wgAppleTouchIcon' => $wgAppleTouchIcon, |
— | — | @@ -1310,27 +1310,24 @@ |
1311 | 1311 | } |
1312 | 1312 | |
1313 | 1313 | public function getMobileAction() { |
1314 | | - global $wgRequest; |
1315 | 1314 | if ( is_null( $this->mobileAction ) ) { |
1316 | | - $this->mobileAction = $wgRequest->getText( 'mobileaction' ); |
| 1315 | + $this->mobileAction = $this->getRequest()->getText( 'mobileaction' ); |
1317 | 1316 | } |
1318 | 1317 | |
1319 | 1318 | return $this->mobileAction; |
1320 | 1319 | } |
1321 | 1320 | |
1322 | 1321 | public function getAction() { |
1323 | | - global $wgRequest; |
1324 | 1322 | if ( is_null( $this->action ) ) { |
1325 | | - $this->action = $wgRequest->getText( 'action' ); |
| 1323 | + $this->action = $this->getRequest()->getText( 'action' ); |
1326 | 1324 | } |
1327 | 1325 | |
1328 | 1326 | return $this->action; |
1329 | 1327 | } |
1330 | 1328 | |
1331 | 1329 | public function getUseFormat() { |
1332 | | - global $wgRequest; |
1333 | 1330 | if ( !isset( $this->useFormat ) ) { |
1334 | | - $useFormat = $wgRequest->getText( 'useformat' ); |
| 1331 | + $useFormat = $this->getRequest()->getText( 'useformat' ); |
1335 | 1332 | $this->setUseFormat( $useFormat ); |
1336 | 1333 | } |
1337 | 1334 | return $this->useFormat; |
— | — | @@ -1358,10 +1355,8 @@ |
1359 | 1356 | } |
1360 | 1357 | |
1361 | 1358 | public function getStopMobileRedirectCookie() { |
1362 | | - global $wgRequest; |
| 1359 | + $stopMobileRedirectCookie = $this->getRequest()->getCookie( 'stopMobileRedirect', '' ); |
1363 | 1360 | |
1364 | | - $stopMobileRedirectCookie = $wgRequest->getCookie( 'stopMobileRedirect', '' ); |
1365 | | - |
1366 | 1361 | return $stopMobileRedirectCookie; |
1367 | 1362 | } |
1368 | 1363 | |
— | — | @@ -1374,10 +1369,8 @@ |
1375 | 1370 | * @return string|null |
1376 | 1371 | */ |
1377 | 1372 | public function getUseFormatCookie() { |
1378 | | - global $wgRequest; |
| 1373 | + $useFormatFromCookie = $this->getRequest()->getCookie( $this->getUseFormatCookieName(), '' ); |
1379 | 1374 | |
1380 | | - $useFormatFromCookie = $wgRequest->getCookie( $this->getUseFormatCookieName(), '' ); |
1381 | | - |
1382 | 1375 | return $useFormatFromCookie; |
1383 | 1376 | } |
1384 | 1377 | |
— | — | @@ -1441,9 +1434,9 @@ |
1442 | 1435 | * @return bool |
1443 | 1436 | */ |
1444 | 1437 | protected function shouldSetUseFormatCookie() { |
1445 | | - global $wgRequest, $wgScriptPath; |
| 1438 | + global $wgScriptPath; |
1446 | 1439 | |
1447 | | - $reqUrl = $wgRequest->getRequestUrl(); |
| 1440 | + $reqUrl = $this->getRequest()->getRequestUrl(); |
1448 | 1441 | $urlsToIgnore = array( '/?useformat=mobile', $wgScriptPath . '/?useformat=mobile' ); |
1449 | 1442 | if ( in_array( $reqUrl, $urlsToIgnore ) ) { |
1450 | 1443 | return false; |
— | — | @@ -1501,7 +1494,7 @@ |
1502 | 1495 | * and set a cookie to keep them on that view for subsequent requests. |
1503 | 1496 | */ |
1504 | 1497 | public function toggleView( $view, $temporary = false ) { |
1505 | | - global $wgMobileUrlTemplate, $wgOut, $wgRequest; |
| 1498 | + global $wgMobileUrlTemplate; |
1506 | 1499 | |
1507 | 1500 | if ( $view == 'mobile' ) { |
1508 | 1501 | // unset stopMobileRedirect cookie |
— | — | @@ -1513,10 +1506,10 @@ |
1514 | 1507 | $this->setUseFormat( $view ); |
1515 | 1508 | } else { |
1516 | 1509 | // else redirect to mobile domain |
1517 | | - $currentUrl = wfExpandUrl( $wgRequest->getRequestURL() ); |
| 1510 | + $currentUrl = wfExpandUrl( $this->getRequest()->getRequestURL() ); |
1518 | 1511 | $currentUrl = $this->removeQueryStringParameter( $currentUrl, 'mobileaction' ); |
1519 | 1512 | $mobileUrl = $this->getMobileUrl( $currentUrl ); |
1520 | | - $wgOut->redirect( $mobileUrl, 301 ); |
| 1513 | + $this->getOutput()->redirect( $mobileUrl, 301 ); |
1521 | 1514 | } |
1522 | 1515 | } elseif ( $view == 'desktop' ) { |
1523 | 1516 | // set stopMobileRedirect cookie |
— | — | @@ -1533,10 +1526,10 @@ |
1534 | 1527 | $this->setUseFormat( $view ); |
1535 | 1528 | } else { |
1536 | 1529 | // if mobileurl template, redirect to desktop domain |
1537 | | - $currentUrl = wfExpandUrl( $wgRequest->getRequestURL() ); |
| 1530 | + $currentUrl = wfExpandUrl( $this->getRequest()->getRequestURL() ); |
1538 | 1531 | $currentUrl = $this->removeQueryStringParameter( $currentUrl, 'mobileaction' ); |
1539 | 1532 | $desktopUrl = $this->getDesktopUrl( $currentUrl ); |
1540 | | - $wgOut->redirect( $desktopUrl, 301 ); |
| 1533 | + $this->getOutput()->redirect( $desktopUrl, 301 ); |
1541 | 1534 | } |
1542 | 1535 | } |
1543 | 1536 | } |
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -155,14 +155,8 @@ |
156 | 156 | |
157 | 157 | function efMobileFrontend_Setup() { |
158 | 158 | global $wgExtMobileFrontend, $wgHooks; |
159 | | - $wgExtMobileFrontend = new ExtMobileFrontend(); |
160 | | - $wgHooks['RequestContextCreateSkin'][] = array( &$wgExtMobileFrontend, 'requestContextCreateSkin' ); |
161 | | - $wgHooks['BeforePageRedirect'][] = array( &$wgExtMobileFrontend, 'beforePageRedirect' ); |
162 | | - $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' ); |
163 | | - $wgHooks['TestCanonicalRedirect'][] = array( &$wgExtMobileFrontend, 'testCanonicalRedirect' ); |
164 | | - $wgHooks['ResourceLoaderTestModules'][] = array( &$wgExtMobileFrontend, 'addTestModules' ); |
165 | | - $wgHooks['GetCacheVaryCookies'][] = array( &$wgExtMobileFrontend, 'getCacheVaryCookies' ); |
166 | | - $wgHooks['ResourceLoaderRegisterModules'][] = array( &$wgExtMobileFrontend, 'resourceLoaderRegisterModules' ); |
| 159 | + $wgExtMobileFrontend = new ExtMobileFrontend( RequestContext::getMain() ); |
| 160 | + $wgExtMobileFrontend->attachHooks(); |
167 | 161 | } |
168 | 162 | |
169 | 163 | /** |
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php |
— | — | @@ -14,6 +14,7 @@ |
15 | 15 | $appleTouchIconTag = ''; |
16 | 16 | } |
17 | 17 | |
| 18 | + $htmlTitle = htmlspecialchars( $this->data['htmlTitle'] ); |
18 | 19 | $zeroRatedBanner = ( isset( $this->data['zeroRatedBanner'] ) ) ? str_replace( 'style="display:none;"', '', $this->data['zeroRatedBanner'] ) : ''; |
19 | 20 | |
20 | 21 | if ( $zeroRatedBanner ) { |
— | — | @@ -57,11 +58,11 @@ |
58 | 59 | ); |
59 | 60 | if ( $this->data['title']->isMainPage() ) { |
60 | 61 | $jsconfig['messages']['empty-homepage'] = wfMsg( 'mobile-frontend-empty-homepage' ); |
| 62 | + $firstHeading = ''; |
| 63 | + } else { |
61 | 64 | $firstHeading = Html::element( 'h1', array( 'id' => 'firstHeading' ), |
62 | 65 | $this->data['pageTitle'] |
63 | 66 | ); |
64 | | - } else { |
65 | | - $firstHeading = ''; |
66 | 67 | } |
67 | 68 | $configuration = FormatJSON::encode( $jsconfig ); |
68 | 69 | |
— | — | @@ -76,7 +77,7 @@ |
77 | 78 | <!DOCTYPE html> |
78 | 79 | <html lang='{$this->data['code']}' dir='{$this->data['dir']}' xml:lang='{$this->data['code']}' xmlns='http://www.w3.org/1999/xhtml'> |
79 | 80 | <head> |
80 | | - <title>{$this->data['htmlTitle']}</title> |
| 81 | + <title>{$htmlTitle}</title> |
81 | 82 | <meta http-equiv="content-type" content="text/html; charset=utf-8" />{$robots} |
82 | 83 | {$this->data['cssLinks']} |
83 | 84 | <meta name="viewport" content="initial-scale=1.0, user-scalable=yes"> |