Index: trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php |
— | — | @@ -168,6 +168,9 @@ |
169 | 169 | |
170 | 170 | if ( is_string( $result['extract'] ) ) { |
171 | 171 | $extract = $result['extract']; |
| 172 | + if ( !isset( $result['extract trimmed'] ) || !$result['extract trimmed'] ) { |
| 173 | + $extract = $this->extractStart( $extract ); |
| 174 | + } |
172 | 175 | } |
173 | 176 | if ( is_array( $result['image'] ) ) { |
174 | 177 | $item['Image'] = $result['image']; |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -121,6 +121,7 @@ |
122 | 122 | $wgHooks['APIAfterExecute'][] = 'ApiParseExtender::onAPIAfterExecute'; |
123 | 123 | $wgHooks['APIGetParamDescription'][] = 'ApiParseExtender::onAPIGetParamDescription'; |
124 | 124 | $wgHooks['APIGetDescription'][] = 'ApiParseExtender::onAPIGetDescription'; |
| 125 | +$wgHooks['OpenSearchXml'][] = 'ApiQueryExcerpts::onOpenSearchXml'; |
125 | 126 | |
126 | 127 | function efMobileFrontend_Setup() { |
127 | 128 | global $wgExtMobileFrontend, $wgHooks; |
— | — | @@ -160,3 +161,8 @@ |
161 | 162 | $files[] = "$dir/MobileFormatterTest.php"; |
162 | 163 | return true; |
163 | 164 | } |
| 165 | + |
| 166 | +/** |
| 167 | + * Whether this extension should provide its excerpts to OpenSearchXml extension |
| 168 | + */ |
| 169 | +$wgMFExtendOpenSearchXml = false; |
Index: trunk/extensions/MobileFrontend/api/ApiQueryExcerpts.php |
— | — | @@ -46,6 +46,36 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
| 50 | + * OpenSearchXml hook handler |
| 51 | + * @param array $results |
| 52 | + */ |
| 53 | + public static function onOpenSearchXml( &$results ) { |
| 54 | + global $wgMFExtendOpenSearchXml; |
| 55 | + if ( !$wgMFExtendOpenSearchXml || !count( $results ) ) { |
| 56 | + return true; |
| 57 | + } |
| 58 | + $pageIds = array_keys( $results ); |
| 59 | + $api = new ApiMain( new FauxRequest( |
| 60 | + array( |
| 61 | + 'action' => 'query', |
| 62 | + 'prop' => 'excerpts', |
| 63 | + 'explaintext' => true, |
| 64 | + 'exlimit' => count( $results ), |
| 65 | + 'pageids' => implode( '|', $pageIds ), |
| 66 | + ) ) |
| 67 | + ); |
| 68 | + $api->execute(); |
| 69 | + $data = $api->getResultData(); |
| 70 | + foreach ( $pageIds as $id ) { |
| 71 | + if ( isset( $data['query']['pages'][$id]['excerpts'][0] ) ) { |
| 72 | + $results[$id]['extract'] = $data['query']['pages'][$id]['excerpts'][0]; |
| 73 | + $results[$id]['extract trimmed'] = false; |
| 74 | + } |
| 75 | + } |
| 76 | + return true; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
50 | 80 | * Returns a processed, but not trimmed excerpt |
51 | 81 | * @param Title $title |
52 | 82 | * @return string |
— | — | @@ -165,8 +195,8 @@ |
166 | 196 | ApiBase::PARAM_DFLT => 1, |
167 | 197 | ApiBase::PARAM_TYPE => 'limit', |
168 | 198 | ApiBase::PARAM_MIN => 1, |
169 | | - ApiBase::PARAM_MAX => 20, |
170 | | - ApiBase::PARAM_MAX2 => 20, |
| 199 | + ApiBase::PARAM_MAX => 100, |
| 200 | + ApiBase::PARAM_MAX2 => 100, |
171 | 201 | ), |
172 | 202 | 'plaintext' => false, |
173 | 203 | 'continue' => array( |