Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -139,18 +139,20 @@ |
140 | 140 | |
141 | 141 | public function addMobileFooter( &$obj, &$tpl ) { |
142 | 142 | global $wgRequest; |
| 143 | + wfProfileIn( __METHOD__ ); |
143 | 144 | $footerlinks = $tpl->data['footerlinks']; |
144 | 145 | $mobileViewUrl = $wgRequest->escapeAppendQuery( 'useformat=mobile' ); |
145 | 146 | |
146 | 147 | $tpl->set('mobileview', "<a href='{$mobileViewUrl}'>".wfMsg( 'mobile-frontend-view')."</a>"); |
147 | 148 | $footerlinks['places'][] = 'mobileview'; |
148 | 149 | $tpl->set('footerlinks', $footerlinks); |
149 | | - |
| 150 | + wfProfileOut( __METHOD__ ); |
150 | 151 | return true; |
151 | 152 | } |
152 | 153 | |
153 | 154 | public function getMsg() { |
154 | 155 | global $wgUser, $wgContLang, $wgRequest; |
| 156 | + wfProfileIn( __METHOD__ ); |
155 | 157 | |
156 | 158 | self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' ); |
157 | 159 | self::$enableImagesURL = $wgRequest->escapeAppendQuery( 'enableImages=1' ); |
— | — | @@ -196,6 +198,7 @@ |
197 | 199 | |
198 | 200 | self::$mainPageUrl = Title::newMainPage()->getLocalUrl(); |
199 | 201 | self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl(); |
| 202 | + wfProfileOut( __METHOD__ ); |
200 | 203 | } |
201 | 204 | |
202 | 205 | /** |
— | — | @@ -205,7 +208,7 @@ |
206 | 209 | */ |
207 | 210 | public function beforePageDisplayHTML( &$out, &$text ) { |
208 | 211 | global $wgContLang, $wgRequest, $wgMemc, $wgUser; |
209 | | - |
| 212 | + wfProfileIn( __METHOD__ ); |
210 | 213 | // The title |
211 | 214 | self::$title = $out->getTitle(); |
212 | 215 | |
— | — | @@ -300,6 +303,7 @@ |
301 | 304 | if ( $mobileAction == 'disable_mobile_site' ) { |
302 | 305 | if ( $this->contentFormat == 'XHTML' ) { |
303 | 306 | echo $this->renderDisableMobileSiteXHTML(); |
| 307 | + wfProfileOut( __METHOD__ ); |
304 | 308 | exit(); |
305 | 309 | } |
306 | 310 | } |
— | — | @@ -307,6 +311,7 @@ |
308 | 312 | if ( $mobileAction == 'opt_in_mobile_site' ) { |
309 | 313 | if ( $this->contentFormat == 'XHTML' ) { |
310 | 314 | echo $this->renderOptInMobileSiteXHTML(); |
| 315 | + wfProfileOut( __METHOD__ ); |
311 | 316 | exit(); |
312 | 317 | } |
313 | 318 | } |
— | — | @@ -314,6 +319,7 @@ |
315 | 320 | if ( $mobileAction == 'opt_out_mobile_site' ) { |
316 | 321 | if ( $this->contentFormat == 'XHTML' ) { |
317 | 322 | echo $this->renderOptOutMobileSiteXHTML(); |
| 323 | + wfProfileOut( __METHOD__ ); |
318 | 324 | exit(); |
319 | 325 | } |
320 | 326 | } |
— | — | @@ -366,49 +372,59 @@ |
367 | 373 | } |
368 | 374 | } |
369 | 375 | |
| 376 | + wfProfileOut( __METHOD__ ); |
370 | 377 | return true; |
371 | 378 | } |
372 | 379 | |
373 | 380 | private function setOptInOutCookie( $value ) { |
374 | 381 | global $wgCookieDomain, $wgRequest; |
| 382 | + wfProfileIn( __METHOD__ ); |
375 | 383 | $tempWgCookieDomain = $wgCookieDomain; |
376 | 384 | $wgCookieDomain = $this->getBaseDomain(); |
377 | 385 | $wgRequest->response()->setcookie( 'optin', $value ); |
378 | 386 | $wgCookieDomain = $tempWgCookieDomain; |
| 387 | + wfProfileOut( __METHOD__ ); |
379 | 388 | } |
380 | 389 | |
381 | 390 | private function getBaseDomain() { |
| 391 | + wfProfileIn( __METHOD__ ); |
382 | 392 | //Validates value as IP address |
383 | 393 | if( !IP::isValid( $_SERVER['HTTP_HOST'] ) ) { |
384 | 394 | $domainParts = explode( '.', $_SERVER['HTTP_HOST'] ); |
385 | 395 | $domainParts = array_reverse( $domainParts ); |
386 | 396 | //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included. |
| 397 | + wfProfileOut( __METHOD__ ); |
387 | 398 | return '.' . $domainParts[1] . '.' . $domainParts[0]; |
388 | 399 | } else { |
| 400 | + wfProfileOut( __METHOD__ ); |
389 | 401 | return $_SERVER['HTTP_HOST']; |
390 | 402 | } |
391 | 403 | } |
392 | 404 | |
393 | 405 | private function disableCaching() { |
394 | 406 | global $wgRequest; |
| 407 | + wfProfileIn( __METHOD__ ); |
395 | 408 | if ( isset( $_SERVER['HTTP_VIA'] ) && |
396 | 409 | stripos( $_SERVER['HTTP_VIA'], '.wikimedia.org:3128' ) !== false ) { |
397 | 410 | $wgRequest->response()->header( 'Cache-Control: no-cache, must-revalidate' ); |
398 | 411 | $wgRequest->response()->header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); |
399 | 412 | $wgRequest->response()->header( 'Pragma: no-cache' ); |
400 | 413 | } |
| 414 | + wfProfileOut( __METHOD__ ); |
401 | 415 | } |
402 | 416 | |
403 | 417 | private function sendXDeviceVaryHeader() { |
404 | 418 | global $wgOut, $wgRequest; |
405 | | - |
| 419 | + wfProfileIn( __METHOD__ ); |
406 | 420 | if ( !empty( $_SERVER['HTTP_X_DEVICE'] ) ) { |
407 | 421 | $wgRequest->response()->header( 'X-Device: ' . $_SERVER['HTTP_X_DEVICE'] ); |
408 | 422 | $wgOut->addVaryHeader( 'X-Device' ); |
409 | 423 | } |
| 424 | + wfProfileOut( __METHOD__ ); |
410 | 425 | } |
411 | 426 | |
412 | 427 | private function renderOptInMobileSiteXHTML() { |
| 428 | + wfProfileIn( __METHOD__ ); |
413 | 429 | if ( $this->contentFormat == 'XHTML' ) { |
414 | 430 | $this->getMsg(); |
415 | 431 | $yesButton = self::$messages['mobile-frontend-opt-in-yes-button']; |
— | — | @@ -421,12 +437,15 @@ |
422 | 438 | require( 'views/information/optin.html.php' ); |
423 | 439 | $contentHtml = $optInHtml; |
424 | 440 | require( 'views/layout/application.html.php' ); |
| 441 | + wfProfileOut( __METHOD__ ); |
425 | 442 | return $applicationHtml; |
426 | 443 | } |
| 444 | + wfProfileOut( __METHOD__ ); |
427 | 445 | return ''; |
428 | 446 | } |
429 | 447 | |
430 | 448 | private function renderOptOutMobileSiteXHTML() { |
| 449 | + wfProfileIn( __METHOD__ ); |
431 | 450 | if ( $this->contentFormat == 'XHTML' ) { |
432 | 451 | $this->getMsg(); |
433 | 452 | $yesButton = self::$messages['mobile-frontend-opt-out-yes-button']; |
— | — | @@ -439,12 +458,15 @@ |
440 | 459 | require( 'views/information/optout.html.php' ); |
441 | 460 | $contentHtml = $optOutHtml; |
442 | 461 | require( 'views/layout/application.html.php' ); |
| 462 | + wfProfileOut( __METHOD__ ); |
443 | 463 | return $applicationHtml; |
444 | 464 | } |
| 465 | + wfProfileOut( __METHOD__ ); |
445 | 466 | return ''; |
446 | 467 | } |
447 | 468 | |
448 | 469 | private function renderDisableMobileSiteXHTML() { |
| 470 | + wfProfileIn( __METHOD__ ); |
449 | 471 | if ( $this->contentFormat == 'XHTML' ) { |
450 | 472 | $this->getMsg(); |
451 | 473 | $areYouSure = self::$messages['mobile-frontend-are-you-sure']; |
— | — | @@ -458,12 +480,15 @@ |
459 | 481 | require( 'views/information/disable.html.php' ); |
460 | 482 | $contentHtml = $disableHtml; |
461 | 483 | require( 'views/layout/application.html.php' ); |
| 484 | + wfProfileOut( __METHOD__ ); |
462 | 485 | return $applicationHtml; |
463 | 486 | } |
| 487 | + wfProfileOut( __METHOD__ ); |
464 | 488 | return ''; |
465 | 489 | } |
466 | 490 | |
467 | 491 | private function headingTransformCallbackWML( $matches ) { |
| 492 | + wfProfileIn( __METHOD__ ); |
468 | 493 | static $headings = 0; |
469 | 494 | ++$headings; |
470 | 495 | |
— | — | @@ -471,12 +496,12 @@ |
472 | 497 | "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>"; |
473 | 498 | |
474 | 499 | self::$headings = $headings; |
475 | | - |
| 500 | + wfProfileOut( __METHOD__ ); |
476 | 501 | return $base; |
477 | 502 | } |
478 | 503 | |
479 | 504 | private function headingTransformCallbackXHTML( $matches ) { |
480 | | - |
| 505 | + wfProfileIn( __METHOD__ ); |
481 | 506 | if ( isset( $matches[0] ) ) { |
482 | 507 | preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches); |
483 | 508 | } |
— | — | @@ -504,7 +529,7 @@ |
505 | 530 | } |
506 | 531 | |
507 | 532 | self::$headings = $headings; |
508 | | - |
| 533 | + wfProfileOut( __METHOD__ ); |
509 | 534 | return $base; |
510 | 535 | } |
511 | 536 | |
— | — | @@ -513,6 +538,7 @@ |
514 | 539 | * @return string |
515 | 540 | */ |
516 | 541 | public function headingTransform( $s ) { |
| 542 | + wfProfileIn( __METHOD__ ); |
517 | 543 | $callback = 'headingTransformCallback'; |
518 | 544 | $callback .= $this->contentFormat; |
519 | 545 | |
— | — | @@ -533,11 +559,12 @@ |
534 | 560 | $s |
535 | 561 | ); |
536 | 562 | } |
537 | | - |
| 563 | + wfProfileOut( __METHOD__ ); |
538 | 564 | return $s; |
539 | 565 | } |
540 | 566 | |
541 | 567 | private function createWMLCard( $s ) { |
| 568 | + wfProfileIn( __METHOD__ ); |
542 | 569 | $segments = explode( $this->WMLSectionSeperator, $s ); |
543 | 570 | $card = ''; |
544 | 571 | $idx = 0; |
— | — | @@ -563,11 +590,13 @@ |
564 | 591 | } |
565 | 592 | |
566 | 593 | $card .= '</card>'; |
| 594 | + wfProfileOut( __METHOD__ ); |
567 | 595 | return $card; |
568 | 596 | } |
569 | 597 | |
570 | 598 | private function parseItemsToRemove() { |
571 | 599 | global $wgMFRemovableClasses; |
| 600 | + wfProfileIn( __METHOD__ ); |
572 | 601 | $itemToRemoveRecords = array(); |
573 | 602 | |
574 | 603 | foreach ( array_merge( $this->itemsToRemove, $wgMFRemovableClasses ) |
— | — | @@ -578,11 +607,13 @@ |
579 | 608 | CssDetection::detectIdCssOrTag( $itemToRemove, $type, $rawName ); |
580 | 609 | $itemToRemoveRecords[$type][] = $rawName; |
581 | 610 | } |
582 | | - |
| 611 | + |
| 612 | + wfProfileOut( __METHOD__ ); |
583 | 613 | return $itemToRemoveRecords; |
584 | 614 | } |
585 | 615 | |
586 | 616 | public function DOMParseMainPage( $html ) { |
| 617 | + wfProfileIn( __METHOD__ ); |
587 | 618 | $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
588 | 619 | libxml_use_internal_errors( true ); |
589 | 620 | $this->mainPage = new DOMDocument(); |
— | — | @@ -613,13 +644,13 @@ |
614 | 645 | } |
615 | 646 | |
616 | 647 | $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG ); |
617 | | - |
| 648 | + wfProfileOut( __METHOD__ ); |
618 | 649 | return $contentHtml; |
619 | 650 | } |
620 | 651 | |
621 | 652 | public function DOMParse( $html ) { |
622 | 653 | global $wgSitename; |
623 | | - |
| 654 | + wfProfileIn( __METHOD__ ); |
624 | 655 | $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
625 | 656 | libxml_use_internal_errors( true ); |
626 | 657 | $this->doc = new DOMDocument(); |
— | — | @@ -759,15 +790,17 @@ |
760 | 791 | $json_data['title'] = self::$title->getText(); |
761 | 792 | $json_data['html'] = $contentHtml; |
762 | 793 | |
763 | | - $json = json_encode( $json_data ); |
| 794 | + $json = FormatJson::encode( $json_data ); |
764 | 795 | |
765 | 796 | if ( !empty( self::$callback ) ) { |
766 | 797 | $json = urlencode( self::$callback ) . '(' . $json . ')'; |
767 | 798 | } |
768 | 799 | |
| 800 | + wfProfileOut( __METHOD__ ); |
769 | 801 | return $json; |
770 | 802 | } |
771 | | - |
| 803 | + |
| 804 | + wfProfileOut( __METHOD__ ); |
772 | 805 | return $applicationHtml; |
773 | 806 | } |
774 | 807 | |
— | — | @@ -776,8 +809,10 @@ |
777 | 810 | */ |
778 | 811 | public function setDefaultLogo() { |
779 | 812 | global $wgMobileFrontendLogo, $wgExtensionAssetsPath; |
| 813 | + wfProfileIn( __METHOD__ ); |
780 | 814 | if ( $wgMobileFrontendLogo === false ) { |
781 | 815 | $wgMobileFrontendLogo = $wgExtensionAssetsPath . '/MobileFrontend/stylesheets/images/mw.png'; |
782 | 816 | } |
| 817 | + wfProfileOut( __METHOD__ ); |
783 | 818 | } |
784 | 819 | } |