r88467 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88466‎ | r88467 | r88468 >
Date:17:09, 20 May 2011
Author:preilly
Status:deferred (Comments)
Tags:
Comment:
added wml and rtl language support
Modified paths:
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.php (modified) (history)
  • /trunk/extensions/PatchOutputMobile/views/layout/application.html.php (modified) (history)
  • /trunk/extensions/PatchOutputMobile/views/layout/application.wml.php (added) (history)

Diff [purge]

Index: trunk/extensions/PatchOutputMobile/views/layout/application.wml.php
@@ -0,0 +1,15 @@
 2+<?php
 3+$applicationHtml = <<<EOT
 4+ <?xml version='1.0' encoding='utf-8' ?>
 5+ <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
 6+ <wml xml:lang="{$code}">
 7+ <head>
 8+ <title>{$title}</title>
 9+ <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
 10+ <meta name="character-set=utf-8" content="charset"/>
 11+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 12+ <meta forua="true" http-equiv="Cache-Control" content="max-age=0"/>
 13+ </head>
 14+ {$contentHtml}
 15+ </wml>
 16+EOT;
Property changes on: trunk/extensions/PatchOutputMobile/views/layout/application.wml.php
___________________________________________________________________
Added: svn:eol-style
117 + native
Index: trunk/extensions/PatchOutputMobile/views/layout/application.html.php
@@ -1,7 +1,7 @@
22 <?php
33 $applicationHtml = <<<EOT
44 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 -<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
 5+<html lang='{$code}' dir='{$dir}' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
66 <head>
77 <title>{$title}</title>
88 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php
@@ -27,11 +27,16 @@
2828 'onOutputPageBeforeHTML' );
2929
3030 class ExtPatchOutputMobile {
31 - const VERSION = '0.2.6';
 31+ const VERSION = '0.2.7';
3232
3333 private $doc;
3434
3535 public static $messages = array();
 36+
 37+ public $contentFormat = 'XHTML'; //'WML'
 38+ public $WMLSectionSeperator = '***************************************************************************';
 39+ public static $dir;
 40+ public static $code;
3641
3742 public $itemsToRemove = array(
3843 '#contentSub', # redirection notice
@@ -71,12 +76,29 @@
7277 ExtPatchOutputMobile::$messages['patch-output-mobile-show'] = wfMsg( 'patch-output-mobile-show' );
7378 ExtPatchOutputMobile::$messages['patch-output-mobile-hide'] = wfMsg( 'patch-output-mobile-hide' );
7479 ExtPatchOutputMobile::$messages['patch-output-mobile-back-to-top'] = wfMsg( 'patch-output-mobile-back-to-top' );
 80+ ExtPatchOutputMobile::$dir = $GLOBALS['wgContLang']->isRTL() ? "rtl" : "ltr";
 81+ ExtPatchOutputMobile::$code = $GLOBALS['wgContLang']->getCode();
7582
7683 ob_start( array( $this, 'parse' ) );
7784 return true;
7885 }
 86+
 87+ private function showHideCallbackWML( $matches ) {
 88+ static $headings = 0;
 89+ $show = ExtPatchOutputMobile::$messages['patch-output-mobile-show'];
 90+ $hide = ExtPatchOutputMobile::$messages['patch-output-mobile-hide'];
 91+ $backToTop = ExtPatchOutputMobile::$messages['patch-output-mobile-back-to-top'];
 92+ ++$headings;
7993
80 - private function showHideCallback( $matches ) {
 94+ $base = $this->WMLSectionSeperator .
 95+ "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>";
 96+
 97+ $GLOBALS['headings'] = $headings;
 98+
 99+ return $base;
 100+ }
 101+
 102+ private function showHideCallbackXHTML( $matches ) {
81103 static $headings = 0;
82104 $show = ExtPatchOutputMobile::$messages['patch-output-mobile-show'];
83105 $hide = ExtPatchOutputMobile::$messages['patch-output-mobile-hide'];
@@ -87,8 +109,10 @@
88110 "'><a href='#section_" . intval( $headings - 1 ) .
89111 "' class='back_to_top'>&uarr; {$backToTop}</a></div>";
90112 // generate the HTML we are going to inject
91 - $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button><button class='section_heading hide' section_id='{$headings}'>{$hide}</button>";
92 - $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span>{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>";
 113+ $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button>" .
 114+ "<button class='section_heading hide' section_id='{$headings}'>{$hide}</button>";
 115+ $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span>" .
 116+ "{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>";
93117
94118 if ( $headings > 1 ) {
95119 // Close it up here
@@ -101,12 +125,15 @@
102126 }
103127
104128 public function javascriptize( $s ) {
 129+ $callback = 'showHideCallback';
 130+ $callback .= $this->contentFormat;
 131+
105132 // Closures are a PHP 5.3 feature.
106133 // MediaWiki currently requires PHP 5.2.3 or higher.
107134 // So, using old style for now.
108135 $s = preg_replace_callback(
109136 '/<h2(.*)<span class="mw-headline" [^>]*>(.+)<\/span>\w*<\/h2>/',
110 - array( $this, 'showHideCallback' ),
 137+ array( $this, $callback ),
111138 $s
112139 );
113140
@@ -121,7 +148,31 @@
122149
123150 return $s;
124151 }
 152+
 153+ private function createWMLCard( $s, $title = '' ) {
 154+ $segments = explode( $this->WMLSectionSeperator, $s );
 155+ $card = '';
 156+ $idx = 0;
125157
 158+ $requestedSegment = isset( $_GET['seg'] ) ? $_GET['seg'] : 0;
 159+ $card .= "<card id='{$idx}' title='{$title}'><p>{$segments[$requestedSegment]}</p>";
 160+ $idx = $requestedSegment + 1;
 161+ $segmentsCount = count($segments);
 162+ $card .= $idx . "/" . $segmentsCount;
 163+
 164+ if ( $idx < $segmentsCount ) {
 165+ $card .= "<p><a href='{$_SERVER['PHP_SELF']}?seg={$idx}'>Continue ...</a></p>";
 166+ }
 167+
 168+ if ( $idx > 1 ) {
 169+ $back_idx = $requestedSegment - 1;
 170+ $card .= "<p><a href='{$_SERVER['PHP_SELF']}?seg={$back_idx}'>Back ...</a></p>";
 171+ }
 172+
 173+ $card .= '</card>';
 174+ return $card;
 175+ }
 176+
126177 public function parse( $s ) {
127178 return $this->DOMParse( $s );
128179 }
@@ -141,10 +192,11 @@
142193
143194 public function DOMParse( $html ) {
144195 libxml_use_internal_errors( true );
145 - $this->doc = DOMDocument::loadHTML( $html );
 196+ $this->doc = DOMDocument::loadHTML( '<?xml encoding="UTF-8">' . $html );
146197 libxml_use_internal_errors( false );
147198 $this->doc->preserveWhiteSpace = false;
148199 $this->doc->strictErrorChecking = false;
 200+ $this->doc->encoding = 'UTF-8';
149201
150202 $itemToRemoveRecords = $this->parseItemsToRemove();
151203
@@ -223,7 +275,6 @@
224276
225277 $redLink->parentNode->replaceChild( $spanNode, $redLink );
226278 }
227 -
228279 $content = $this->doc->getElementById( 'content' );
229280
230281 $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG );
@@ -231,13 +282,26 @@
232283 if ( empty( $title ) ) {
233284 $title = 'Wikipedia';
234285 }
235 -
236 - require( 'views/notices/_donate.html.php' );
237 - require( 'views/layout/_search_webkit.html.php' );
238 - require( 'views/layout/_footmenu_default.html.php' );
239 - require( 'views/layout/application.html.php' );
240 -
241 - return ( strlen( $contentHtml ) > 4000 ) ? $this->javascriptize( $applicationHtml ) : $applicationHtml;
 286+
 287+ $dir = ExtPatchOutputMobile::$dir;
 288+ $code = ExtPatchOutputMobile::$code;
 289+
 290+ if ( strlen( $contentHtml ) > 4000 && $this->contentFormat == 'XHTML' ) {
 291+ $contentHtml = $this->javascriptize( $contentHtml );
 292+ } else if ( $this->contentFormat == 'WML' ) {
 293+ $contentHtml = $this->javascriptize( $contentHtml );
 294+ $contentHtml = $this->createWMLCard( $contentHtml, $title );
 295+ require( 'views/layout/application.wml.php' );
 296+ }
 297+
 298+ if ( $this->contentFormat == 'XHTML' ) {
 299+ require( 'views/notices/_donate.html.php' );
 300+ require( 'views/layout/_search_webkit.html.php' );
 301+ require( 'views/layout/_footmenu_default.html.php' );
 302+ require( 'views/layout/application.html.php' );
 303+ }
 304+
 305+ return $applicationHtml;
242306 }
243307 }
244308

Comments

#Comment by 😂 (talk | contribs)   00:16, 21 May 2011
+		ExtPatchOutputMobile::$dir = $GLOBALS['wgContLang']->isRTL()  ? "rtl" : "ltr";

Use $wgContLang->getDir(). Also as a general note, we typically declare globals at the beginning of the function, rather than using the $GLOBALS superglobal. Also, I'm not entirely sure why "$GLOBALS['headings'] = $headings;" is necessary in showHideCallbackWML(). The other uses of $headings seem to be static local variables and not this global reference.

#Comment by Preilly (talk | contribs)   00:24, 21 May 2011

I'm using $GLOBALS['headings'] in the javascriptize method based on what is set in the previous method.

#Comment by 😂 (talk | contribs)   00:32, 21 May 2011

Ah ok, didn't look that far into it.

#Comment by Preilly (talk | contribs)   00:33, 21 May 2011

FYI: I also fixed the other things that you mentioned in my latest commit.

Status & tagging log