X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiOpenSearch.php;h=5ce43ccead764b7c4fb01a086037d8c25cab0839;hb=1e296da3d7da4bf095ae228d7f5890f7ef520873;hp=a93b7cc6989d206cfd0ec72aae239aafb8dc738e;hpb=6989663bbc53c59e0f931a9f112798ea9cccd5e4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index a93b7cc698..5ce43ccead 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -140,7 +140,7 @@ class ApiOpenSearch extends ApiBase { $redirects = array(); $lb = new LinkBatch( $titles ); if ( !$lb->isEmpty() ) { - $db = $this->getDb(); + $db = $this->getDB(); $res = $db->select( array( 'page', 'redirect' ), array( 'page_namespace', 'page_title', 'rd_namespace', 'rd_title' ), @@ -170,7 +170,7 @@ class ApiOpenSearch extends ApiBase { } if ( !isset( $seen[$ns][$dbkey] ) ) { $seen[$ns][$dbkey] = true; - $resultId = $title->getArticleId(); + $resultId = $title->getArticleID(); if ( $resultId === 0 ) { $resultId = $nextSpecialPageId; $nextSpecialPageId -= 1; @@ -181,7 +181,7 @@ class ApiOpenSearch extends ApiBase { 'extract' => false, 'extract trimmed' => false, 'image' => false, - 'url' => wfExpandUrl( $title->getFullUrl(), PROTO_CURRENT ), + 'url' => wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ), ); } } @@ -311,7 +311,7 @@ class ApiOpenSearch extends ApiBase { * Extension:ActiveAbstract. * * @param string $text - * @param int $len Target length; actual result will continue to the end of a sentence. + * @param int $length Target length; actual result will continue to the end of a sentence. * @return string */ public static function trimExtract( $text, $length ) { @@ -384,13 +384,25 @@ class ApiOpenSearchFormatJson extends ApiFormatJson { public function execute() { if ( !$this->getResult()->getResultData( 'error' ) ) { - $warnings = $this->getResult()->removeValue( 'warnings', null ); + $result = $this->getResult(); + + // Ignore warnings or treat as errors, as requested + $warnings = $result->removeValue( 'warnings', null ); if ( $this->warningsAsError && $warnings ) { $this->dieUsage( 'Warnings cannot be represented in OpenSearch JSON format', 'warnings', 0, array( 'warnings' => $warnings ) ); } + + // Ignore any other unexpected keys (e.g. from $wgDebugToolbar) + $remove = array_keys( array_diff_key( + $result->getResultData(), + array( 0 => 'search', 1 => 'terms', 2 => 'descriptions', 3 => 'urls' ) + ) ); + foreach ( $remove as $key ) { + $result->removeValue( $key, null ); + } } parent::execute();