Index: trunk/extensions/MobileFrontend/DomManipulator.php |
— | — | @@ -11,6 +11,11 @@ |
12 | 12 | protected $format; |
13 | 13 | protected $removeImages = false; |
14 | 14 | protected $idWhitelist = array(); |
| 15 | + /** |
| 16 | + * Message cache, false if they should be loaded dynamically |
| 17 | + * @var Array|bool |
| 18 | + */ |
| 19 | + protected $messages = false; |
15 | 20 | |
16 | 21 | private static $defaultItemsToRemove = array( |
17 | 22 | '#contentSub', |
— | — | @@ -63,6 +68,14 @@ |
64 | 69 | } |
65 | 70 | |
66 | 71 | /** |
| 72 | + * Use the given message cache |
| 73 | + * @param Array $messages |
| 74 | + */ |
| 75 | + public function useMessages( Array $messages ) { |
| 76 | + $this->messages = $messages; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
67 | 80 | * @return DOMDocument: DOM to manipulate |
68 | 81 | */ |
69 | 82 | public function getDoc() { |
— | — | @@ -195,7 +208,26 @@ |
196 | 209 | wfProfileOut( __METHOD__ ); |
197 | 210 | } |
198 | 211 | |
| 212 | + public function getText( $id = false ) { |
| 213 | + $element = $id ? $this->doc->getElementById( $id ) : null; |
| 214 | + return $this->doc->saveXML( $element, LIBXML_NOEMPTYTAG ); |
| 215 | + } |
| 216 | + |
199 | 217 | /** |
| 218 | + * Returns interface message text |
| 219 | + * @param string $key: Message key |
| 220 | + * @return string |
| 221 | + */ |
| 222 | + protected function msg( $key ) { |
| 223 | + if ( !$this->messages ) { |
| 224 | + return wfMsg( $key ); |
| 225 | + } elseif ( isset( $this->messages[$key] ) ) { |
| 226 | + return $this->messages[$key]; |
| 227 | + } |
| 228 | + throw new MWException( __METHOD__ . ": unrecognised message key '$key' in cached mode" ); |
| 229 | + } |
| 230 | + |
| 231 | + /** |
200 | 232 | * @return array |
201 | 233 | */ |
202 | 234 | private function parseItemsToRemove() { |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -474,16 +474,8 @@ |
475 | 475 | |
476 | 476 | self::$device = $device->format( $formatName ); |
477 | 477 | |
478 | | - if ( self::$device['view_format'] === 'wml' ) { |
479 | | - $this->contentFormat = 'WML'; |
480 | | - } elseif ( self::$device['view_format'] === 'html' ) { |
481 | | - $this->contentFormat = 'XHTML'; |
482 | | - } |
| 478 | + $this->contentFormat = self::parseContentFormat( self::$device['view_format'] ); |
483 | 479 | |
484 | | - if ( self::$useFormat === 'mobile-wap' ) { |
485 | | - $this->contentFormat = 'WML'; |
486 | | - } |
487 | | - |
488 | 480 | if ( $mobileAction == 'leave_feedback' ) { |
489 | 481 | echo $this->renderLeaveFeedbackXHTML(); |
490 | 482 | wfProfileOut( __METHOD__ ); |
— | — | @@ -572,6 +564,18 @@ |
573 | 565 | return true; |
574 | 566 | } |
575 | 567 | |
| 568 | + public static function parseOutputFormat( $format ) { |
| 569 | + if ( $format === 'wml' ) { |
| 570 | + return 'WML'; |
| 571 | + } elseif ( $format === 'html' ) { |
| 572 | + return 'XHTML'; |
| 573 | + } |
| 574 | + if ( $format === 'mobile-wap' ) { |
| 575 | + return 'WML'; |
| 576 | + } |
| 577 | + return 'XHTML';//@todo: |
| 578 | + } |
| 579 | + |
576 | 580 | /** |
577 | 581 | * @return bool |
578 | 582 | */ |
— | — | @@ -1216,6 +1220,7 @@ |
1217 | 1221 | wfProfileIn( __METHOD__ ); |
1218 | 1222 | |
1219 | 1223 | $manipulator = new DomManipulator( $html, $this->contentFormat ); |
| 1224 | + $manipulator->useMessages( self::$messages ); |
1220 | 1225 | $doc = $manipulator->getDoc(); |
1221 | 1226 | |
1222 | 1227 | $zeroRatedBannerElement = $doc->getElementById( 'zero-rated-banner' ); |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -43,8 +43,10 @@ |
44 | 44 | |
45 | 45 | $autoloadClasses = array ( |
46 | 46 | 'ExtMobileFrontend' => 'MobileFrontend.body', |
| 47 | + |
| 48 | + 'ApiParseExtender' => 'ApiParseExtender', |
| 49 | + 'CssDetection' => 'CssDetection', |
47 | 50 | 'DeviceDetection' => 'DeviceDetection', |
48 | | - 'CssDetection' => 'CssDetection', |
49 | 51 | 'DomManipulator' => 'DomManipulator', |
50 | 52 | |
51 | 53 | 'MobileFrontendTemplate' => 'templates/MobileFrontendTemplate', |
— | — | @@ -85,6 +87,9 @@ |
86 | 88 | |
87 | 89 | $wgExtensionFunctions[] = 'efMobileFrontend_Setup'; |
88 | 90 | |
| 91 | +$wgHooks['APIGetAllowedParams'][] = 'ApiParseExtender::onAPIGetAllowedParams'; |
| 92 | +$wgHooks['APIAfterExecute'][] = 'ApiParseExtender::onAPIAfterExecute'; |
| 93 | + |
89 | 94 | function efMobileFrontend_Setup() { |
90 | 95 | global $wgExtMobileFrontend, $wgHooks; |
91 | 96 | $wgExtMobileFrontend = new ExtMobileFrontend(); |