r94564 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94563‎ | r94564 | r94565 >
Date:20:53, 15 August 2011
Author:preilly
Status:resolved (Comments)
Tags:
Comment:
add support to render the main page content in a sane way
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.i18n.php (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.i18n.php
@@ -56,6 +56,8 @@
5757 'mobile-frontend-opt-out-explain' => 'This allows you to leave the test',
5858 'mobile-frontend-disable-images' => 'Disable images on mobile site',
5959 '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',
6062 );
6163
6264 /** Moroccan Spoken Arabic (Maġribi) */
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -49,12 +49,13 @@
5050 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' );
5151
5252 class ExtMobileFrontend {
53 - const VERSION = '0.5.23';
 53+ const VERSION = '0.5.24';
5454
5555 /**
5656 * @var DOMDocument
5757 */
5858 private $doc;
 59+ private $mainPage;
5960
6061 public static $messages = array();
6162
@@ -79,6 +80,7 @@
8081 public static $useFormat;
8182 public static $disableImages;
8283 public static $enableImages;
 84+ public static $isMainPage = false;
8385
8486 public $itemsToRemove = array(
8587 '#contentSub', # redirection notice
@@ -158,6 +160,8 @@
159161 self::$messages['mobile-frontend-wml-continue'] = wfMsg( 'mobile-frontend-wml-continue' );
160162 self::$messages['mobile-frontend-wml-back'] = wfMsg( 'mobile-frontend-wml-back' );
161163 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' );
162166
163167 self::$dir = $wgContLang->getDir();
164168 self::$code = $wgContLang->getCode();
@@ -176,6 +180,11 @@
177181
178182 // The title
179183 self::$title = $out->getTitle();
 184+
 185+ if ( $out->getTitle()->isMainPage() ) {
 186+ self::$isMainPage = true;
 187+ }
 188+
180189 self::$htmlTitle = $out->getHTMLTitle();
181190
182191 $userAgent = $_SERVER['HTTP_USER_AGENT'];
@@ -328,7 +337,8 @@
329338 if (self::$useFormat === 'mobile' ||
330339 self::$useFormat === 'mobile-wap' ||
331340 !empty( $xDevice ) ) {
332 - if ( $action !== 'edit' ) {
 341+ if ( $action !== 'edit' &&
 342+ $mAction !== 'view_normal_site' ) {
333343 $this->getMsg();
334344 $this->disableCaching();
335345 ob_start( array( $this, 'DOMParse' ) );
@@ -567,7 +577,40 @@
568578
569579 return $itemToRemoveRecords;
570580 }
 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' );
571594
 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+
572615 public function DOMParse( $html ) {
573616 global $wgSitename;
574617
@@ -664,6 +707,10 @@
665708 $content = $this->doc->getElementById( 'content' );
666709
667710 $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG );
 711+
 712+ if ( self::$isMainPage ) {
 713+ $contentHtml = $this->DOMParseMainPage( $contentHtml );
 714+ }
668715
669716 $dir = self::$dir;
670717 $code = self::$code;

Follow-up revisions

RevisionCommit summaryAuthorDate
r94565mft r94564preilly20:55, 15 August 2011
r94668fix for r94564preilly17:51, 16 August 2011

Comments

#Comment by Nikerabbit (talk | contribs)   11:24, 16 August 2011

Why is there both $mAction and $action, which are both set to the same and never changed? Besides m prefix refers to member variables.

#Comment by Preilly (talk | contribs)   17:07, 16 August 2011

$mAction and $action are not set to the same thing. I was using the m prefix to refer to mobile.

#Comment by Nikerabbit (talk | contribs)   17:21, 16 August 2011

Right, I misread the code. Still, m prefix is a bit confusing.

#Comment by Preilly (talk | contribs)   17:22, 16 August 2011

I understand I'll work on getting that changed.

#Comment by Preilly (talk | contribs)   17:53, 16 August 2011

This should be fixed now in r94668.

Status & tagging log