Index: trunk/extensions/MobileFrontend/ApiParseExtender.php |
— | — | @@ -1,24 +1,61 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * |
| 5 | + * Extends API action=parse with mobile goodies |
6 | 6 | */ |
7 | 7 | 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 | + */ |
8 | 14 | public static function onAPIGetAllowedParams( ApiBase &$module, Array &$params ) { |
9 | 15 | if ( $module->getModuleName() == 'parse' ) { |
10 | 16 | $params['mobileformat'] = array( |
11 | 17 | ApiBase::PARAM_TYPE => array( 'wml', 'html' ), |
12 | | - ApiBase::PARAM_DFLT => 'html', |
13 | 18 | ); |
14 | 19 | } |
15 | 20 | return true; |
16 | 21 | } |
17 | 22 | |
| 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 | + */ |
18 | 55 | public static function onAPIAfterExecute( ApiBase &$module ) { |
19 | 56 | if ( $module->getModuleName() == 'parse' ) { |
20 | 57 | $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'] ) ) { |
23 | 60 | $mf = new DomManipulator( '<body><div id="content">' . $data['parse']['text']['*'] . '</div></body>', |
24 | 61 | ExtMobileFrontend::parseContentFormat( $params['mobileformat'] ) |
25 | 62 | ); |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -89,6 +89,8 @@ |
90 | 90 | |
91 | 91 | $wgHooks['APIGetAllowedParams'][] = 'ApiParseExtender::onAPIGetAllowedParams'; |
92 | 92 | $wgHooks['APIAfterExecute'][] = 'ApiParseExtender::onAPIAfterExecute'; |
| 93 | +$wgHooks['APIGetParamDescription'][] = 'ApiParseExtender::onAPIGetParamDescription'; |
| 94 | +$wgHooks['APIGetDescription'][] = 'ApiParseExtender::onAPIGetDescription'; |
93 | 95 | |
94 | 96 | function efMobileFrontend_Setup() { |
95 | 97 | global $wgExtMobileFrontend, $wgHooks; |