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 |
1 | 17 | + native |
Index: trunk/extensions/PatchOutputMobile/views/layout/application.html.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | $applicationHtml = <<<EOT |
4 | 4 | <!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'> |
6 | 6 | <head> |
7 | 7 | <title>{$title}</title> |
8 | 8 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php |
— | — | @@ -27,11 +27,16 @@ |
28 | 28 | 'onOutputPageBeforeHTML' ); |
29 | 29 | |
30 | 30 | class ExtPatchOutputMobile { |
31 | | - const VERSION = '0.2.6'; |
| 31 | + const VERSION = '0.2.7'; |
32 | 32 | |
33 | 33 | private $doc; |
34 | 34 | |
35 | 35 | public static $messages = array(); |
| 36 | + |
| 37 | + public $contentFormat = 'XHTML'; //'WML' |
| 38 | + public $WMLSectionSeperator = '***************************************************************************'; |
| 39 | + public static $dir; |
| 40 | + public static $code; |
36 | 41 | |
37 | 42 | public $itemsToRemove = array( |
38 | 43 | '#contentSub', # redirection notice |
— | — | @@ -71,12 +76,29 @@ |
72 | 77 | ExtPatchOutputMobile::$messages['patch-output-mobile-show'] = wfMsg( 'patch-output-mobile-show' ); |
73 | 78 | ExtPatchOutputMobile::$messages['patch-output-mobile-hide'] = wfMsg( 'patch-output-mobile-hide' ); |
74 | 79 | 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(); |
75 | 82 | |
76 | 83 | ob_start( array( $this, 'parse' ) ); |
77 | 84 | return true; |
78 | 85 | } |
| 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; |
79 | 93 | |
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 ) { |
81 | 103 | static $headings = 0; |
82 | 104 | $show = ExtPatchOutputMobile::$messages['patch-output-mobile-show']; |
83 | 105 | $hide = ExtPatchOutputMobile::$messages['patch-output-mobile-hide']; |
— | — | @@ -87,8 +109,10 @@ |
88 | 110 | "'><a href='#section_" . intval( $headings - 1 ) . |
89 | 111 | "' class='back_to_top'>↑ {$backToTop}</a></div>"; |
90 | 112 | // 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}'>"; |
93 | 117 | |
94 | 118 | if ( $headings > 1 ) { |
95 | 119 | // Close it up here |
— | — | @@ -101,12 +125,15 @@ |
102 | 126 | } |
103 | 127 | |
104 | 128 | public function javascriptize( $s ) { |
| 129 | + $callback = 'showHideCallback'; |
| 130 | + $callback .= $this->contentFormat; |
| 131 | + |
105 | 132 | // Closures are a PHP 5.3 feature. |
106 | 133 | // MediaWiki currently requires PHP 5.2.3 or higher. |
107 | 134 | // So, using old style for now. |
108 | 135 | $s = preg_replace_callback( |
109 | 136 | '/<h2(.*)<span class="mw-headline" [^>]*>(.+)<\/span>\w*<\/h2>/', |
110 | | - array( $this, 'showHideCallback' ), |
| 137 | + array( $this, $callback ), |
111 | 138 | $s |
112 | 139 | ); |
113 | 140 | |
— | — | @@ -121,7 +148,31 @@ |
122 | 149 | |
123 | 150 | return $s; |
124 | 151 | } |
| 152 | + |
| 153 | + private function createWMLCard( $s, $title = '' ) { |
| 154 | + $segments = explode( $this->WMLSectionSeperator, $s ); |
| 155 | + $card = ''; |
| 156 | + $idx = 0; |
125 | 157 | |
| 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 | + |
126 | 177 | public function parse( $s ) { |
127 | 178 | return $this->DOMParse( $s ); |
128 | 179 | } |
— | — | @@ -141,10 +192,11 @@ |
142 | 193 | |
143 | 194 | public function DOMParse( $html ) { |
144 | 195 | libxml_use_internal_errors( true ); |
145 | | - $this->doc = DOMDocument::loadHTML( $html ); |
| 196 | + $this->doc = DOMDocument::loadHTML( '<?xml encoding="UTF-8">' . $html ); |
146 | 197 | libxml_use_internal_errors( false ); |
147 | 198 | $this->doc->preserveWhiteSpace = false; |
148 | 199 | $this->doc->strictErrorChecking = false; |
| 200 | + $this->doc->encoding = 'UTF-8'; |
149 | 201 | |
150 | 202 | $itemToRemoveRecords = $this->parseItemsToRemove(); |
151 | 203 | |
— | — | @@ -223,7 +275,6 @@ |
224 | 276 | |
225 | 277 | $redLink->parentNode->replaceChild( $spanNode, $redLink ); |
226 | 278 | } |
227 | | - |
228 | 279 | $content = $this->doc->getElementById( 'content' ); |
229 | 280 | |
230 | 281 | $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |
— | — | @@ -231,13 +282,26 @@ |
232 | 283 | if ( empty( $title ) ) { |
233 | 284 | $title = 'Wikipedia'; |
234 | 285 | } |
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; |
242 | 306 | } |
243 | 307 | } |
244 | 308 | |