r111205 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111204‎ | r111205 | r111206 >
Date:22:06, 10 February 2012
Author:maxsem
Status:ok
Tags:
Comment:
Sketch of action=parse extended by MobileFrontend, doesn't work yet
Modified paths:
  • /trunk/extensions/MobileFrontend/DomManipulator.php (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.body.php (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/DomManipulator.php
@@ -11,6 +11,11 @@
1212 protected $format;
1313 protected $removeImages = false;
1414 protected $idWhitelist = array();
 15+ /**
 16+ * Message cache, false if they should be loaded dynamically
 17+ * @var Array|bool
 18+ */
 19+ protected $messages = false;
1520
1621 private static $defaultItemsToRemove = array(
1722 '#contentSub',
@@ -63,6 +68,14 @@
6469 }
6570
6671 /**
 72+ * Use the given message cache
 73+ * @param Array $messages
 74+ */
 75+ public function useMessages( Array $messages ) {
 76+ $this->messages = $messages;
 77+ }
 78+
 79+ /**
6780 * @return DOMDocument: DOM to manipulate
6881 */
6982 public function getDoc() {
@@ -195,7 +208,26 @@
196209 wfProfileOut( __METHOD__ );
197210 }
198211
 212+ public function getText( $id = false ) {
 213+ $element = $id ? $this->doc->getElementById( $id ) : null;
 214+ return $this->doc->saveXML( $element, LIBXML_NOEMPTYTAG );
 215+ }
 216+
199217 /**
 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+ /**
200232 * @return array
201233 */
202234 private function parseItemsToRemove() {
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php
@@ -474,16 +474,8 @@
475475
476476 self::$device = $device->format( $formatName );
477477
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'] );
483479
484 - if ( self::$useFormat === 'mobile-wap' ) {
485 - $this->contentFormat = 'WML';
486 - }
487 -
488480 if ( $mobileAction == 'leave_feedback' ) {
489481 echo $this->renderLeaveFeedbackXHTML();
490482 wfProfileOut( __METHOD__ );
@@ -572,6 +564,18 @@
573565 return true;
574566 }
575567
 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+
576580 /**
577581 * @return bool
578582 */
@@ -1216,6 +1220,7 @@
12171221 wfProfileIn( __METHOD__ );
12181222
12191223 $manipulator = new DomManipulator( $html, $this->contentFormat );
 1224+ $manipulator->useMessages( self::$messages );
12201225 $doc = $manipulator->getDoc();
12211226
12221227 $zeroRatedBannerElement = $doc->getElementById( 'zero-rated-banner' );
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -43,8 +43,10 @@
4444
4545 $autoloadClasses = array (
4646 'ExtMobileFrontend' => 'MobileFrontend.body',
 47+
 48+ 'ApiParseExtender' => 'ApiParseExtender',
 49+ 'CssDetection' => 'CssDetection',
4750 'DeviceDetection' => 'DeviceDetection',
48 - 'CssDetection' => 'CssDetection',
4951 'DomManipulator' => 'DomManipulator',
5052
5153 'MobileFrontendTemplate' => 'templates/MobileFrontendTemplate',
@@ -85,6 +87,9 @@
8688
8789 $wgExtensionFunctions[] = 'efMobileFrontend_Setup';
8890
 91+$wgHooks['APIGetAllowedParams'][] = 'ApiParseExtender::onAPIGetAllowedParams';
 92+$wgHooks['APIAfterExecute'][] = 'ApiParseExtender::onAPIAfterExecute';
 93+
8994 function efMobileFrontend_Setup() {
9095 global $wgExtMobileFrontend, $wgHooks;
9196 $wgExtMobileFrontend = new ExtMobileFrontend();

Follow-up revisions

RevisionCommit summaryAuthorDate
r111227Follow-up r111205: forgot to add a file, fixed a fatal in non-API execution pathmaxsem07:09, 11 February 2012

Status & tagging log