Index: trunk/extensions/MobileFrontend/MobileFrontend.i18n.php |
— | — | @@ -56,6 +56,8 @@ |
57 | 57 | 'mobile-frontend-opt-out-explain' => 'This allows you to leave the test', |
58 | 58 | 'mobile-frontend-disable-images' => 'Disable images on mobile site', |
59 | 59 | 'mobile-frontend-enable-images' => 'Enable images on mobile site', |
| 60 | + 'mobile-frontend-featured-article' => 'Today\'s Featured Article', |
| 61 | + 'mobile-frontend-news-items' => 'In The News', |
60 | 62 | ); |
61 | 63 | |
62 | 64 | /** Moroccan Spoken Arabic (Maġribi) */ |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -49,12 +49,13 @@ |
50 | 50 | $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' ); |
51 | 51 | |
52 | 52 | class ExtMobileFrontend { |
53 | | - const VERSION = '0.5.23'; |
| 53 | + const VERSION = '0.5.24'; |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @var DOMDocument |
57 | 57 | */ |
58 | 58 | private $doc; |
| 59 | + private $mainPage; |
59 | 60 | |
60 | 61 | public static $messages = array(); |
61 | 62 | |
— | — | @@ -79,6 +80,7 @@ |
80 | 81 | public static $useFormat; |
81 | 82 | public static $disableImages; |
82 | 83 | public static $enableImages; |
| 84 | + public static $isMainPage = false; |
83 | 85 | |
84 | 86 | public $itemsToRemove = array( |
85 | 87 | '#contentSub', # redirection notice |
— | — | @@ -158,6 +160,8 @@ |
159 | 161 | self::$messages['mobile-frontend-wml-continue'] = wfMsg( 'mobile-frontend-wml-continue' ); |
160 | 162 | self::$messages['mobile-frontend-wml-back'] = wfMsg( 'mobile-frontend-wml-back' ); |
161 | 163 | self::$messages['mobile-frontend-enable-images'] = wfMsg( 'mobile-frontend-enable-images' ); |
| 164 | + self::$messages['mobile-frontend-featured-article'] = wfMsg( 'mobile-frontend-featured-article' ); |
| 165 | + self::$messages['mobile-frontend-news-items'] = wfMsg( 'mobile-frontend-news-items' ); |
162 | 166 | |
163 | 167 | self::$dir = $wgContLang->getDir(); |
164 | 168 | self::$code = $wgContLang->getCode(); |
— | — | @@ -176,6 +180,11 @@ |
177 | 181 | |
178 | 182 | // The title |
179 | 183 | self::$title = $out->getTitle(); |
| 184 | + |
| 185 | + if ( $out->getTitle()->isMainPage() ) { |
| 186 | + self::$isMainPage = true; |
| 187 | + } |
| 188 | + |
180 | 189 | self::$htmlTitle = $out->getHTMLTitle(); |
181 | 190 | |
182 | 191 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
— | — | @@ -328,7 +337,8 @@ |
329 | 338 | if (self::$useFormat === 'mobile' || |
330 | 339 | self::$useFormat === 'mobile-wap' || |
331 | 340 | !empty( $xDevice ) ) { |
332 | | - if ( $action !== 'edit' ) { |
| 341 | + if ( $action !== 'edit' && |
| 342 | + $mAction !== 'view_normal_site' ) { |
333 | 343 | $this->getMsg(); |
334 | 344 | $this->disableCaching(); |
335 | 345 | ob_start( array( $this, 'DOMParse' ) ); |
— | — | @@ -567,7 +577,40 @@ |
568 | 578 | |
569 | 579 | return $itemToRemoveRecords; |
570 | 580 | } |
| 581 | + |
| 582 | + public function DOMParseMainPage( $html ) { |
| 583 | + $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
| 584 | + libxml_use_internal_errors( true ); |
| 585 | + $this->mainPage = new DOMDocument(); |
| 586 | + $this->mainPage->loadHTML( '<?xml encoding="UTF-8">' . $html ); |
| 587 | + libxml_use_internal_errors( false ); |
| 588 | + $this->mainPage->preserveWhiteSpace = false; |
| 589 | + $this->mainPage->strictErrorChecking = false; |
| 590 | + $this->mainPage->encoding = 'UTF-8'; |
| 591 | + |
| 592 | + $featuredArticle = $this->mainPage->getElementById( 'mp-tfa' ); |
| 593 | + $newsItems = $this->mainPage->getElementById( 'mp-itn' ); |
571 | 594 | |
| 595 | + $content = $this->mainPage->createElement( 'div' ); |
| 596 | + $content->setAttribute( 'id', 'main_box' ); |
| 597 | + |
| 598 | + if ( $featuredArticle ) { |
| 599 | + $h2FeaturedArticle = $this->mainPage->createElement( 'h2', self::$messages['mobile-frontend-featured-article'] ); |
| 600 | + $content->appendChild( $h2FeaturedArticle ); |
| 601 | + $content->appendChild( $featuredArticle ); |
| 602 | + } |
| 603 | + |
| 604 | + if ( $newsItems ) { |
| 605 | + $h2NewsItems = $this->mainPage->createElement( 'h2', self::$messages['mobile-frontend-news-items'] ); |
| 606 | + $content->appendChild( $h2NewsItems ); |
| 607 | + $content->appendChild( $newsItems ); |
| 608 | + } |
| 609 | + |
| 610 | + $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG ); |
| 611 | + |
| 612 | + return $contentHtml; |
| 613 | + } |
| 614 | + |
572 | 615 | public function DOMParse( $html ) { |
573 | 616 | global $wgSitename; |
574 | 617 | |
— | — | @@ -664,6 +707,10 @@ |
665 | 708 | $content = $this->doc->getElementById( 'content' ); |
666 | 709 | |
667 | 710 | $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |
| 711 | + |
| 712 | + if ( self::$isMainPage ) { |
| 713 | + $contentHtml = $this->DOMParseMainPage( $contentHtml ); |
| 714 | + } |
668 | 715 | |
669 | 716 | $dir = self::$dir; |
670 | 717 | $code = self::$code; |