r111228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111227‎ | r111228 | r111229 >
Date:07:54, 11 February 2012
Author:maxsem
Status:ok
Tags:
Comment:
* Made mobile format non-compulsory
* Full param info
Modified paths:
  • /trunk/extensions/MobileFrontend/ApiParseExtender.php (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/ApiParseExtender.php
@@ -1,24 +1,61 @@
22 <?php
33
44 /**
5 - *
 5+ * Extends API action=parse with mobile goodies
66 */
77 class ApiParseExtender {
 8+ /**
 9+ * APIGetAllowedParams hook handler
 10+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/APIGetAllowedParams
 11+ * @param ApiBase $module
 12+ * @param array $params
 13+ */
814 public static function onAPIGetAllowedParams( ApiBase &$module, Array &$params ) {
915 if ( $module->getModuleName() == 'parse' ) {
1016 $params['mobileformat'] = array(
1117 ApiBase::PARAM_TYPE => array( 'wml', 'html' ),
12 - ApiBase::PARAM_DFLT => 'html',
1318 );
1419 }
1520 return true;
1621 }
1722
 23+ /**
 24+ * APIGetParamDescription hook handler
 25+ * @see: https://www.mediawiki.org/wiki/Manual:Hooks/APIGetParamDescription
 26+ * @param ApiBase $module
 27+ * @param Array $desc
 28+ */
 29+ public static function onAPIGetParamDescription( ApiBase &$module, Array &$params ) {
 30+ if ( $module->getModuleName() == 'parse' ) {
 31+ $params['mobileformat'] = 'Return parse output in a format suitable for mobile devices';
 32+ }
 33+ return true;
 34+ }
 35+
 36+ /**
 37+ * APIGetDescription hook handler
 38+ * @see: https://www.mediawiki.org/wiki/Manual:Hooks/APIGetDescription
 39+ * @param ApiBase $module
 40+ * @param Array|string $desc
 41+ */
 42+ public static function onAPIGetDescription( ApiBase &$module, &$desc ) {
 43+ if ( $module->getModuleName() == 'parse' ) {
 44+ $desc= (array)$desc;
 45+ $desc[] = 'Extended by MobileFrontend';
 46+ }
 47+ return true;
 48+ }
 49+
 50+ /**
 51+ * APIAfterExecute hook handler
 52+ * @see: https://www.mediawiki.org/wiki/Manual:Hooks/
 53+ * @param ApiBase $module
 54+ */
1855 public static function onAPIAfterExecute( ApiBase &$module ) {
1956 if ( $module->getModuleName() == 'parse' ) {
2057 $data = $module->getResultData();
21 - if ( isset( $data['parse']['text'] ) ) {
22 - $params = $module->extractRequestParams();
 58+ $params = $module->extractRequestParams();
 59+ if ( isset( $data['parse']['text'] ) && isset( $params['mobileformat'] ) ) {
2360 $mf = new DomManipulator( '<body><div id="content">' . $data['parse']['text']['*'] . '</div></body>',
2461 ExtMobileFrontend::parseContentFormat( $params['mobileformat'] )
2562 );
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -89,6 +89,8 @@
9090
9191 $wgHooks['APIGetAllowedParams'][] = 'ApiParseExtender::onAPIGetAllowedParams';
9292 $wgHooks['APIAfterExecute'][] = 'ApiParseExtender::onAPIAfterExecute';
 93+$wgHooks['APIGetParamDescription'][] = 'ApiParseExtender::onAPIGetParamDescription';
 94+$wgHooks['APIGetDescription'][] = 'ApiParseExtender::onAPIGetDescription';
9395
9496 function efMobileFrontend_Setup() {
9597 global $wgExtMobileFrontend, $wgHooks;

Status & tagging log