r113474 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113473‎ | r113474 | r113475 >
Date:15:49, 9 March 2012
Author:maxsem
Status:reverted
Tags:gerritmigration 
Comment:
Plugged MobileFrontend's excerpts into OpenSearchXml
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /trunk/extensions/MobileFrontend/api/ApiQueryExcerpts.php (modified) (history)
  • /trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php
@@ -168,6 +168,9 @@
169169
170170 if ( is_string( $result['extract'] ) ) {
171171 $extract = $result['extract'];
 172+ if ( !isset( $result['extract trimmed'] ) || !$result['extract trimmed'] ) {
 173+ $extract = $this->extractStart( $extract );
 174+ }
172175 }
173176 if ( is_array( $result['image'] ) ) {
174177 $item['Image'] = $result['image'];
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -121,6 +121,7 @@
122122 $wgHooks['APIAfterExecute'][] = 'ApiParseExtender::onAPIAfterExecute';
123123 $wgHooks['APIGetParamDescription'][] = 'ApiParseExtender::onAPIGetParamDescription';
124124 $wgHooks['APIGetDescription'][] = 'ApiParseExtender::onAPIGetDescription';
 125+$wgHooks['OpenSearchXml'][] = 'ApiQueryExcerpts::onOpenSearchXml';
125126
126127 function efMobileFrontend_Setup() {
127128 global $wgExtMobileFrontend, $wgHooks;
@@ -160,3 +161,8 @@
161162 $files[] = "$dir/MobileFormatterTest.php";
162163 return true;
163164 }
 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 @@
4747 }
4848
4949 /**
 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+ /**
5080 * Returns a processed, but not trimmed excerpt
5181 * @param Title $title
5282 * @return string
@@ -165,8 +195,8 @@
166196 ApiBase::PARAM_DFLT => 1,
167197 ApiBase::PARAM_TYPE => 'limit',
168198 ApiBase::PARAM_MIN => 1,
169 - ApiBase::PARAM_MAX => 20,
170 - ApiBase::PARAM_MAX2 => 20,
 199+ ApiBase::PARAM_MAX => 100,
 200+ ApiBase::PARAM_MAX2 => 100,
171201 ),
172202 'plaintext' => false,
173203 'continue' => array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r114401Revert r113365, r113372, r113395, r113474, r113475: unreviewed revisions in O...catrope20:27, 21 March 2012

Status & tagging log