Index: trunk/extensions/MobileFrontend/MobileFormatter.php |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | protected $title; |
22 | 22 | |
23 | 23 | protected $expandableSections = false; |
| 24 | + protected $mainPage = false; |
24 | 25 | |
25 | 26 | private $headings = 0; |
26 | 27 | |
— | — | @@ -115,6 +116,10 @@ |
116 | 117 | $this->expandableSections = $flag; |
117 | 118 | } |
118 | 119 | |
| 120 | + public function setIsMainPage( $value = true ) { |
| 121 | + $this->mainPage = $value; |
| 122 | + } |
| 123 | + |
119 | 124 | /** |
120 | 125 | * Sets whether images should be removed from output |
121 | 126 | * @param bool $flag |
— | — | @@ -236,12 +241,16 @@ |
237 | 242 | |
238 | 243 | public function getText( $id = false, $prependHtml = '', $appendHtml = '' ) { |
239 | 244 | wfProfileIn( __METHOD__ ); |
240 | | - $element = $id ? $this->doc->getElementById( $id ) : null; |
241 | | - $html = $this->doc->saveXML( $element, LIBXML_NOEMPTYTAG ); |
| 245 | + if ( $this->mainPage ) { |
| 246 | + $element = $this->parseMainPage( $this->doc ); |
| 247 | + } else { |
| 248 | + $element = $id ? $this->doc->getElementById( $id ) : null; |
| 249 | + } |
| 250 | + $html = $prependHtml . $this->doc->saveXML( $element, LIBXML_NOEMPTYTAG ) . $appendHtml; |
242 | 251 | |
243 | 252 | switch ( $this->format ) { |
244 | 253 | case 'XHTML': |
245 | | - if ( $this->expandableSections && strlen( $html ) > 4000 ) { |
| 254 | + if ( $this->expandableSections && !$this->mainPage && strlen( $html ) > 4000 ) { |
246 | 255 | $html = $this->headingTransform( $html ); |
247 | 256 | } |
248 | 257 | break; |
— | — | @@ -470,4 +479,58 @@ |
471 | 480 | wfProfileOut( __METHOD__ ); |
472 | 481 | return $removals; |
473 | 482 | } |
| 483 | + |
| 484 | + /** |
| 485 | + * @param DOMDocument $mainPage |
| 486 | + * @return DOMElement |
| 487 | + */ |
| 488 | + protected function parseMainPage( DOMDocument $mainPage ) { |
| 489 | + wfProfileIn( __METHOD__ ); |
| 490 | + |
| 491 | + $zeroLandingPage = $mainPage->getElementById( 'zero-landing-page' ); |
| 492 | + $featuredArticle = $mainPage->getElementById( 'mp-tfa' ); |
| 493 | + $newsItems = $mainPage->getElementById( 'mp-itn' ); |
| 494 | + |
| 495 | + $xpath = new DOMXpath( $mainPage ); |
| 496 | + $elements = $xpath->query( '//*[starts-with(@id, "mf-")]' ); |
| 497 | + |
| 498 | + $commonAttributes = array( 'mp-tfa', 'mp-itn' ); |
| 499 | + |
| 500 | + $content = $mainPage->createElement( 'div' ); |
| 501 | + $content->setAttribute( 'id', 'content' ); |
| 502 | + |
| 503 | + if ( $zeroLandingPage ) { |
| 504 | + $content->appendChild( $zeroLandingPage ); |
| 505 | + } |
| 506 | + |
| 507 | + if ( $featuredArticle ) { |
| 508 | + $h2FeaturedArticle = $mainPage->createElement( 'h2', $this->msg( 'mobile-frontend-featured-article' ) ); |
| 509 | + $content->appendChild( $h2FeaturedArticle ); |
| 510 | + $content->appendChild( $featuredArticle ); |
| 511 | + } |
| 512 | + |
| 513 | + if ( $newsItems ) { |
| 514 | + $h2NewsItems = $mainPage->createElement( 'h2', $this->msg( 'mobile-frontend-news-items' ) ); |
| 515 | + $content->appendChild( $h2NewsItems ); |
| 516 | + $content->appendChild( $newsItems ); |
| 517 | + } |
| 518 | + |
| 519 | + foreach ( $elements as $element ) { |
| 520 | + if ( $element->hasAttribute( 'id' ) ) { |
| 521 | + $id = $element->getAttribute( 'id' ); |
| 522 | + if ( !in_array( $id, $commonAttributes ) ) { |
| 523 | + $elementTitle = $element->hasAttribute( 'title' ) ? $element->getAttribute( 'title' ) : ''; |
| 524 | + $h2UnknownMobileSection = $mainPage->createElement( 'h2', $elementTitle ); |
| 525 | + $br = $mainPage->createElement( 'br' ); |
| 526 | + $br->setAttribute( 'CLEAR', 'ALL' ); |
| 527 | + $content->appendChild( $h2UnknownMobileSection ); |
| 528 | + $content->appendChild( $element ); |
| 529 | + $content->appendChild( $br ); |
| 530 | + } |
| 531 | + } |
| 532 | + } |
| 533 | + |
| 534 | + wfProfileOut( __METHOD__ ); |
| 535 | + return $content; |
| 536 | + } |
474 | 537 | } |
Index: trunk/extensions/MobileFrontend/ApiParseExtender.php |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 | ); |
19 | 19 | $params['expandablesections'] = false; |
20 | 20 | $params['noimages'] = false; |
| 21 | + $params['mainpage'] = false; |
21 | 22 | } |
22 | 23 | return true; |
23 | 24 | } |
— | — | @@ -33,6 +34,7 @@ |
34 | 35 | $params['expandablesections'] = 'Make sections in mobile output collapsed by default, expandable via JavaScript.' |
35 | 36 | . " Ignored if `section' parameter is set."; |
36 | 37 | $params['noimages'] = 'Disable images in mobile output'; |
| 38 | + $params['mainpage'] = 'Apply mobile main page transformations'; |
37 | 39 | } |
38 | 40 | return true; |
39 | 41 | } |
— | — | @@ -80,12 +82,16 @@ |
81 | 83 | ); |
82 | 84 | if ( $params['expandablesections'] ) { |
83 | 85 | if ( isset( $params['section'] ) ) { |
84 | | - $module->setWarning( "`expandablesections' and `section' can't be used simultaneusly" ); |
| 86 | + $module->setWarning( "`expandablesections' and `section' can't be used simultaneously" ); |
85 | 87 | } elseif ( !$title->isMainPage() ) { |
86 | 88 | $mf->enableExpandableSections(); |
87 | 89 | } |
88 | 90 | } |
89 | 91 | $mf->removeImages( $params['noimages'] ); |
| 92 | + $mf->setIsMainPage( $params['mainpage'] ); |
| 93 | + if ( $params['mainpage'] && $params['expandablesections'] ) { |
| 94 | + $module->setWarning( "`mainpage' and `expandablesections' can't be used simultaneously" ); |
| 95 | + } |
90 | 96 | $mf->filterContent(); |
91 | 97 | $data['parse']['text'] = $mf->getText( 'content' ); |
92 | 98 | |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -921,58 +921,6 @@ |
922 | 922 | } |
923 | 923 | |
924 | 924 | /** |
925 | | - * @param DOMDocument $mainPage |
926 | | - */ |
927 | | - public function DOMParseMainPage( DOMDocument $mainPage ) { |
928 | | - wfProfileIn( __METHOD__ ); |
929 | | - |
930 | | - $zeroLandingPage = $mainPage->getElementById( 'zero-landing-page' ); |
931 | | - $featuredArticle = $mainPage->getElementById( 'mp-tfa' ); |
932 | | - $newsItems = $mainPage->getElementById( 'mp-itn' ); |
933 | | - |
934 | | - $xpath = new DOMXpath( $mainPage ); |
935 | | - $elements = $xpath->query( '//*[starts-with(@id, "mf-")]' ); |
936 | | - |
937 | | - $commonAttributes = array( 'mp-tfa', 'mp-itn' ); |
938 | | - |
939 | | - $content = $mainPage->createElement( 'div' ); |
940 | | - $content->setAttribute( 'id', 'content' ); |
941 | | - |
942 | | - if ( $zeroLandingPage ) { |
943 | | - $content->appendChild( $zeroLandingPage ); |
944 | | - } |
945 | | - |
946 | | - if ( $featuredArticle ) { |
947 | | - $h2FeaturedArticle = $mainPage->createElement( 'h2', self::$messages['mobile-frontend-featured-article'] ); |
948 | | - $content->appendChild( $h2FeaturedArticle ); |
949 | | - $content->appendChild( $featuredArticle ); |
950 | | - } |
951 | | - |
952 | | - if ( $newsItems ) { |
953 | | - $h2NewsItems = $mainPage->createElement( 'h2', self::$messages['mobile-frontend-news-items'] ); |
954 | | - $content->appendChild( $h2NewsItems ); |
955 | | - $content->appendChild( $newsItems ); |
956 | | - } |
957 | | - |
958 | | - foreach ( $elements as $element ) { |
959 | | - if ( $element->hasAttribute( 'id' ) ) { |
960 | | - $id = $element->getAttribute( 'id' ); |
961 | | - if ( !in_array( $id, $commonAttributes ) ) { |
962 | | - $elementTitle = $element->hasAttribute( 'title' ) ? $element->getAttribute( 'title' ) : ''; |
963 | | - $h2UnknownMobileSection = $mainPage->createElement( 'h2', $elementTitle ); |
964 | | - $br = $mainPage->createElement( 'br' ); |
965 | | - $br->setAttribute( 'CLEAR', 'ALL' ); |
966 | | - $content->appendChild( $h2UnknownMobileSection ); |
967 | | - $content->appendChild( $element ); |
968 | | - $content->appendChild( $br ); |
969 | | - } |
970 | | - } |
971 | | - } |
972 | | - |
973 | | - wfProfileOut( __METHOD__ ); |
974 | | - } |
975 | | - |
976 | | - /** |
977 | 925 | * @return DomElement |
978 | 926 | */ |
979 | 927 | public function renderLogin() { |
— | — | @@ -1134,9 +1082,7 @@ |
1135 | 1083 | } |
1136 | 1084 | } |
1137 | 1085 | |
1138 | | - if ( self::$isMainPage ) { |
1139 | | - $this->DOMParseMainPage( $doc ); |
1140 | | - } |
| 1086 | + $formatter->setIsMainPage( self::$isMainPage ); |
1141 | 1087 | $prepend = ''; |
1142 | 1088 | if ( $this->contentFormat == 'WML' ) { |
1143 | 1089 | // Wml for searching |
— | — | @@ -1145,7 +1091,7 @@ |
1146 | 1092 | '<go href="' . $wgScript . '?title=Special%3ASearch&search=$(search)"></go></do></p>'; |
1147 | 1093 | } elseif ( $this->contentFormat == 'XHTML' |
1148 | 1094 | && self::$device['supports_javascript'] === true |
1149 | | - && empty( self::$search ) && !self::$isMainPage ) |
| 1095 | + && empty( self::$search ) ) |
1150 | 1096 | { |
1151 | 1097 | $formatter->enableExpandableSections(); |
1152 | 1098 | } |