Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -87,7 +87,7 @@ |
88 | 88 | } |
89 | 89 | |
90 | 90 | class ExtMobileFrontend { |
91 | | - const VERSION = '0.5.81'; |
| 91 | + const VERSION = '0.5.82'; |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @var DOMDocument |
— | — | @@ -432,156 +432,155 @@ |
433 | 433 | // echo $e->getMessage(); |
434 | 434 | } |
435 | 435 | |
436 | | - // The title |
437 | | - self::$title = $out->getTitle(); |
438 | | - |
439 | | - if ( Title::newMainPage()->equals( self::$title ) ) { |
440 | | - self::$isMainPage = true; |
441 | | - } |
442 | | - |
443 | | - if ( self::$title == 'Special:UserLogin' ) { |
444 | | - self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' ); |
445 | | - $returnToVal = $wgRequest->getVal( 'returnto' ); |
446 | | - $returnto = ( !empty ( $returnToVal ) ) ? '&returnto=' . wfUrlencode( $returnToVal ) : ''; |
447 | | - self::$wsLoginFormAction = self::$title->getLocalURL( 'action=submitlogin&type=login' . $returnto ); |
448 | | - } |
449 | | - |
450 | | - self::$htmlTitle = $out->getHTMLTitle(); |
451 | | - |
452 | 436 | // Note: The WebRequest Class calls are made in this block because |
453 | 437 | // since PHP 5.1.x, all objects have their destructors called |
454 | 438 | // before the output buffer callback function executes. |
455 | 439 | // Thus, globalized objects will not be available as expected in the function. |
456 | 440 | // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104] |
457 | | - |
| 441 | + |
| 442 | + $xDevice = !empty( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
| 443 | + self::$useFormat = $wgRequest->getText( 'useformat' ); |
458 | 444 | $mobileAction = $wgRequest->getText( 'mobileaction' ); |
459 | 445 | $action = $wgRequest->getText( 'action' ); |
460 | | - self::$disableImages = $wgRequest->getText( 'disableImages', 0 ); |
461 | | - self::$enableImages = $wgRequest->getText( 'enableImages', 0 ); |
462 | | - self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' ); |
463 | 446 | |
464 | | - if ( self::$disableImages == 1 ) { |
465 | | - $wgRequest->response()->setcookie( 'disableImages', 1 ); |
466 | | - $location = str_replace( '?disableImages=1', '', str_replace( '&disableImages=1', '', $wgRequest->getFullRequestURL() ) ); |
467 | | - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) ); |
468 | | - $location = $this->getRelativeURL( $location ); |
469 | | - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' ); |
470 | | - } |
| 447 | + if ( self::$useFormat === 'mobile' || |
| 448 | + self::$useFormat === 'mobile-wap' || |
| 449 | + !empty( $xDevice ) ) { |
| 450 | + if ( $action !== 'edit' && |
| 451 | + $mobileAction !== 'view_normal_site' ) { |
471 | 452 | |
472 | | - if ( self::$disableImages == 0 ) { |
473 | | - $disableImages = $wgRequest->getCookie( 'disableImages' ); |
474 | | - if ( $disableImages ) { |
475 | | - self::$disableImages = $disableImages; |
476 | | - } |
477 | | - } |
| 453 | + self::$title = $out->getTitle(); |
478 | 454 | |
479 | | - if ( self::$enableImages == 1 ) { |
480 | | - $disableImages = $wgRequest->getCookie( 'disableImages' ); |
481 | | - if ( $disableImages ) { |
482 | | - $wgRequest->response()->setcookie( 'disableImages', '' ); |
483 | | - } |
484 | | - $location = str_replace( '?enableImages=1', '', str_replace( '&enableImages=1', '', $wgRequest->getFullRequestURL() ) ); |
485 | | - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) ); |
486 | | - $location = $this->getRelativeURL( $location ); |
487 | | - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=1' ); |
488 | | - } |
| 455 | + if ( Title::newMainPage()->equals( self::$title ) ) { |
| 456 | + self::$isMainPage = true; |
| 457 | + } |
489 | 458 | |
490 | | - self::$useFormat = $wgRequest->getText( 'useformat' ); |
491 | | - self::$format = $wgRequest->getText( 'format' ); |
492 | | - self::$requestedSegment = $wgRequest->getText( 'seg', 0 ); |
493 | | - self::$search = $wgRequest->getText( 'search' ); |
494 | | - self::$callback = $wgRequest->getText( 'callback' ); |
495 | | - self::$searchField = $wgRequest->getText( 'search', '' ); |
| 459 | + if ( self::$title == 'Special:UserLogin' ) { |
| 460 | + self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' ); |
| 461 | + $returnToVal = $wgRequest->getVal( 'returnto' ); |
| 462 | + $returnto = ( !empty ( $returnToVal ) ) ? '&returnto=' . wfUrlencode( $returnToVal ) : ''; |
| 463 | + self::$wsLoginFormAction = self::$title->getLocalURL( 'action=submitlogin&type=login' . $returnto ); |
| 464 | + } |
496 | 465 | |
497 | | - $xDevice = !empty( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
| 466 | + self::$htmlTitle = $out->getHTMLTitle(); |
| 467 | + self::$disableImages = $wgRequest->getText( 'disableImages', 0 ); |
| 468 | + self::$enableImages = $wgRequest->getText( 'enableImages', 0 ); |
| 469 | + self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' ); |
498 | 470 | |
499 | | - $acceptHeader = !empty( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : ''; |
500 | | - $device = new DeviceDetection(); |
| 471 | + if ( self::$disableImages == 1 ) { |
| 472 | + $wgRequest->response()->setcookie( 'disableImages', 1 ); |
| 473 | + $location = str_replace( '?disableImages=1', '', str_replace( '&disableImages=1', '', $wgRequest->getFullRequestURL() ) ); |
| 474 | + $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) ); |
| 475 | + $location = $this->getRelativeURL( $location ); |
| 476 | + $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' ); |
| 477 | + } |
501 | 478 | |
502 | | - if ( !empty( $xDevice ) ) { |
503 | | - $formatName = $xDevice; |
504 | | - } else { |
505 | | - $formatName = $device->formatName( $userAgent, $acceptHeader ); |
506 | | - } |
| 479 | + if ( self::$disableImages == 0 ) { |
| 480 | + $disableImages = $wgRequest->getCookie( 'disableImages' ); |
| 481 | + if ( $disableImages ) { |
| 482 | + self::$disableImages = $disableImages; |
| 483 | + } |
| 484 | + } |
507 | 485 | |
508 | | - self::$device = $device->format( $formatName ); |
| 486 | + if ( self::$enableImages == 1 ) { |
| 487 | + $disableImages = $wgRequest->getCookie( 'disableImages' ); |
| 488 | + if ( $disableImages ) { |
| 489 | + $wgRequest->response()->setcookie( 'disableImages', '' ); |
| 490 | + } |
| 491 | + $location = str_replace( '?enableImages=1', '', str_replace( '&enableImages=1', '', $wgRequest->getFullRequestURL() ) ); |
| 492 | + $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) ); |
| 493 | + $location = $this->getRelativeURL( $location ); |
| 494 | + $wgRequest->response()->header( 'Location: ' . $location . '&mfi=1' ); |
| 495 | + } |
509 | 496 | |
510 | | - if ( self::$device['view_format'] === 'wml' ) { |
511 | | - $this->contentFormat = 'WML'; |
512 | | - } elseif ( self::$device['view_format'] === 'html' ) { |
513 | | - $this->contentFormat = 'XHTML'; |
514 | | - } |
| 497 | + self::$format = $wgRequest->getText( 'format' ); |
| 498 | + self::$callback = $wgRequest->getText( 'callback' ); |
| 499 | + self::$requestedSegment = $wgRequest->getText( 'seg', 0 ); |
| 500 | + self::$search = $wgRequest->getText( 'search' ); |
| 501 | + self::$searchField = $wgRequest->getText( 'search', '' ); |
515 | 502 | |
516 | | - if ( self::$useFormat === 'mobile-wap' ) { |
517 | | - $this->contentFormat = 'WML'; |
518 | | - } |
| 503 | + $acceptHeader = !empty( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : ''; |
| 504 | + $device = new DeviceDetection(); |
519 | 505 | |
520 | | - if ( $mobileAction == 'leave_feedback' ) { |
521 | | - echo $this->renderLeaveFeedbackXHTML(); |
522 | | - wfProfileOut( __METHOD__ ); |
523 | | - exit(); |
524 | | - } |
| 506 | + if ( !empty( $xDevice ) ) { |
| 507 | + $formatName = $xDevice; |
| 508 | + } else { |
| 509 | + $formatName = $device->formatName( $userAgent, $acceptHeader ); |
| 510 | + } |
525 | 511 | |
526 | | - if ( $mobileAction == 'leave_feedback_post' ) { |
| 512 | + self::$device = $device->format( $formatName ); |
527 | 513 | |
528 | | - $this->getMsg(); |
| 514 | + if ( self::$device['view_format'] === 'wml' ) { |
| 515 | + $this->contentFormat = 'WML'; |
| 516 | + } elseif ( self::$device['view_format'] === 'html' ) { |
| 517 | + $this->contentFormat = 'XHTML'; |
| 518 | + } |
529 | 519 | |
530 | | - $subject = $wgRequest->getText( 'subject', '' ); |
531 | | - $message = $wgRequest->getText( 'message', '' ); |
532 | | - $token = $wgRequest->getText( 'edittoken', '' ); |
| 520 | + if ( self::$useFormat === 'mobile-wap' ) { |
| 521 | + $this->contentFormat = 'WML'; |
| 522 | + } |
533 | 523 | |
534 | | - $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] ); |
| 524 | + if ( $mobileAction == 'leave_feedback' ) { |
| 525 | + echo $this->renderLeaveFeedbackXHTML(); |
| 526 | + wfProfileOut( __METHOD__ ); |
| 527 | + exit(); |
| 528 | + } |
535 | 529 | |
536 | | - if ( $title->userCan( 'edit' ) && |
537 | | - !$wgUser->isBlockedFrom( $title ) && |
538 | | - $wgUser->matchEditToken( $token ) ) { |
539 | | - $article = new Article( $title, 0 ); |
540 | | - $rawtext = $article->getRawText(); |
541 | | - $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> "; |
542 | | - $article->doEdit( $rawtext, '' ); |
543 | | - } |
| 530 | + if ( $mobileAction == 'leave_feedback_post' ) { |
544 | 531 | |
545 | | - $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '¬iceid=1&useformat=mobile' ); |
546 | | - $location = $this->getRelativeURL( $location ); |
547 | | - $wgRequest->response()->header( 'Location: ' . $location ); |
548 | | - wfProfileOut( __METHOD__ ); |
549 | | - exit(); |
550 | | - } |
| 532 | + $this->getMsg(); |
551 | 533 | |
552 | | - if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) { |
553 | | - echo $this->renderDisableMobileSiteXHTML(); |
554 | | - wfProfileOut( __METHOD__ ); |
555 | | - exit(); |
556 | | - } |
| 534 | + $subject = $wgRequest->getText( 'subject', '' ); |
| 535 | + $message = $wgRequest->getText( 'message', '' ); |
| 536 | + $token = $wgRequest->getText( 'edittoken', '' ); |
557 | 537 | |
558 | | - if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) { |
559 | | - echo $this->renderOptInMobileSiteXHTML(); |
560 | | - wfProfileOut( __METHOD__ ); |
561 | | - exit(); |
562 | | - } |
| 538 | + $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] ); |
563 | 539 | |
564 | | - if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) { |
565 | | - echo $this->renderOptOutMobileSiteXHTML(); |
566 | | - wfProfileOut( __METHOD__ ); |
567 | | - exit(); |
568 | | - } |
| 540 | + if ( $title->userCan( 'edit' ) && |
| 541 | + !$wgUser->isBlockedFrom( $title ) && |
| 542 | + $wgUser->matchEditToken( $token ) ) { |
| 543 | + $article = new Article( $title, 0 ); |
| 544 | + $rawtext = $article->getRawText(); |
| 545 | + $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> "; |
| 546 | + $article->doEdit( $rawtext, '' ); |
| 547 | + } |
569 | 548 | |
570 | | - if ( $mobileAction == 'opt_in_cookie' ) { |
571 | | - $this->setOptInOutCookie( '1' ); |
572 | | - $this->disableCaching(); |
573 | | - $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT ); |
574 | | - $wgRequest->response()->header( 'Location: ' . $location ); |
575 | | - } |
| 549 | + $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '¬iceid=1&useformat=mobile' ); |
| 550 | + $location = $this->getRelativeURL( $location ); |
| 551 | + $wgRequest->response()->header( 'Location: ' . $location ); |
| 552 | + wfProfileOut( __METHOD__ ); |
| 553 | + exit(); |
| 554 | + } |
576 | 555 | |
577 | | - if ( $mobileAction == 'opt_out_cookie' ) { |
578 | | - $this->setOptInOutCookie( '' ); |
579 | | - } |
| 556 | + if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) { |
| 557 | + echo $this->renderDisableMobileSiteXHTML(); |
| 558 | + wfProfileOut( __METHOD__ ); |
| 559 | + exit(); |
| 560 | + } |
580 | 561 | |
581 | | - if ( self::$useFormat === 'mobile' || |
582 | | - self::$useFormat === 'mobile-wap' || |
583 | | - !empty( $xDevice ) ) { |
584 | | - if ( $action !== 'edit' && |
585 | | - $mobileAction !== 'view_normal_site' ) { |
| 562 | + if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) { |
| 563 | + echo $this->renderOptInMobileSiteXHTML(); |
| 564 | + wfProfileOut( __METHOD__ ); |
| 565 | + exit(); |
| 566 | + } |
| 567 | + |
| 568 | + if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) { |
| 569 | + echo $this->renderOptOutMobileSiteXHTML(); |
| 570 | + wfProfileOut( __METHOD__ ); |
| 571 | + exit(); |
| 572 | + } |
| 573 | + |
| 574 | + if ( $mobileAction == 'opt_in_cookie' ) { |
| 575 | + $this->setOptInOutCookie( '1' ); |
| 576 | + $this->disableCaching(); |
| 577 | + $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT ); |
| 578 | + $wgRequest->response()->header( 'Location: ' . $location ); |
| 579 | + } |
| 580 | + |
| 581 | + if ( $mobileAction == 'opt_out_cookie' ) { |
| 582 | + $this->setOptInOutCookie( '' ); |
| 583 | + } |
| 584 | + |
586 | 585 | $this->getMsg(); |
587 | 586 | $this->disableCaching(); |
588 | 587 | $this->sendXDeviceVaryHeader(); |