r95585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95584‎ | r95585 | r95586 >
Date:23:42, 26 August 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: Revert r95549, was never deployed and I want to have the branch clean for the weekend
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
@@ -139,20 +139,18 @@
140140
141141 public function addMobileFooter( &$obj, &$tpl ) {
142142 global $wgRequest;
143 - wfProfileIn( __METHOD__ );
144143 $footerlinks = $tpl->data['footerlinks'];
145144 $mobileViewUrl = $wgRequest->escapeAppendQuery( 'useformat=mobile' );
146145
147146 $tpl->set('mobileview', "<a href='{$mobileViewUrl}'>".wfMsg( 'mobile-frontend-view')."</a>");
148147 $footerlinks['places'][] = 'mobileview';
149148 $tpl->set('footerlinks', $footerlinks);
150 - wfProfileOut( __METHOD__ );
 149+
151150 return true;
152151 }
153152
154153 public function getMsg() {
155154 global $wgUser, $wgContLang, $wgRequest;
156 - wfProfileIn( __METHOD__ );
157155
158156 self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' );
159157 self::$enableImagesURL = $wgRequest->escapeAppendQuery( 'enableImages=1' );
@@ -198,7 +196,6 @@
199197
200198 self::$mainPageUrl = Title::newMainPage()->getLocalUrl();
201199 self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl();
202 - wfProfileOut( __METHOD__ );
203200 }
204201
205202 /**
@@ -208,7 +205,7 @@
209206 */
210207 public function beforePageDisplayHTML( &$out, &$text ) {
211208 global $wgContLang, $wgRequest, $wgMemc, $wgUser;
212 - wfProfileIn( __METHOD__ );
 209+
213210 // The title
214211 self::$title = $out->getTitle();
215212
@@ -303,7 +300,6 @@
304301 if ( $mobileAction == 'disable_mobile_site' ) {
305302 if ( $this->contentFormat == 'XHTML' ) {
306303 echo $this->renderDisableMobileSiteXHTML();
307 - wfProfileOut( __METHOD__ );
308304 exit();
309305 }
310306 }
@@ -311,7 +307,6 @@
312308 if ( $mobileAction == 'opt_in_mobile_site' ) {
313309 if ( $this->contentFormat == 'XHTML' ) {
314310 echo $this->renderOptInMobileSiteXHTML();
315 - wfProfileOut( __METHOD__ );
316311 exit();
317312 }
318313 }
@@ -319,7 +314,6 @@
320315 if ( $mobileAction == 'opt_out_mobile_site' ) {
321316 if ( $this->contentFormat == 'XHTML' ) {
322317 echo $this->renderOptOutMobileSiteXHTML();
323 - wfProfileOut( __METHOD__ );
324318 exit();
325319 }
326320 }
@@ -372,59 +366,49 @@
373367 }
374368 }
375369
376 - wfProfileOut( __METHOD__ );
377370 return true;
378371 }
379372
380373 private function setOptInOutCookie( $value ) {
381374 global $wgCookieDomain, $wgRequest;
382 - wfProfileIn( __METHOD__ );
383375 $tempWgCookieDomain = $wgCookieDomain;
384376 $wgCookieDomain = $this->getBaseDomain();
385377 $wgRequest->response()->setcookie( 'optin', $value );
386378 $wgCookieDomain = $tempWgCookieDomain;
387 - wfProfileOut( __METHOD__ );
388379 }
389380
390381 private function getBaseDomain() {
391 - wfProfileIn( __METHOD__ );
392382 //Validates value as IP address
393383 if( !IP::isValid( $_SERVER['HTTP_HOST'] ) ) {
394384 $domainParts = explode( '.', $_SERVER['HTTP_HOST'] );
395385 $domainParts = array_reverse( $domainParts );
396386 //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included.
397 - wfProfileOut( __METHOD__ );
398387 return '.' . $domainParts[1] . '.' . $domainParts[0];
399388 } else {
400 - wfProfileOut( __METHOD__ );
401389 return $_SERVER['HTTP_HOST'];
402390 }
403391 }
404392
405393 private function disableCaching() {
406394 global $wgRequest;
407 - wfProfileIn( __METHOD__ );
408395 if ( isset( $_SERVER['HTTP_VIA'] ) &&
409396 stripos( $_SERVER['HTTP_VIA'], '.wikimedia.org:3128' ) !== false ) {
410397 $wgRequest->response()->header( 'Cache-Control: no-cache, must-revalidate' );
411398 $wgRequest->response()->header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
412399 $wgRequest->response()->header( 'Pragma: no-cache' );
413400 }
414 - wfProfileOut( __METHOD__ );
415401 }
416402
417403 private function sendXDeviceVaryHeader() {
418404 global $wgOut, $wgRequest;
419 - wfProfileIn( __METHOD__ );
 405+
420406 if ( !empty( $_SERVER['HTTP_X_DEVICE'] ) ) {
421407 $wgRequest->response()->header( 'X-Device: ' . $_SERVER['HTTP_X_DEVICE'] );
422408 $wgOut->addVaryHeader( 'X-Device' );
423409 }
424 - wfProfileOut( __METHOD__ );
425410 }
426411
427412 private function renderOptInMobileSiteXHTML() {
428 - wfProfileIn( __METHOD__ );
429413 if ( $this->contentFormat == 'XHTML' ) {
430414 $this->getMsg();
431415 $yesButton = self::$messages['mobile-frontend-opt-in-yes-button'];
@@ -437,15 +421,12 @@
438422 require( 'views/information/optin.html.php' );
439423 $contentHtml = $optInHtml;
440424 require( 'views/layout/application.html.php' );
441 - wfProfileOut( __METHOD__ );
442425 return $applicationHtml;
443426 }
444 - wfProfileOut( __METHOD__ );
445427 return '';
446428 }
447429
448430 private function renderOptOutMobileSiteXHTML() {
449 - wfProfileIn( __METHOD__ );
450431 if ( $this->contentFormat == 'XHTML' ) {
451432 $this->getMsg();
452433 $yesButton = self::$messages['mobile-frontend-opt-out-yes-button'];
@@ -458,15 +439,12 @@
459440 require( 'views/information/optout.html.php' );
460441 $contentHtml = $optOutHtml;
461442 require( 'views/layout/application.html.php' );
462 - wfProfileOut( __METHOD__ );
463443 return $applicationHtml;
464444 }
465 - wfProfileOut( __METHOD__ );
466445 return '';
467446 }
468447
469448 private function renderDisableMobileSiteXHTML() {
470 - wfProfileIn( __METHOD__ );
471449 if ( $this->contentFormat == 'XHTML' ) {
472450 $this->getMsg();
473451 $areYouSure = self::$messages['mobile-frontend-are-you-sure'];
@@ -480,15 +458,12 @@
481459 require( 'views/information/disable.html.php' );
482460 $contentHtml = $disableHtml;
483461 require( 'views/layout/application.html.php' );
484 - wfProfileOut( __METHOD__ );
485462 return $applicationHtml;
486463 }
487 - wfProfileOut( __METHOD__ );
488464 return '';
489465 }
490466
491467 private function headingTransformCallbackWML( $matches ) {
492 - wfProfileIn( __METHOD__ );
493468 static $headings = 0;
494469 ++$headings;
495470
@@ -496,12 +471,12 @@
497472 "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>";
498473
499474 self::$headings = $headings;
500 - wfProfileOut( __METHOD__ );
 475+
501476 return $base;
502477 }
503478
504479 private function headingTransformCallbackXHTML( $matches ) {
505 - wfProfileIn( __METHOD__ );
 480+
506481 if ( isset( $matches[0] ) ) {
507482 preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches);
508483 }
@@ -529,7 +504,7 @@
530505 }
531506
532507 self::$headings = $headings;
533 - wfProfileOut( __METHOD__ );
 508+
534509 return $base;
535510 }
536511
@@ -538,7 +513,6 @@
539514 * @return string
540515 */
541516 public function headingTransform( $s ) {
542 - wfProfileIn( __METHOD__ );
543517 $callback = 'headingTransformCallback';
544518 $callback .= $this->contentFormat;
545519
@@ -559,12 +533,11 @@
560534 $s
561535 );
562536 }
563 - wfProfileOut( __METHOD__ );
 537+
564538 return $s;
565539 }
566540
567541 private function createWMLCard( $s ) {
568 - wfProfileIn( __METHOD__ );
569542 $segments = explode( $this->WMLSectionSeperator, $s );
570543 $card = '';
571544 $idx = 0;
@@ -590,13 +563,11 @@
591564 }
592565
593566 $card .= '</card>';
594 - wfProfileOut( __METHOD__ );
595567 return $card;
596568 }
597569
598570 private function parseItemsToRemove() {
599571 global $wgMFRemovableClasses;
600 - wfProfileIn( __METHOD__ );
601572 $itemToRemoveRecords = array();
602573
603574 foreach ( array_merge( $this->itemsToRemove, $wgMFRemovableClasses )
@@ -607,13 +578,11 @@
608579 CssDetection::detectIdCssOrTag( $itemToRemove, $type, $rawName );
609580 $itemToRemoveRecords[$type][] = $rawName;
610581 }
611 -
612 - wfProfileOut( __METHOD__ );
 582+
613583 return $itemToRemoveRecords;
614584 }
615585
616586 public function DOMParseMainPage( $html ) {
617 - wfProfileIn( __METHOD__ );
618587 $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
619588 libxml_use_internal_errors( true );
620589 $this->mainPage = new DOMDocument();
@@ -644,13 +613,13 @@
645614 }
646615
647616 $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG );
648 - wfProfileOut( __METHOD__ );
 617+
649618 return $contentHtml;
650619 }
651620
652621 public function DOMParse( $html ) {
653622 global $wgSitename;
654 - wfProfileIn( __METHOD__ );
 623+
655624 $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
656625 libxml_use_internal_errors( true );
657626 $this->doc = new DOMDocument();
@@ -790,17 +759,15 @@
791760 $json_data['title'] = self::$title->getText();
792761 $json_data['html'] = $contentHtml;
793762
794 - $json = FormatJson::encode( $json_data );
 763+ $json = json_encode( $json_data );
795764
796765 if ( !empty( self::$callback ) ) {
797766 $json = urlencode( self::$callback ) . '(' . $json . ')';
798767 }
799768
800 - wfProfileOut( __METHOD__ );
801769 return $json;
802770 }
803 -
804 - wfProfileOut( __METHOD__ );
 771+
805772 return $applicationHtml;
806773 }
807774
@@ -809,10 +776,8 @@
810777 */
811778 public function setDefaultLogo() {
812779 global $wgMobileFrontendLogo, $wgExtensionAssetsPath;
813 - wfProfileIn( __METHOD__ );
814780 if ( $wgMobileFrontendLogo === false ) {
815781 $wgMobileFrontendLogo = $wgExtensionAssetsPath . '/MobileFrontend/stylesheets/images/mw.png';
816782 }
817 - wfProfileOut( __METHOD__ );
818783 }
819784 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95549mft r95548preilly00:41, 26 August 2011

Status & tagging log