Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | /** |
8 | 8 | * @var DOMDocument |
9 | 9 | */ |
10 | | - private $doc, $mainPage; |
| 10 | + private $doc; |
11 | 11 | public $contentFormat = ''; |
12 | 12 | public $WMLSectionSeperator = '***************************************************************************'; |
13 | 13 | |
— | — | @@ -711,7 +711,7 @@ |
712 | 712 | $domainParts = array_reverse( $domainParts ); |
713 | 713 | // Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included. |
714 | 714 | wfProfileOut( __METHOD__ ); |
715 | | - return '.' . $domainParts[1] . '.' . $domainParts[0]; |
| 715 | + return count( $domainParts ) >= 2 ? '.' . $domainParts[1] . '.' . $domainParts[0] : $_SERVER['HTTP_HOST']; |
716 | 716 | } |
717 | 717 | wfProfileOut( __METHOD__ ); |
718 | 718 | return $_SERVER['HTTP_HOST']; |
— | — | @@ -1125,32 +1125,22 @@ |
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | /** |
1129 | | - * @param $html string |
| 1129 | + * @param DOMNode $mainPage |
1130 | 1130 | * @return string |
1131 | 1131 | */ |
1132 | | - public function DOMParseMainPage( $html ) { |
| 1132 | + public function DOMParseMainPage( DOMDocument $mainPage ) { |
1133 | 1133 | wfProfileIn( __METHOD__ ); |
1134 | | - $html = mb_convert_encoding( $html, 'HTML-ENTITIES', "UTF-8" ); |
1135 | | - libxml_use_internal_errors( true ); |
1136 | | - $this->mainPage = new DOMDocument(); |
1137 | | - // It seems that loadhtml() does not "attach" the html dtd that defines id as an id-attribute to the DOM. |
1138 | | - $this->mainPage->loadHTML( '<?xml encoding="UTF-8"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
1139 | | - <html><head><title></title></head><body>' . $html . '</body></html>' ); |
1140 | | - libxml_use_internal_errors( false ); |
1141 | | - $this->mainPage->preserveWhiteSpace = false; |
1142 | | - $this->mainPage->strictErrorChecking = false; |
1143 | | - $this->mainPage->encoding = 'UTF-8'; |
1144 | 1134 | |
1145 | | - $zeroLandingPage = $this->mainPage->getElementById( 'zero-landing-page' ); |
1146 | | - $featuredArticle = $this->mainPage->getElementById( 'mp-tfa' ); |
1147 | | - $newsItems = $this->mainPage->getElementById( 'mp-itn' ); |
| 1135 | + $zeroLandingPage = $mainPage->getElementById( 'zero-landing-page' ); |
| 1136 | + $featuredArticle = $mainPage->getElementById( 'mp-tfa' ); |
| 1137 | + $newsItems = $mainPage->getElementById( 'mp-itn' ); |
1148 | 1138 | |
1149 | | - $xpath = new DOMXpath( $this->mainPage ); |
| 1139 | + $xpath = new DOMXpath( $mainPage ); |
1150 | 1140 | $elements = $xpath->query( '//*[starts-with(@id, "mf-")]' ); |
1151 | 1141 | |
1152 | 1142 | $commonAttributes = array( 'mp-tfa', 'mp-itn' ); |
1153 | 1143 | |
1154 | | - $content = $this->mainPage->createElement( 'div' ); |
| 1144 | + $content = $mainPage->createElement( 'div' ); |
1155 | 1145 | $content->setAttribute( 'id', 'content' ); |
1156 | 1146 | |
1157 | 1147 | if ( $zeroLandingPage ) { |
— | — | @@ -1158,13 +1148,13 @@ |
1159 | 1149 | } |
1160 | 1150 | |
1161 | 1151 | if ( $featuredArticle ) { |
1162 | | - $h2FeaturedArticle = $this->mainPage->createElement( 'h2', self::$messages['mobile-frontend-featured-article'] ); |
| 1152 | + $h2FeaturedArticle = $mainPage->createElement( 'h2', self::$messages['mobile-frontend-featured-article'] ); |
1163 | 1153 | $content->appendChild( $h2FeaturedArticle ); |
1164 | 1154 | $content->appendChild( $featuredArticle ); |
1165 | 1155 | } |
1166 | 1156 | |
1167 | 1157 | if ( $newsItems ) { |
1168 | | - $h2NewsItems = $this->mainPage->createElement( 'h2', self::$messages['mobile-frontend-news-items'] ); |
| 1158 | + $h2NewsItems = $mainPage->createElement( 'h2', self::$messages['mobile-frontend-news-items'] ); |
1169 | 1159 | $content->appendChild( $h2NewsItems ); |
1170 | 1160 | $content->appendChild( $newsItems ); |
1171 | 1161 | } |
— | — | @@ -1174,8 +1164,8 @@ |
1175 | 1165 | $id = $element->getAttribute( 'id' ); |
1176 | 1166 | if ( !in_array( $id, $commonAttributes ) ) { |
1177 | 1167 | $elementTitle = $element->hasAttribute( 'title' ) ? $element->getAttribute( 'title' ) : ''; |
1178 | | - $h2UnknownMobileSection = $this->mainPage->createElement( 'h2', $elementTitle ); |
1179 | | - $br = $this->mainPage->createElement( 'br' ); |
| 1168 | + $h2UnknownMobileSection = $mainPage->createElement( 'h2', $elementTitle ); |
| 1169 | + $br = $mainPage->createElement( 'br' ); |
1180 | 1170 | $br->setAttribute( 'CLEAR', 'ALL' ); |
1181 | 1171 | $content->appendChild( $h2UnknownMobileSection ); |
1182 | 1172 | $content->appendChild( $element ); |
— | — | @@ -1184,7 +1174,7 @@ |
1185 | 1175 | } |
1186 | 1176 | } |
1187 | 1177 | |
1188 | | - $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG ); |
| 1178 | + $contentHtml = $mainPage->saveXML( $content, LIBXML_NOEMPTYTAG ); |
1189 | 1179 | wfProfileOut( __METHOD__ ); |
1190 | 1180 | return $contentHtml; |
1191 | 1181 | } |
— | — | @@ -1443,12 +1433,11 @@ |
1444 | 1434 | } |
1445 | 1435 | } |
1446 | 1436 | |
1447 | | - $content = $this->doc->getElementById( 'content' ); |
1448 | | - |
1449 | | - $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |
1450 | | - |
1451 | 1437 | if ( self::$isMainPage ) { |
1452 | | - $contentHtml = $this->DOMParseMainPage( $contentHtml ); |
| 1438 | + $contentHtml = $this->DOMParseMainPage( $this->doc ); |
| 1439 | + } else { |
| 1440 | + $content = $this->doc->getElementById( 'content' ); |
| 1441 | + $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |
1453 | 1442 | } |
1454 | 1443 | |
1455 | 1444 | $title = htmlspecialchars( self::$title->getText() ); |