Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | ); |
67 | 67 | |
68 | 68 | class ExtMobileFrontend { |
69 | | - const VERSION = '0.5.59'; |
| 69 | + const VERSION = '0.5.60'; |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @var DOMDocument |
— | — | @@ -728,17 +728,6 @@ |
729 | 729 | return $itemToRemoveRecords; |
730 | 730 | } |
731 | 731 | |
732 | | - private function getClassElement( $DOMElement, $className ) { |
733 | | - $children = $DOMElement->childNodes; |
734 | | - foreach ( $children as $child ) { |
735 | | - if ( $child->hasAttributes() && |
736 | | - $child->getAttribute( 'class' ) == $className ) { |
737 | | - return $child; |
738 | | - } |
739 | | - } |
740 | | - return $DOMElement; |
741 | | - } |
742 | | - |
743 | 732 | public function DOMParseMainPage( $html ) { |
744 | 733 | wfProfileIn( __METHOD__ ); |
745 | 734 | $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
— | — | @@ -755,28 +744,10 @@ |
756 | 745 | $featuredArticle = $this->mainPage->getElementById( 'mp-tfa' ); |
757 | 746 | $newsItems = $this->mainPage->getElementById( 'mp-itn' ); |
758 | 747 | |
759 | | - switch ( self::$code ) { |
760 | | - case 'de': |
761 | | - $featuredArticle = $this->mainPage->getElementById( 'hauptseite-artikel' ); |
762 | | - $featuredArticle = $this->getClassElement($featuredArticle, 'inhalt' ); |
763 | | - |
764 | | - $newsItems = $this->mainPage->getElementById( 'hauptseite-nachrichten' ); |
765 | | - $newsItems = $this->getClassElement($newsItems, 'inhalt' ); |
766 | | - break; |
767 | | - case 'fr': |
768 | | - $featuredArticle = $this->mainPage->getElementById( 'accueil-lumieresur' ); |
769 | | - $newsItems = $this->mainPage->getElementById( 'accueil-actualite' ); |
770 | | - break; |
771 | | - case 'ku': |
772 | | - $newsItems = $this->mainPage->getElementById( 'hauptseite-wikipedia' ); |
773 | | - $newsItems = $this->getClassElement($newsItems, 'inhalt' ); |
774 | | - break; |
775 | | - case 'bh': |
776 | | - $featuredArticle = $this->mainPage->getElementById( 'mp-featured_article' ); |
777 | | - break; |
778 | | - case 'ja': |
779 | | - break; |
780 | | - } |
| 748 | + $xpath = new DOMXpath( $this->mainPage ); |
| 749 | + $elements = $xpath->query( '//*[starts-with(@id, "mp-")]' ); |
| 750 | + |
| 751 | + $commonAttributes = array('mp-tfa', 'mp-itn'); |
781 | 752 | |
782 | 753 | $content = $this->mainPage->createElement( 'div' ); |
783 | 754 | $content->setAttribute( 'id', 'main_box' ); |
— | — | @@ -793,6 +764,18 @@ |
794 | 765 | $content->appendChild( $newsItems ); |
795 | 766 | } |
796 | 767 | |
| 768 | + foreach ( $elements as $element ) { |
| 769 | + if ( $element->hasAttribute( 'id' ) ) { |
| 770 | + $id = $element->getAttribute( 'id' ); |
| 771 | + if ( !in_array( $id, $commonAttributes ) ) { |
| 772 | + $elementTitle = $element->hasAttribute( 'title' ) ? $element->getAttribute( 'title' ) : ''; |
| 773 | + $h2UnknownMobileSection = $this->mainPage->createElement( 'h2', $elementTitle ); |
| 774 | + $content->appendChild( $h2UnknownMobileSection ); |
| 775 | + $content->appendChild( $element ); |
| 776 | + } |
| 777 | + } |
| 778 | + } |
| 779 | + |
797 | 780 | $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG ); |
798 | 781 | wfProfileOut( __METHOD__ ); |
799 | 782 | return $contentHtml; |