r96520 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96519‎ | r96520 | r96521 >
Date:23:34, 7 September 2011
Author:preilly
Status:ok
Tags:
Comment:
newer fix for bug 30785 - missing main page on mobile frontend
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -65,7 +65,7 @@
6666 );
6767
6868 class ExtMobileFrontend {
69 - const VERSION = '0.5.59';
 69+ const VERSION = '0.5.60';
7070
7171 /**
7272 * @var DOMDocument
@@ -728,17 +728,6 @@
729729 return $itemToRemoveRecords;
730730 }
731731
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 -
743732 public function DOMParseMainPage( $html ) {
744733 wfProfileIn( __METHOD__ );
745734 $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
@@ -755,28 +744,10 @@
756745 $featuredArticle = $this->mainPage->getElementById( 'mp-tfa' );
757746 $newsItems = $this->mainPage->getElementById( 'mp-itn' );
758747
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');
781752
782753 $content = $this->mainPage->createElement( 'div' );
783754 $content->setAttribute( 'id', 'main_box' );
@@ -793,6 +764,18 @@
794765 $content->appendChild( $newsItems );
795766 }
796767
 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+
797780 $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG );
798781 wfProfileOut( __METHOD__ );
799782 return $contentHtml;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96365fix for bug 30785 - missing main page on mobile frontendpreilly20:07, 6 September 2011

Status & tagging log