Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.i18n.php |
— | — | @@ -56,6 +56,8 @@ |
57 | 57 | 'mobile-frontend-opt-out-explain' => 'This allows you to leave the test', |
58 | 58 | 'mobile-frontend-disable-images' => 'Disable images on mobile site', |
59 | 59 | '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', |
60 | 62 | ); |
61 | 63 | |
62 | 64 | /** Moroccan Spoken Arabic (Maġribi) */ |
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -49,12 +49,13 @@ |
50 | 50 | $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' ); |
51 | 51 | |
52 | 52 | class ExtMobileFrontend { |
53 | | - const VERSION = '0.5.23'; |
| 53 | + const VERSION = '0.5.24'; |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @var DOMDocument |
57 | 57 | */ |
58 | 58 | private $doc; |
| 59 | + private $mainPage; |
59 | 60 | |
60 | 61 | public static $messages = array(); |
61 | 62 | |
— | — | @@ -79,6 +80,7 @@ |
80 | 81 | public static $useFormat; |
81 | 82 | public static $disableImages; |
82 | 83 | public static $enableImages; |
| 84 | + public static $isMainPage = false; |
83 | 85 | |
84 | 86 | public $itemsToRemove = array( |
85 | 87 | '#contentSub', # redirection notice |
— | — | @@ -158,6 +160,8 @@ |
159 | 161 | self::$messages['mobile-frontend-wml-continue'] = wfMsg( 'mobile-frontend-wml-continue' ); |
160 | 162 | self::$messages['mobile-frontend-wml-back'] = wfMsg( 'mobile-frontend-wml-back' ); |
161 | 163 | 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' ); |
162 | 166 | |
163 | 167 | self::$dir = $wgContLang->getDir(); |
164 | 168 | self::$code = $wgContLang->getCode(); |
— | — | @@ -176,6 +180,11 @@ |
177 | 181 | |
178 | 182 | // The title |
179 | 183 | self::$title = $out->getTitle(); |
| 184 | + |
| 185 | + if ( $out->getTitle()->isMainPage() ) { |
| 186 | + self::$isMainPage = true; |
| 187 | + } |
| 188 | + |
180 | 189 | self::$htmlTitle = $out->getHTMLTitle(); |
181 | 190 | |
182 | 191 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
— | — | @@ -214,26 +223,26 @@ |
215 | 224 | $action = $wgRequest->getText( 'action' ); |
216 | 225 | self::$disableImages = $wgRequest->getText( 'disableImages', 0 ); |
217 | 226 | self::$enableImages = $wgRequest->getText( 'enableImages', 0 ); |
218 | | - |
| 227 | + |
219 | 228 | if ( self::$disableImages == 1 ) { |
220 | 229 | $wgRequest->response()->setcookie( 'disableImages', 1 ); |
221 | 230 | } |
222 | | - |
| 231 | + |
223 | 232 | if ( self::$disableImages == 0 ) { |
224 | 233 | $disableImages = $wgRequest->getCookie( 'disableImages' ); |
225 | 234 | if ( $disableImages ) { |
226 | 235 | self::$disableImages = $disableImages; |
227 | 236 | } |
228 | 237 | } |
229 | | - |
| 238 | + |
230 | 239 | if ( self::$enableImages == 1 ) { |
231 | 240 | $disableImages = $wgRequest->getCookie( 'disableImages' ); |
232 | 241 | if ( $disableImages ) { |
233 | 242 | $wgRequest->response()->setcookie( 'disableImages', '' ); |
234 | 243 | } |
235 | 244 | } |
236 | | - |
237 | | - |
| 245 | + |
| 246 | + |
238 | 247 | self::$useFormat = $wgRequest->getText( 'useFormat' ); |
239 | 248 | self::$format = $wgRequest->getText( 'format' ); |
240 | 249 | self::$requestedSegment = $wgRequest->getText( 'seg', 0 ); |
— | — | @@ -261,28 +270,28 @@ |
262 | 271 | exit(); |
263 | 272 | } |
264 | 273 | } |
265 | | - |
| 274 | + |
266 | 275 | if ( $mAction == 'opt_in_mobile_site' ) { |
267 | 276 | if ( $this->contentFormat == 'XHTML' ) { |
268 | 277 | echo $this->renderOptInMobileSiteXHTML(); |
269 | 278 | exit(); |
270 | 279 | } |
271 | 280 | } |
272 | | - |
| 281 | + |
273 | 282 | if ( $mAction == 'opt_out_mobile_site' ) { |
274 | 283 | if ( $this->contentFormat == 'XHTML' ) { |
275 | 284 | echo $this->renderOptOutMobileSiteXHTML(); |
276 | 285 | exit(); |
277 | 286 | } |
278 | 287 | } |
279 | | - |
| 288 | + |
280 | 289 | if ( $mAction == 'opt_in_cookie' ) { |
281 | 290 | $this->setOptInOutCookie( '1' ); |
282 | 291 | $this->disableCaching(); |
283 | 292 | $location = Title::newMainPage()->getFullURL(); |
284 | 293 | header( 'Location: ' . $location ); |
285 | 294 | } |
286 | | - |
| 295 | + |
287 | 296 | if ( $mAction == 'opt_out_cookie' ) { |
288 | 297 | $this->setOptInOutCookie( '' ); |
289 | 298 | } |
— | — | @@ -322,13 +331,14 @@ |
323 | 332 | // html_preferred_dtd |
324 | 333 | |
325 | 334 | // Determine |
326 | | - |
| 335 | + |
327 | 336 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
328 | 337 | |
329 | 338 | if (self::$useFormat === 'mobile' || |
330 | 339 | self::$useFormat === 'mobile-wap' || |
331 | 340 | !empty( $xDevice ) ) { |
332 | | - if ( $action !== 'edit' ) { |
| 341 | + if ( $action !== 'edit' && |
| 342 | + $mAction !== 'view_normal_site' ) { |
333 | 343 | $this->getMsg(); |
334 | 344 | $this->disableCaching(); |
335 | 345 | ob_start( array( $this, 'DOMParse' ) ); |
— | — | @@ -337,7 +347,7 @@ |
338 | 348 | |
339 | 349 | return true; |
340 | 350 | } |
341 | | - |
| 351 | + |
342 | 352 | private function setOptInOutCookie( $value ) { |
343 | 353 | global $wgCookieDomain, $wgRequest; |
344 | 354 | $tempWgCookieDomain = $wgCookieDomain; |
— | — | @@ -345,13 +355,13 @@ |
346 | 356 | $wgRequest->response()->setcookie( 'optin', $value ); |
347 | 357 | $wgCookieDomain = $tempWgCookieDomain; |
348 | 358 | } |
349 | | - |
| 359 | + |
350 | 360 | private function getBaseDomain() { |
351 | 361 | //Validates value as IP address |
352 | 362 | if( !filter_var( $_SERVER['HTTP_HOST'], FILTER_VALIDATE_IP ) ) { |
353 | 363 | $domainParts = explode( '.', $_SERVER['HTTP_HOST'] ); |
354 | 364 | $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. |
356 | 366 | return '.' . $domainParts[1] . '.' . $domainParts[0]; |
357 | 367 | } else { |
358 | 368 | return $_SERVER['HTTP_HOST']; |
— | — | @@ -366,59 +376,59 @@ |
367 | 377 | header( 'Pragma: no-cache' ); |
368 | 378 | } |
369 | 379 | } |
370 | | - |
| 380 | + |
371 | 381 | private function renderOptInMobileSiteXHTML() { |
372 | 382 | 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; |
395 | 405 | } |
396 | 406 | return ''; |
397 | 407 | } |
398 | | - |
| 408 | + |
399 | 409 | private function renderOptOutMobileSiteXHTML() { |
400 | 410 | 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; |
423 | 433 | } |
424 | 434 | return ''; |
425 | 435 | } |
— | — | @@ -455,8 +465,8 @@ |
456 | 466 | private function headingTransformCallbackWML( $matches ) { |
457 | 467 | static $headings = 0; |
458 | 468 | ++$headings; |
459 | | - |
460 | | - $base = $this->WMLSectionSeperator . |
| 469 | + |
| 470 | + $base = $this->WMLSectionSeperator . |
461 | 471 | "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>"; |
462 | 472 | |
463 | 473 | self::$headings = $headings; |
— | — | @@ -567,7 +577,40 @@ |
568 | 578 | |
569 | 579 | return $itemToRemoveRecords; |
570 | 580 | } |
| 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' ); |
571 | 594 | |
| 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 | + |
572 | 615 | public function DOMParse( $html ) { |
573 | 616 | global $wgSitename; |
574 | 617 | |
— | — | @@ -664,6 +707,10 @@ |
665 | 708 | $content = $this->doc->getElementById( 'content' ); |
666 | 709 | |
667 | 710 | $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |
| 711 | + |
| 712 | + if ( self::$isMainPage ) { |
| 713 | + $contentHtml = $this->DOMParseMainPage( $contentHtml ); |
| 714 | + } |
668 | 715 | |
669 | 716 | $dir = self::$dir; |
670 | 717 | $code = self::$code; |