r94565 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94564‎ | r94565 | r94566 >
Date:20:55, 15 August 2011
Author:preilly
Status:ok
Tags:
Comment:
mft r94564
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.i18n.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/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: branches/wmf/1.17wmf1/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'];
@@ -214,26 +223,26 @@
215224 $action = $wgRequest->getText( 'action' );
216225 self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
217226 self::$enableImages = $wgRequest->getText( 'enableImages', 0 );
218 -
 227+
219228 if ( self::$disableImages == 1 ) {
220229 $wgRequest->response()->setcookie( 'disableImages', 1 );
221230 }
222 -
 231+
223232 if ( self::$disableImages == 0 ) {
224233 $disableImages = $wgRequest->getCookie( 'disableImages' );
225234 if ( $disableImages ) {
226235 self::$disableImages = $disableImages;
227236 }
228237 }
229 -
 238+
230239 if ( self::$enableImages == 1 ) {
231240 $disableImages = $wgRequest->getCookie( 'disableImages' );
232241 if ( $disableImages ) {
233242 $wgRequest->response()->setcookie( 'disableImages', '' );
234243 }
235244 }
236 -
237 -
 245+
 246+
238247 self::$useFormat = $wgRequest->getText( 'useFormat' );
239248 self::$format = $wgRequest->getText( 'format' );
240249 self::$requestedSegment = $wgRequest->getText( 'seg', 0 );
@@ -261,28 +270,28 @@
262271 exit();
263272 }
264273 }
265 -
 274+
266275 if ( $mAction == 'opt_in_mobile_site' ) {
267276 if ( $this->contentFormat == 'XHTML' ) {
268277 echo $this->renderOptInMobileSiteXHTML();
269278 exit();
270279 }
271280 }
272 -
 281+
273282 if ( $mAction == 'opt_out_mobile_site' ) {
274283 if ( $this->contentFormat == 'XHTML' ) {
275284 echo $this->renderOptOutMobileSiteXHTML();
276285 exit();
277286 }
278287 }
279 -
 288+
280289 if ( $mAction == 'opt_in_cookie' ) {
281290 $this->setOptInOutCookie( '1' );
282291 $this->disableCaching();
283292 $location = Title::newMainPage()->getFullURL();
284293 header( 'Location: ' . $location );
285294 }
286 -
 295+
287296 if ( $mAction == 'opt_out_cookie' ) {
288297 $this->setOptInOutCookie( '' );
289298 }
@@ -322,13 +331,14 @@
323332 // html_preferred_dtd
324333
325334 // Determine
326 -
 335+
327336 $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : '';
328337
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' ) );
@@ -337,7 +347,7 @@
338348
339349 return true;
340350 }
341 -
 351+
342352 private function setOptInOutCookie( $value ) {
343353 global $wgCookieDomain, $wgRequest;
344354 $tempWgCookieDomain = $wgCookieDomain;
@@ -345,13 +355,13 @@
346356 $wgRequest->response()->setcookie( 'optin', $value );
347357 $wgCookieDomain = $tempWgCookieDomain;
348358 }
349 -
 359+
350360 private function getBaseDomain() {
351361 //Validates value as IP address
352362 if( !filter_var( $_SERVER['HTTP_HOST'], FILTER_VALIDATE_IP ) ) {
353363 $domainParts = explode( '.', $_SERVER['HTTP_HOST'] );
354364 $domainParts = array_reverse( $domainParts );
355 - //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included.
 365+ //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included.
356366 return '.' . $domainParts[1] . '.' . $domainParts[0];
357367 } else {
358368 return $_SERVER['HTTP_HOST'];
@@ -366,59 +376,59 @@
367377 header( 'Pragma: no-cache' );
368378 }
369379 }
370 -
 380+
371381 private function renderOptInMobileSiteXHTML() {
372382 if ( $this->contentFormat == 'XHTML' ) {
373 - $this->getMsg();
374 - $dir = self::$dir;
375 - $code = self::$code;
376 - $regularSite = self::$messages['mobile-frontend-regular-site'];
377 - $permStopRedirect = self::$messages['mobile-frontend-perm-stop-redirect'];
378 - $copyright = self::$messages['mobile-frontend-copyright'];
379 - $homeButton = self::$messages['mobile-frontend-home-button'];
380 - $randomButton = self::$messages['mobile-frontend-random-button'];
381 - $yesButton = self::$messages['mobile-frontend-opt-in-yes-button'];
382 - $noButton = self::$messages['mobile-frontend-opt-in-no-button'];
383 - $htmlTitle = self::$messages['mobile-frontend-opt-in-title'];
384 - $explainOptIn = self::$messages['mobile-frontend-opt-in-explain'];
385 - $disableImages = self::$messages['mobile-frontend-disable-images'];
386 - $enableImages = self::$messages['mobile-frontend-enable-images'];
387 - $optInMessage = self::$messages['mobile-frontend-opt-in-message'];
388 - $cssFileName = ( isset( self::$device['css_file_name'] ) ) ? self::$device['css_file_name'] : 'default';
389 - require( 'views/layout/_search_webkit.html.php' );
390 - require( 'views/layout/_footmenu_default.html.php' );
391 - require( 'views/information/optin.html.php' );
392 - $contentHtml = $optInHtml;
393 - require( 'views/layout/application.html.php' );
394 - return $applicationHtml;
 383+ $this->getMsg();
 384+ $dir = self::$dir;
 385+ $code = self::$code;
 386+ $regularSite = self::$messages['mobile-frontend-regular-site'];
 387+ $permStopRedirect = self::$messages['mobile-frontend-perm-stop-redirect'];
 388+ $copyright = self::$messages['mobile-frontend-copyright'];
 389+ $homeButton = self::$messages['mobile-frontend-home-button'];
 390+ $randomButton = self::$messages['mobile-frontend-random-button'];
 391+ $yesButton = self::$messages['mobile-frontend-opt-in-yes-button'];
 392+ $noButton = self::$messages['mobile-frontend-opt-in-no-button'];
 393+ $htmlTitle = self::$messages['mobile-frontend-opt-in-title'];
 394+ $explainOptIn = self::$messages['mobile-frontend-opt-in-explain'];
 395+ $disableImages = self::$messages['mobile-frontend-disable-images'];
 396+ $enableImages = self::$messages['mobile-frontend-enable-images'];
 397+ $optInMessage = self::$messages['mobile-frontend-opt-in-message'];
 398+ $cssFileName = ( isset( self::$device['css_file_name'] ) ) ? self::$device['css_file_name'] : 'default';
 399+ require( 'views/layout/_search_webkit.html.php' );
 400+ require( 'views/layout/_footmenu_default.html.php' );
 401+ require( 'views/information/optin.html.php' );
 402+ $contentHtml = $optInHtml;
 403+ require( 'views/layout/application.html.php' );
 404+ return $applicationHtml;
395405 }
396406 return '';
397407 }
398 -
 408+
399409 private function renderOptOutMobileSiteXHTML() {
400410 if ( $this->contentFormat == 'XHTML' ) {
401 - $this->getMsg();
402 - $dir = self::$dir;
403 - $code = self::$code;
404 - $regularSite = self::$messages['mobile-frontend-regular-site'];
405 - $permStopRedirect = self::$messages['mobile-frontend-perm-stop-redirect'];
406 - $copyright = self::$messages['mobile-frontend-copyright'];
407 - $homeButton = self::$messages['mobile-frontend-home-button'];
408 - $randomButton = self::$messages['mobile-frontend-random-button'];
409 - $yesButton = self::$messages['mobile-frontend-opt-out-yes-button'];
410 - $noButton = self::$messages['mobile-frontend-opt-out-no-button'];
411 - $htmlTitle = self::$messages['mobile-frontend-opt-out-title'];
412 - $explainOptOut = self::$messages['mobile-frontend-opt-out-explain'];
413 - $optOutMessage = self::$messages['mobile-frontend-opt-out-message'];
414 - $disableImages = self::$messages['mobile-frontend-disable-images'];
415 - $enableImages = self::$messages['mobile-frontend-enable-images'];
416 - $cssFileName = ( isset( self::$device['css_file_name'] ) ) ? self::$device['css_file_name'] : 'default';
417 - require( 'views/layout/_search_webkit.html.php' );
418 - require( 'views/layout/_footmenu_default.html.php' );
419 - require( 'views/information/optout.html.php' );
420 - $contentHtml = $optOutHtml;
421 - require( 'views/layout/application.html.php' );
422 - return $applicationHtml;
 411+ $this->getMsg();
 412+ $dir = self::$dir;
 413+ $code = self::$code;
 414+ $regularSite = self::$messages['mobile-frontend-regular-site'];
 415+ $permStopRedirect = self::$messages['mobile-frontend-perm-stop-redirect'];
 416+ $copyright = self::$messages['mobile-frontend-copyright'];
 417+ $homeButton = self::$messages['mobile-frontend-home-button'];
 418+ $randomButton = self::$messages['mobile-frontend-random-button'];
 419+ $yesButton = self::$messages['mobile-frontend-opt-out-yes-button'];
 420+ $noButton = self::$messages['mobile-frontend-opt-out-no-button'];
 421+ $htmlTitle = self::$messages['mobile-frontend-opt-out-title'];
 422+ $explainOptOut = self::$messages['mobile-frontend-opt-out-explain'];
 423+ $optOutMessage = self::$messages['mobile-frontend-opt-out-message'];
 424+ $disableImages = self::$messages['mobile-frontend-disable-images'];
 425+ $enableImages = self::$messages['mobile-frontend-enable-images'];
 426+ $cssFileName = ( isset( self::$device['css_file_name'] ) ) ? self::$device['css_file_name'] : 'default';
 427+ require( 'views/layout/_search_webkit.html.php' );
 428+ require( 'views/layout/_footmenu_default.html.php' );
 429+ require( 'views/information/optout.html.php' );
 430+ $contentHtml = $optOutHtml;
 431+ require( 'views/layout/application.html.php' );
 432+ return $applicationHtml;
423433 }
424434 return '';
425435 }
@@ -455,8 +465,8 @@
456466 private function headingTransformCallbackWML( $matches ) {
457467 static $headings = 0;
458468 ++$headings;
459 -
460 - $base = $this->WMLSectionSeperator .
 469+
 470+ $base = $this->WMLSectionSeperator .
461471 "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>";
462472
463473 self::$headings = $headings;
@@ -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;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94564add support to render the main page content in a sane waypreilly20:53, 15 August 2011

Status & tagging log