Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -18,11 +18,11 @@ |
19 | 19 | // Define the extension; allows us make sure the extension is used correctly |
20 | 20 | define( 'MOBILEFRONTEND', 'MobileFrontend' ); |
21 | 21 | // WURFL installation dir |
22 | | -define( 'WURFL_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library' . |
| 22 | +define( 'WURFL_DIR', dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'library' . |
23 | 23 | DIRECTORY_SEPARATOR . 'WURFL' . DIRECTORY_SEPARATOR ); |
24 | 24 | // WURFL configuration files directory |
25 | | -define( 'RESOURCES_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library' . |
26 | | - DIRECTORY_SEPARATOR. 'resources' . DIRECTORY_SEPARATOR ); |
| 25 | +define( 'RESOURCES_DIR', dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'library' . |
| 26 | + DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR ); |
27 | 27 | |
28 | 28 | require_once( WURFL_DIR . 'Application.php' ); |
29 | 29 | |
— | — | @@ -36,9 +36,9 @@ |
37 | 37 | 'url' => 'http://www.mediawiki.org/wiki/Extension:MobileFrontend', |
38 | 38 | ); |
39 | 39 | |
40 | | -$cwd = dirname(__FILE__) . DIRECTORY_SEPARATOR; |
| 40 | +$cwd = dirname( __FILE__ ) . DIRECTORY_SEPARATOR; |
41 | 41 | $wgExtensionMessagesFiles['MobileFrontend'] = $cwd . 'MobileFrontend.i18n.php'; |
42 | | -//autoload extension classes |
| 42 | +// autoload extension classes |
43 | 43 | $wgAutoloadClasses['DeviceDetection'] = $cwd . 'DeviceDetection.php'; |
44 | 44 | $wgAutoloadClasses['CssDetection'] = $cwd . 'CssDetection.php'; |
45 | 45 | |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | } |
86 | 86 | |
87 | 87 | class ExtMobileFrontend { |
88 | | - const VERSION = '0.5.70'; |
| 88 | + const VERSION = '0.5.73'; |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @var DOMDocument |
— | — | @@ -125,8 +125,8 @@ |
126 | 126 | public static $displayNoticeId; |
127 | 127 | public static $leaveFeedbackURL; |
128 | 128 | public static $mobileRedirectFormAction; |
129 | | - |
130 | | - public static $messageKeys = array( |
| 129 | + |
| 130 | + public static $messageKeys = array( |
131 | 131 | 'mobile-frontend-show-button', |
132 | 132 | 'mobile-frontend-hide-button', |
133 | 133 | 'mobile-frontend-back-to-top-of-section', |
— | — | @@ -198,7 +198,7 @@ |
199 | 199 | '#ogg_player_1', |
200 | 200 | '.nomobile', |
201 | 201 | ); |
202 | | - |
| 202 | + |
203 | 203 | public function testCanonicalRedirect( $request, $title, $output ) { |
204 | 204 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
205 | 205 | if ( empty( $xDevice ) ) { |
— | — | @@ -214,39 +214,49 @@ |
215 | 215 | |
216 | 216 | $title = $obj->getTitle(); |
217 | 217 | $isSpecial = $title->isSpecialPage(); |
218 | | - |
| 218 | + |
219 | 219 | if ( ! $isSpecial ) { |
220 | 220 | $footerlinks = $tpl->data['footerlinks']; |
221 | 221 | $mobileViewUrl = $wgRequest->escapeAppendQuery( 'useformat=mobile' ); |
222 | 222 | |
223 | | - $tpl->set('mobileview', "<a href='{$mobileViewUrl}'>" . wfMsg( 'mobile-frontend-view' ) . "</a>"); |
| 223 | + $tpl->set( 'mobileview', "<a href='{$mobileViewUrl}'>" . wfMsg( 'mobile-frontend-view' ) . "</a>" ); |
224 | 224 | $footerlinks['places'][] = 'mobileview'; |
225 | | - $tpl->set('footerlinks', $footerlinks); |
| 225 | + $tpl->set( 'footerlinks', $footerlinks ); |
226 | 226 | } |
227 | 227 | wfProfileOut( __METHOD__ ); |
228 | 228 | return true; |
229 | 229 | } |
| 230 | + |
| 231 | + private function removeQueryStringParameter( $url, $field ) { |
| 232 | + $url = preg_replace( '/(.*)(\?|&)' . $field . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&' ); |
| 233 | + $url = substr( $url, 0, -1 ); |
| 234 | + return $url; |
| 235 | + } |
230 | 236 | |
231 | 237 | public function getMsg() { |
232 | 238 | global $wgUser, $wgContLang, $wgRequest, $wgServer, $wgMobileRedirectFormAction, $wgMobileDomain; |
233 | 239 | wfProfileIn( __METHOD__ ); |
234 | | - |
| 240 | + |
235 | 241 | self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' ); |
236 | 242 | self::$enableImagesURL = $wgRequest->escapeAppendQuery( 'enableImages=1' ); |
237 | 243 | self::$disableMobileSiteURL = $wgRequest->escapeAppendQuery( 'mobileaction=disable_mobile_site' ); |
238 | | - self::$viewNormalSiteURL = $wgRequest->escapeAppendQuery( 'mobileaction=view_normal_site' ); |
239 | | - self::$currentURL = $wgRequest->getFullRequestURL(); |
| 244 | + $parsedUrl = wfParseUrl( $wgRequest->getFullRequestURL() ); |
| 245 | + $parsedUrl['host'] = str_replace( $wgMobileDomain, '.', $parsedUrl['host'] ); |
| 246 | + $parsedUrl['query'] = $this->removeQueryStringParameter( $parsedUrl['query'], 'useformat' ); |
| 247 | + $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : ''; |
| 248 | + self::$viewNormalSiteURL = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'] . '?' . $parsedUrl['query'] . $fragmentDelimiter . $parsedUrl['fragment']; |
| 249 | + self::$currentURL = $wgRequest->getFullRequestURL(); |
240 | 250 | self::$leaveFeedbackURL = $wgRequest->escapeAppendQuery( 'mobileaction=leave_feedback' ); |
241 | | - |
| 251 | + |
242 | 252 | $skin = $wgUser->getSkin(); |
243 | 253 | $copyright = $skin->getCopyright(); |
244 | 254 | // Need to stash the results of the "wfMsg" call before the Output Buffering handler |
245 | 255 | // because at this point the database connection is shut down, etc. |
246 | | - |
| 256 | + |
247 | 257 | self::$messages['mobile-frontend-copyright'] = $copyright; |
248 | | - |
| 258 | + |
249 | 259 | foreach ( self::$messageKeys as $messageKey ) { |
250 | | - |
| 260 | + |
251 | 261 | if ( $messageKey == 'mobile-frontend-leave-feedback-notice' ) { |
252 | 262 | $linkText = wfMsg( 'mobile-frontend-leave-feedback-link-text' ); |
253 | 263 | $linkTarget = wfMsgNoTrans( 'mobile-frontend-feedback-page' ); |
— | — | @@ -260,7 +270,7 @@ |
261 | 271 | |
262 | 272 | self::$dir = $wgContLang->getDir(); |
263 | 273 | self::$code = $wgContLang->getCode(); |
264 | | - |
| 274 | + |
265 | 275 | $nonMobileServerBaseURL = str_replace( $wgMobileDomain, '.', $wgServer ); |
266 | 276 | self::$mobileRedirectFormAction = ( $wgMobileRedirectFormAction !== false ) ? $wgMobileRedirectFormAction : "{$nonMobileServerBaseURL}/w/mobileRedirect.php"; |
267 | 277 | |
— | — | @@ -279,15 +289,15 @@ |
280 | 290 | wfProfileIn( __METHOD__ ); |
281 | 291 | // The title |
282 | 292 | self::$title = $out->getTitle(); |
283 | | - |
| 293 | + |
284 | 294 | if ( Title::newMainPage()->equals( self::$title ) ) { |
285 | 295 | self::$isMainPage = true; |
286 | 296 | } |
287 | | - |
| 297 | + |
288 | 298 | self::$htmlTitle = $out->getHTMLTitle(); |
289 | 299 | |
290 | 300 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
291 | | - $uAmd5 = md5($userAgent); |
| 301 | + $uAmd5 = md5( $userAgent ); |
292 | 302 | |
293 | 303 | $key = wfMemcKey( 'mobile', 'ua', $uAmd5 ); |
294 | 304 | |
— | — | @@ -308,8 +318,8 @@ |
309 | 319 | $props = "generic"; |
310 | 320 | } |
311 | 321 | } |
312 | | - } catch (Exception $e) { |
313 | | - //echo $e->getMessage(); |
| 322 | + } catch ( Exception $e ) { |
| 323 | + // echo $e->getMessage(); |
314 | 324 | } |
315 | 325 | |
316 | 326 | // Note: The WebRequest Class calls are made in this block because |
— | — | @@ -331,7 +341,7 @@ |
332 | 342 | $location = $this->getRelativeURL( $location ); |
333 | 343 | $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' ); |
334 | 344 | } |
335 | | - |
| 345 | + |
336 | 346 | if ( self::$disableImages == 0 ) { |
337 | 347 | $disableImages = $wgRequest->getCookie( 'disableImages' ); |
338 | 348 | if ( $disableImages ) { |
— | — | @@ -356,18 +366,18 @@ |
357 | 367 | self::$search = $wgRequest->getText( 'search' ); |
358 | 368 | self::$callback = $wgRequest->getText( 'callback' ); |
359 | 369 | self::$searchField = $wgRequest->getText( 'search', '' ); |
360 | | - |
| 370 | + |
361 | 371 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
362 | 372 | |
363 | 373 | $acceptHeader = $_SERVER["HTTP_ACCEPT"]; |
364 | 374 | $device = new DeviceDetection(); |
365 | | - |
| 375 | + |
366 | 376 | if ( !empty( $xDevice ) ) { |
367 | 377 | $formatName = $xDevice; |
368 | 378 | } else { |
369 | 379 | $formatName = $device->formatName( $userAgent, $acceptHeader ); |
370 | 380 | } |
371 | | - |
| 381 | + |
372 | 382 | self::$device = $device->format( $formatName ); |
373 | 383 | |
374 | 384 | if ( self::$device['view_format'] === 'wml' ) { |
— | — | @@ -379,7 +389,7 @@ |
380 | 390 | if ( self::$useFormat === 'mobile-wap' ) { |
381 | 391 | $this->contentFormat = 'WML'; |
382 | 392 | } |
383 | | - |
| 393 | + |
384 | 394 | if ( $mobileAction == 'leave_feedback' ) { |
385 | 395 | echo $this->renderLeaveFeedbackXHTML(); |
386 | 396 | wfProfileOut( __METHOD__ ); |
— | — | @@ -387,15 +397,15 @@ |
388 | 398 | } |
389 | 399 | |
390 | 400 | if ( $mobileAction == 'leave_feedback_post' ) { |
391 | | - |
| 401 | + |
392 | 402 | $this->getMsg(); |
393 | | - |
| 403 | + |
394 | 404 | $subject = $wgRequest->getText( 'subject', '' ); |
395 | 405 | $message = $wgRequest->getText( 'message', '' ); |
396 | 406 | $token = $wgRequest->getText( 'edittoken', '' ); |
397 | | - |
| 407 | + |
398 | 408 | $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] ); |
399 | | - |
| 409 | + |
400 | 410 | if ( $title->userCan( 'edit' ) && |
401 | 411 | !$wgUser->isBlockedFrom( $title ) && |
402 | 412 | $wgUser->matchEditToken( $token ) ) { |
— | — | @@ -404,7 +414,7 @@ |
405 | 415 | $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> "; |
406 | 416 | $article->doEdit( $rawtext, '' ); |
407 | 417 | } |
408 | | - |
| 418 | + |
409 | 419 | $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '¬iceid=1' ); |
410 | 420 | $location = $this->getRelativeURL( $location ); |
411 | 421 | $wgRequest->response()->header( 'Location: ' . $location ); |
— | — | @@ -449,8 +459,8 @@ |
450 | 460 | |
451 | 461 | // WURFL documentation: http://wurfl.sourceforge.net/help_doc.php |
452 | 462 | // Determine the kind of markup |
453 | | - if( is_array( $props ) && $props['preferred_markup'] ) { |
454 | | - //wfDebug( __METHOD__ . ": preferred markup for this device: " . $props['preferred_markup'] ); |
| 463 | + if ( is_array( $props ) && $props['preferred_markup'] ) { |
| 464 | + // wfDebug( __METHOD__ . ": preferred markup for this device: " . $props['preferred_markup'] ); |
455 | 465 | // xhtml/html: html_web_3_2, html_web_4_0 |
456 | 466 | // xthml basic/xhtmlmp (wap 2.0): html_wi_w3_xhtmlbasic html_wi_oma_xhtmlmp_1_0 |
457 | 467 | // chtml (imode): html_wi_imode_* |
— | — | @@ -470,10 +480,10 @@ |
471 | 481 | |
472 | 482 | // Determine |
473 | 483 | |
474 | | - if (self::$useFormat === 'mobile' || |
| 484 | + if ( self::$useFormat === 'mobile' || |
475 | 485 | self::$useFormat === 'mobile-wap' || |
476 | 486 | !empty( $xDevice ) ) { |
477 | | - if ( $action !== 'edit' && |
| 487 | + if ( $action !== 'edit' && |
478 | 488 | $mobileAction !== 'view_normal_site' ) { |
479 | 489 | $this->getMsg(); |
480 | 490 | $this->disableCaching(); |
— | — | @@ -498,11 +508,11 @@ |
499 | 509 | |
500 | 510 | private function getBaseDomain() { |
501 | 511 | wfProfileIn( __METHOD__ ); |
502 | | - //Validates value as IP address |
503 | | - if( !IP::isValid( $_SERVER['HTTP_HOST'] ) ) { |
| 512 | + // Validates value as IP address |
| 513 | + if ( !IP::isValid( $_SERVER['HTTP_HOST'] ) ) { |
504 | 514 | $domainParts = explode( '.', $_SERVER['HTTP_HOST'] ); |
505 | 515 | $domainParts = array_reverse( $domainParts ); |
506 | | - //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included. |
| 516 | + // Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included. |
507 | 517 | wfProfileOut( __METHOD__ ); |
508 | 518 | return '.' . $domainParts[1] . '.' . $domainParts[0]; |
509 | 519 | } else { |
— | — | @@ -514,8 +524,8 @@ |
515 | 525 | private function getRelativeURL( $url ) { |
516 | 526 | wfProfileIn( __METHOD__ ); |
517 | 527 | $parsedUrl = parse_url( $url ); |
518 | | - //Validates value as IP address |
519 | | - if( !IP::isValid( $parsedUrl['host'] ) ) { |
| 528 | + // Validates value as IP address |
| 529 | + if ( !IP::isValid( $parsedUrl['host'] ) ) { |
520 | 530 | wfProfileOut( __METHOD__ ); |
521 | 531 | $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; |
522 | 532 | $baseUrl = str_replace( $baseUrl, '', $url ); |
— | — | @@ -537,7 +547,7 @@ |
538 | 548 | } |
539 | 549 | wfProfileOut( __METHOD__ ); |
540 | 550 | } |
541 | | - |
| 551 | + |
542 | 552 | private function sendXDeviceVaryHeader() { |
543 | 553 | global $wgOut, $wgRequest; |
544 | 554 | wfProfileIn( __METHOD__ ); |
— | — | @@ -547,14 +557,14 @@ |
548 | 558 | } |
549 | 559 | wfProfileOut( __METHOD__ ); |
550 | 560 | } |
551 | | - |
| 561 | + |
552 | 562 | private function renderLeaveFeedbackXHTML() { |
553 | 563 | global $wgRequest, $wgUser; |
554 | 564 | wfProfileIn( __METHOD__ ); |
555 | 565 | if ( $this->contentFormat == 'XHTML' ) { |
556 | 566 | $this->getMsg(); |
557 | 567 | $editToken = $wgUser->editToken(); |
558 | | - |
| 568 | + |
559 | 569 | $htmlTitle = self::$messages['mobile-frontend-leave-feedback']; |
560 | 570 | $title = self::$messages['mobile-frontend-leave-feedback-title']; |
561 | 571 | $notice = self::$messages['mobile-frontend-leave-feedback-notice']; |
— | — | @@ -562,7 +572,7 @@ |
563 | 573 | $message = self::$messages['mobile-frontend-leave-feedback-message']; |
564 | 574 | $cancel = self::$messages['mobile-frontend-leave-feedback-cancel']; |
565 | 575 | $submit = self::$messages['mobile-frontend-leave-feedback-submit']; |
566 | | - |
| 576 | + |
567 | 577 | $feedbackPostURL = str_replace( '&mobileaction=leave_feedback', '', $wgRequest->getFullRequestURL() ) . '&mobileaction=leave_feedback_post'; |
568 | 578 | require( 'views/layout/_search_webkit.html.php' ); |
569 | 579 | require( 'views/layout/_footmenu_default.html.php' ); |
— | — | @@ -656,7 +666,7 @@ |
657 | 667 | private function headingTransformCallbackXHTML( $matches ) { |
658 | 668 | wfProfileIn( __METHOD__ ); |
659 | 669 | if ( isset( $matches[0] ) ) { |
660 | | - preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches); |
| 670 | + preg_match( '/id="([^"]*)"/', $matches[0], $headlineMatches ); |
661 | 671 | } |
662 | 672 | |
663 | 673 | $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : ''; |
— | — | @@ -667,35 +677,35 @@ |
668 | 678 | $backToTop = self::$messages['mobile-frontend-back-to-top-of-section']; |
669 | 679 | ++$headings; |
670 | 680 | // Back to top link |
671 | | - $base = Html::openElement( 'div', |
672 | | - array( 'id' => 'anchor_' . intval( $headings - 1 ), |
673 | | - 'class' => 'section_anchors', ) |
| 681 | + $base = Html::openElement( 'div', |
| 682 | + array( 'id' => 'anchor_' . intval( $headings - 1 ), |
| 683 | + 'class' => 'section_anchors', ) |
674 | 684 | ) . |
675 | 685 | Html::rawElement( 'a', |
676 | | - array( 'href' => '#section_' . intval( $headings - 1 ), |
677 | | - 'class' => 'back_to_top' ), |
678 | | - '↑' . $backToTop ) . |
| 686 | + array( 'href' => '#section_' . intval( $headings - 1 ), |
| 687 | + 'class' => 'back_to_top' ), |
| 688 | + '↑' . $backToTop ) . |
679 | 689 | Html::closeElement( 'div' ); |
680 | 690 | // generate the HTML we are going to inject |
681 | 691 | $buttons = Html::element( 'button', |
682 | | - array('class' => 'section_heading show', |
683 | | - 'section_id' => $headings ), |
| 692 | + array( 'class' => 'section_heading show', |
| 693 | + 'section_id' => $headings ), |
684 | 694 | $show ) . |
685 | | - Html::element( 'button', |
686 | | - array('class' => 'section_heading hide', |
| 695 | + Html::element( 'button', |
| 696 | + array( 'class' => 'section_heading hide', |
687 | 697 | 'section_id' => $headings ), |
688 | | - $hide ); |
| 698 | + $hide ); |
689 | 699 | $base .= Html::openElement( 'h2', |
690 | | - array('class' => 'section_heading', |
691 | | - 'id' => 'section_' . $headings) ) . |
| 700 | + array( 'class' => 'section_heading', |
| 701 | + 'id' => 'section_' . $headings ) ) . |
692 | 702 | $buttons . |
693 | 703 | Html::rawElement( 'span', |
694 | | - array( 'id' => $headlineId), |
| 704 | + array( 'id' => $headlineId ), |
695 | 705 | $matches[2] ) . |
696 | | - Html::closeElement( 'h2' ) . |
697 | | - Html::openElement( 'div', |
698 | | - array('class' => 'content_block', |
699 | | - 'id' => 'content_' . $headings) ); |
| 706 | + Html::closeElement( 'h2' ) . |
| 707 | + Html::openElement( 'div', |
| 708 | + array( 'class' => 'content_block', |
| 709 | + 'id' => 'content_' . $headings ) ); |
700 | 710 | |
701 | 711 | if ( $headings > 1 ) { |
702 | 712 | // Close it up here |
— | — | @@ -748,11 +758,11 @@ |
749 | 759 | |
750 | 760 | $card .= "<card id='s{$idx}' title='{$title}'><p>{$segments[$requestedSegment]}</p>"; |
751 | 761 | $idx = $requestedSegment + 1; |
752 | | - $segmentsCount = count($segments); |
| 762 | + $segmentsCount = count( $segments ); |
753 | 763 | $card .= "<p>" . $idx . "/" . $segmentsCount . "</p>"; |
754 | 764 | |
755 | 765 | $useFormatParam = ( isset( self::$useFormat ) ) ? '&' . 'useformat=' . self::$useFormat : ''; |
756 | | - |
| 766 | + |
757 | 767 | // Title::getLocalUrl doesn't work at this point since PHP 5.1.x, all objects have their destructors called |
758 | 768 | // before the output buffer callback function executes. |
759 | 769 | // Thus, globalized objects will not be available as expected in the function. |
— | — | @@ -760,13 +770,13 @@ |
761 | 771 | $mDefaultQuery = $_GET; |
762 | 772 | unset( $mDefaultQuery['seg'] ); |
763 | 773 | unset( $mDefaultQuery['useformat'] ); |
764 | | - |
| 774 | + |
765 | 775 | $qs = wfArrayToCGI( $mDefaultQuery ); |
766 | 776 | $delimiter = ( !empty( $qs ) ) ? '?' : ''; |
767 | 777 | $basePageParts = wfParseUrl( self::$currentURL ); |
768 | 778 | $basePage = $basePageParts['scheme'] . $basePageParts['delimiter'] . $basePageParts['host'] . $basePageParts['path'] . $delimiter . $qs; |
769 | 779 | $appendDelimiter = ( $delimiter === '?' ) ? '&' : '?'; |
770 | | - |
| 780 | + |
771 | 781 | if ( $idx < $segmentsCount ) { |
772 | 782 | $card .= "<p><a href=\"{$basePage}{$appendDelimiter}seg={$idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-continue'] . "</a></p>"; |
773 | 783 | } |
— | — | @@ -794,47 +804,47 @@ |
795 | 805 | CssDetection::detectIdCssOrTag( $itemToRemove, $type, $rawName ); |
796 | 806 | $itemToRemoveRecords[$type][] = $rawName; |
797 | 807 | } |
798 | | - |
| 808 | + |
799 | 809 | wfProfileOut( __METHOD__ ); |
800 | 810 | return $itemToRemoveRecords; |
801 | 811 | } |
802 | | - |
| 812 | + |
803 | 813 | public function DOMParseMainPage( $html ) { |
804 | 814 | wfProfileIn( __METHOD__ ); |
805 | | - $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
| 815 | + $html = mb_convert_encoding( $html, 'HTML-ENTITIES', "UTF-8" ); |
806 | 816 | libxml_use_internal_errors( true ); |
807 | 817 | $this->mainPage = new DOMDocument(); |
808 | | - //It seems that loadhtml() does not "attach" the html dtd that defines id as an id-attribute to the DOM. |
| 818 | + // It seems that loadhtml() does not "attach" the html dtd that defines id as an id-attribute to the DOM. |
809 | 819 | $this->mainPage->loadHTML( '<?xml encoding="UTF-8"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
810 | 820 | <html><head><title></title></head><body>' . $html . '</body></html>' ); |
811 | 821 | libxml_use_internal_errors( false ); |
812 | 822 | $this->mainPage->preserveWhiteSpace = false; |
813 | 823 | $this->mainPage->strictErrorChecking = false; |
814 | 824 | $this->mainPage->encoding = 'UTF-8'; |
815 | | - |
| 825 | + |
816 | 826 | $featuredArticle = $this->mainPage->getElementById( 'mp-tfa' ); |
817 | 827 | $newsItems = $this->mainPage->getElementById( 'mp-itn' ); |
818 | | - |
| 828 | + |
819 | 829 | $xpath = new DOMXpath( $this->mainPage ); |
820 | 830 | $elements = $xpath->query( '//*[starts-with(@id, "mf-")]' ); |
821 | | - |
822 | | - $commonAttributes = array('mp-tfa', 'mp-itn'); |
823 | 831 | |
| 832 | + $commonAttributes = array( 'mp-tfa', 'mp-itn' ); |
| 833 | + |
824 | 834 | $content = $this->mainPage->createElement( 'div' ); |
825 | 835 | $content->setAttribute( 'id', 'main_box' ); |
826 | | - |
| 836 | + |
827 | 837 | if ( $featuredArticle ) { |
828 | 838 | $h2FeaturedArticle = $this->mainPage->createElement( 'h2', self::$messages['mobile-frontend-featured-article'] ); |
829 | 839 | $content->appendChild( $h2FeaturedArticle ); |
830 | 840 | $content->appendChild( $featuredArticle ); |
831 | 841 | } |
832 | | - |
| 842 | + |
833 | 843 | if ( $newsItems ) { |
834 | 844 | $h2NewsItems = $this->mainPage->createElement( 'h2', self::$messages['mobile-frontend-news-items'] ); |
835 | 845 | $content->appendChild( $h2NewsItems ); |
836 | 846 | $content->appendChild( $newsItems ); |
837 | 847 | } |
838 | | - |
| 848 | + |
839 | 849 | foreach ( $elements as $element ) { |
840 | 850 | if ( $element->hasAttribute( 'id' ) ) { |
841 | 851 | $id = $element->getAttribute( 'id' ); |
— | — | @@ -849,16 +859,16 @@ |
850 | 860 | } |
851 | 861 | } |
852 | 862 | } |
853 | | - |
| 863 | + |
854 | 864 | $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG ); |
855 | 865 | wfProfileOut( __METHOD__ ); |
856 | 866 | return $contentHtml; |
857 | 867 | } |
858 | 868 | |
859 | | - public function DOMParse( $html ) { |
| 869 | + public function DOMParse( $html ) { |
860 | 870 | global $wgSitename; |
861 | 871 | wfProfileIn( __METHOD__ ); |
862 | | - $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
| 872 | + $html = mb_convert_encoding( $html, 'HTML-ENTITIES', "UTF-8" ); |
863 | 873 | libxml_use_internal_errors( true ); |
864 | 874 | $this->doc = new DOMDocument(); |
865 | 875 | $this->doc->loadHTML( '<?xml encoding="UTF-8">' . $html ); |
— | — | @@ -891,14 +901,14 @@ |
892 | 902 | foreach ( $itemToRemoveRecords['TAG'] as $tagToRemove ) { |
893 | 903 | $tagToRemoveNodes = $this->doc->getElementsByTagName( $tagToRemove ); |
894 | 904 | |
895 | | - foreach( $tagToRemoveNodes as $tagToRemoveNode ) { |
| 905 | + foreach ( $tagToRemoveNodes as $tagToRemoveNode ) { |
896 | 906 | if ( $tagToRemoveNode ) { |
897 | 907 | $domElemsToRemove[] = $tagToRemoveNode; |
898 | 908 | } |
899 | 909 | } |
900 | 910 | } |
901 | 911 | |
902 | | - foreach( $domElemsToRemove as $domElement ) { |
| 912 | + foreach ( $domElemsToRemove as $domElement ) { |
903 | 913 | $domElement->parentNode->removeChild( $domElement ); |
904 | 914 | } |
905 | 915 | |
— | — | @@ -915,7 +925,7 @@ |
916 | 926 | foreach ( $itemToRemoveRecords['CLASS'] as $classToRemove ) { |
917 | 927 | $elements = $xpath->query( '//*[@class="' . $classToRemove . '"]' ); |
918 | 928 | |
919 | | - foreach( $elements as $element ) { |
| 929 | + foreach ( $elements as $element ) { |
920 | 930 | $removedElement = $element->parentNode->removeChild( $element ); |
921 | 931 | } |
922 | 932 | } |
— | — | @@ -928,15 +938,15 @@ |
929 | 939 | '//' . $parts[0] . '[@class="' . $parts[1] . '"]' |
930 | 940 | ); |
931 | 941 | |
932 | | - foreach( $elements as $element ) { |
| 942 | + foreach ( $elements as $element ) { |
933 | 943 | $removedElement = $element->parentNode->removeChild( $element ); |
934 | 944 | } |
935 | 945 | } |
936 | 946 | |
937 | 947 | // Handle red links with action equal to edit |
938 | 948 | $redLinks = $xpath->query( '//a[@class="new"]' ); |
939 | | - foreach( $redLinks as $redLink ) { |
940 | | - //PHP Bug #36795 — Inappropriate "unterminated entity reference" |
| 949 | + foreach ( $redLinks as $redLink ) { |
| 950 | + // PHP Bug #36795 — Inappropriate "unterminated entity reference" |
941 | 951 | $spanNode = $this->doc->createElement( "span", str_replace( "&", "&", $redLink->nodeValue ) ); |
942 | 952 | |
943 | 953 | if ( $redLink->hasAttributes() ) { |
— | — | @@ -951,7 +961,7 @@ |
952 | 962 | $content = $this->doc->getElementById( 'content' ); |
953 | 963 | |
954 | 964 | $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |
955 | | - |
| 965 | + |
956 | 966 | if ( self::$isMainPage ) { |
957 | 967 | $contentHtml = $this->DOMParseMainPage( $contentHtml ); |
958 | 968 | } |
— | — | @@ -966,7 +976,7 @@ |
967 | 977 | } elseif ( $this->contentFormat == 'WML' ) { |
968 | 978 | $homeButton = self::$messages['mobile-frontend-home-button']; |
969 | 979 | $randomButton = self::$messages['mobile-frontend-random-button']; |
970 | | - //header( 'Content-Type: text/vnd.wap.wml' ); |
| 980 | + // header( 'Content-Type: text/vnd.wap.wml' ); |
971 | 981 | |
972 | 982 | // TODO: Content transformations required |
973 | 983 | // WML Validator: |
— | — | @@ -988,12 +998,12 @@ |
989 | 999 | if ( $this->contentFormat == 'XHTML' && self::$format != 'json' ) { |
990 | 1000 | if ( !empty( self::$displayNoticeId ) ) { |
991 | 1001 | $noticePagePath = 'views/notices/notice_' . intval( self::$displayNoticeId ) . '.html.php'; |
992 | | - if ( file_exists( dirname(__FILE__) . '/' . $noticePagePath ) ) { |
| 1002 | + if ( file_exists( dirname( __FILE__ ) . '/' . $noticePagePath ) ) { |
993 | 1003 | require( $noticePagePath ); |
994 | 1004 | } |
995 | 1005 | } |
996 | | - |
997 | | - //header( 'Content-Type: application/xhtml+xml; charset=utf-8' ); |
| 1006 | + |
| 1007 | + // header( 'Content-Type: application/xhtml+xml; charset=utf-8' ); |
998 | 1008 | require( 'views/layout/_search_webkit.html.php' ); |
999 | 1009 | require( 'views/layout/_footmenu_default.html.php' ); |
1000 | 1010 | require( 'views/layout/application.html.php' ); |
— | — | @@ -1015,7 +1025,7 @@ |
1016 | 1026 | wfProfileOut( __METHOD__ ); |
1017 | 1027 | return $json; |
1018 | 1028 | } |
1019 | | - |
| 1029 | + |
1020 | 1030 | wfProfileOut( __METHOD__ ); |
1021 | 1031 | return $applicationHtml; |
1022 | 1032 | } |