r95549 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95548‎ | r95549 | r95550 >
Date:00:41, 26 August 2011
Author:preilly
Status:ok
Tags:
Comment:
mft r95548
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
@@ -139,18 +139,20 @@
140140
141141 public function addMobileFooter( &$obj, &$tpl ) {
142142 global $wgRequest;
 143+ wfProfileIn( __METHOD__ );
143144 $footerlinks = $tpl->data['footerlinks'];
144145 $mobileViewUrl = $wgRequest->escapeAppendQuery( 'useformat=mobile' );
145146
146147 $tpl->set('mobileview', "<a href='{$mobileViewUrl}'>".wfMsg( 'mobile-frontend-view')."</a>");
147148 $footerlinks['places'][] = 'mobileview';
148149 $tpl->set('footerlinks', $footerlinks);
149 -
 150+ wfProfileOut( __METHOD__ );
150151 return true;
151152 }
152153
153154 public function getMsg() {
154155 global $wgUser, $wgContLang, $wgRequest;
 156+ wfProfileIn( __METHOD__ );
155157
156158 self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' );
157159 self::$enableImagesURL = $wgRequest->escapeAppendQuery( 'enableImages=1' );
@@ -196,6 +198,7 @@
197199
198200 self::$mainPageUrl = Title::newMainPage()->getLocalUrl();
199201 self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl();
 202+ wfProfileOut( __METHOD__ );
200203 }
201204
202205 /**
@@ -205,7 +208,7 @@
206209 */
207210 public function beforePageDisplayHTML( &$out, &$text ) {
208211 global $wgContLang, $wgRequest, $wgMemc, $wgUser;
209 -
 212+ wfProfileIn( __METHOD__ );
210213 // The title
211214 self::$title = $out->getTitle();
212215
@@ -300,6 +303,7 @@
301304 if ( $mobileAction == 'disable_mobile_site' ) {
302305 if ( $this->contentFormat == 'XHTML' ) {
303306 echo $this->renderDisableMobileSiteXHTML();
 307+ wfProfileOut( __METHOD__ );
304308 exit();
305309 }
306310 }
@@ -307,6 +311,7 @@
308312 if ( $mobileAction == 'opt_in_mobile_site' ) {
309313 if ( $this->contentFormat == 'XHTML' ) {
310314 echo $this->renderOptInMobileSiteXHTML();
 315+ wfProfileOut( __METHOD__ );
311316 exit();
312317 }
313318 }
@@ -314,6 +319,7 @@
315320 if ( $mobileAction == 'opt_out_mobile_site' ) {
316321 if ( $this->contentFormat == 'XHTML' ) {
317322 echo $this->renderOptOutMobileSiteXHTML();
 323+ wfProfileOut( __METHOD__ );
318324 exit();
319325 }
320326 }
@@ -366,49 +372,59 @@
367373 }
368374 }
369375
 376+ wfProfileOut( __METHOD__ );
370377 return true;
371378 }
372379
373380 private function setOptInOutCookie( $value ) {
374381 global $wgCookieDomain, $wgRequest;
 382+ wfProfileIn( __METHOD__ );
375383 $tempWgCookieDomain = $wgCookieDomain;
376384 $wgCookieDomain = $this->getBaseDomain();
377385 $wgRequest->response()->setcookie( 'optin', $value );
378386 $wgCookieDomain = $tempWgCookieDomain;
 387+ wfProfileOut( __METHOD__ );
379388 }
380389
381390 private function getBaseDomain() {
 391+ wfProfileIn( __METHOD__ );
382392 //Validates value as IP address
383393 if( !IP::isValid( $_SERVER['HTTP_HOST'] ) ) {
384394 $domainParts = explode( '.', $_SERVER['HTTP_HOST'] );
385395 $domainParts = array_reverse( $domainParts );
386396 //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included.
 397+ wfProfileOut( __METHOD__ );
387398 return '.' . $domainParts[1] . '.' . $domainParts[0];
388399 } else {
 400+ wfProfileOut( __METHOD__ );
389401 return $_SERVER['HTTP_HOST'];
390402 }
391403 }
392404
393405 private function disableCaching() {
394406 global $wgRequest;
 407+ wfProfileIn( __METHOD__ );
395408 if ( isset( $_SERVER['HTTP_VIA'] ) &&
396409 stripos( $_SERVER['HTTP_VIA'], '.wikimedia.org:3128' ) !== false ) {
397410 $wgRequest->response()->header( 'Cache-Control: no-cache, must-revalidate' );
398411 $wgRequest->response()->header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
399412 $wgRequest->response()->header( 'Pragma: no-cache' );
400413 }
 414+ wfProfileOut( __METHOD__ );
401415 }
402416
403417 private function sendXDeviceVaryHeader() {
404418 global $wgOut, $wgRequest;
405 -
 419+ wfProfileIn( __METHOD__ );
406420 if ( !empty( $_SERVER['HTTP_X_DEVICE'] ) ) {
407421 $wgRequest->response()->header( 'X-Device: ' . $_SERVER['HTTP_X_DEVICE'] );
408422 $wgOut->addVaryHeader( 'X-Device' );
409423 }
 424+ wfProfileOut( __METHOD__ );
410425 }
411426
412427 private function renderOptInMobileSiteXHTML() {
 428+ wfProfileIn( __METHOD__ );
413429 if ( $this->contentFormat == 'XHTML' ) {
414430 $this->getMsg();
415431 $yesButton = self::$messages['mobile-frontend-opt-in-yes-button'];
@@ -421,12 +437,15 @@
422438 require( 'views/information/optin.html.php' );
423439 $contentHtml = $optInHtml;
424440 require( 'views/layout/application.html.php' );
 441+ wfProfileOut( __METHOD__ );
425442 return $applicationHtml;
426443 }
 444+ wfProfileOut( __METHOD__ );
427445 return '';
428446 }
429447
430448 private function renderOptOutMobileSiteXHTML() {
 449+ wfProfileIn( __METHOD__ );
431450 if ( $this->contentFormat == 'XHTML' ) {
432451 $this->getMsg();
433452 $yesButton = self::$messages['mobile-frontend-opt-out-yes-button'];
@@ -439,12 +458,15 @@
440459 require( 'views/information/optout.html.php' );
441460 $contentHtml = $optOutHtml;
442461 require( 'views/layout/application.html.php' );
 462+ wfProfileOut( __METHOD__ );
443463 return $applicationHtml;
444464 }
 465+ wfProfileOut( __METHOD__ );
445466 return '';
446467 }
447468
448469 private function renderDisableMobileSiteXHTML() {
 470+ wfProfileIn( __METHOD__ );
449471 if ( $this->contentFormat == 'XHTML' ) {
450472 $this->getMsg();
451473 $areYouSure = self::$messages['mobile-frontend-are-you-sure'];
@@ -458,12 +480,15 @@
459481 require( 'views/information/disable.html.php' );
460482 $contentHtml = $disableHtml;
461483 require( 'views/layout/application.html.php' );
 484+ wfProfileOut( __METHOD__ );
462485 return $applicationHtml;
463486 }
 487+ wfProfileOut( __METHOD__ );
464488 return '';
465489 }
466490
467491 private function headingTransformCallbackWML( $matches ) {
 492+ wfProfileIn( __METHOD__ );
468493 static $headings = 0;
469494 ++$headings;
470495
@@ -471,12 +496,12 @@
472497 "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>";
473498
474499 self::$headings = $headings;
475 -
 500+ wfProfileOut( __METHOD__ );
476501 return $base;
477502 }
478503
479504 private function headingTransformCallbackXHTML( $matches ) {
480 -
 505+ wfProfileIn( __METHOD__ );
481506 if ( isset( $matches[0] ) ) {
482507 preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches);
483508 }
@@ -504,7 +529,7 @@
505530 }
506531
507532 self::$headings = $headings;
508 -
 533+ wfProfileOut( __METHOD__ );
509534 return $base;
510535 }
511536
@@ -513,6 +538,7 @@
514539 * @return string
515540 */
516541 public function headingTransform( $s ) {
 542+ wfProfileIn( __METHOD__ );
517543 $callback = 'headingTransformCallback';
518544 $callback .= $this->contentFormat;
519545
@@ -533,11 +559,12 @@
534560 $s
535561 );
536562 }
537 -
 563+ wfProfileOut( __METHOD__ );
538564 return $s;
539565 }
540566
541567 private function createWMLCard( $s ) {
 568+ wfProfileIn( __METHOD__ );
542569 $segments = explode( $this->WMLSectionSeperator, $s );
543570 $card = '';
544571 $idx = 0;
@@ -563,11 +590,13 @@
564591 }
565592
566593 $card .= '</card>';
 594+ wfProfileOut( __METHOD__ );
567595 return $card;
568596 }
569597
570598 private function parseItemsToRemove() {
571599 global $wgMFRemovableClasses;
 600+ wfProfileIn( __METHOD__ );
572601 $itemToRemoveRecords = array();
573602
574603 foreach ( array_merge( $this->itemsToRemove, $wgMFRemovableClasses )
@@ -578,11 +607,13 @@
579608 CssDetection::detectIdCssOrTag( $itemToRemove, $type, $rawName );
580609 $itemToRemoveRecords[$type][] = $rawName;
581610 }
582 -
 611+
 612+ wfProfileOut( __METHOD__ );
583613 return $itemToRemoveRecords;
584614 }
585615
586616 public function DOMParseMainPage( $html ) {
 617+ wfProfileIn( __METHOD__ );
587618 $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
588619 libxml_use_internal_errors( true );
589620 $this->mainPage = new DOMDocument();
@@ -613,13 +644,13 @@
614645 }
615646
616647 $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG );
617 -
 648+ wfProfileOut( __METHOD__ );
618649 return $contentHtml;
619650 }
620651
621652 public function DOMParse( $html ) {
622653 global $wgSitename;
623 -
 654+ wfProfileIn( __METHOD__ );
624655 $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
625656 libxml_use_internal_errors( true );
626657 $this->doc = new DOMDocument();
@@ -759,15 +790,17 @@
760791 $json_data['title'] = self::$title->getText();
761792 $json_data['html'] = $contentHtml;
762793
763 - $json = json_encode( $json_data );
 794+ $json = FormatJson::encode( $json_data );
764795
765796 if ( !empty( self::$callback ) ) {
766797 $json = urlencode( self::$callback ) . '(' . $json . ')';
767798 }
768799
 800+ wfProfileOut( __METHOD__ );
769801 return $json;
770802 }
771 -
 803+
 804+ wfProfileOut( __METHOD__ );
772805 return $applicationHtml;
773806 }
774807
@@ -776,8 +809,10 @@
777810 */
778811 public function setDefaultLogo() {
779812 global $wgMobileFrontendLogo, $wgExtensionAssetsPath;
 813+ wfProfileIn( __METHOD__ );
780814 if ( $wgMobileFrontendLogo === false ) {
781815 $wgMobileFrontendLogo = $wgExtensionAssetsPath . '/MobileFrontend/stylesheets/images/mw.png';
782816 }
 817+ wfProfileOut( __METHOD__ );
783818 }
784819 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r955851.17wmf1: Revert r95549, was never deployed and I want to have the branch cle...catrope23:42, 26 August 2011
r95795mft r95549 through r95794preilly17:22, 30 August 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95548bug 30577 - re-add profiling into MobileFrontendpreilly00:38, 26 August 2011

Status & tagging log