From: Philip Tzou Date: Wed, 5 Jan 2011 16:21:01 +0000 (+0000) Subject: Add fallback languages support for ApiOpenSearch. X-Git-Tag: 1.31.0-rc.0~32807 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=233fb62e225b3b5494959c9bcd85c927e2f2f598;p=lhc%2Fweb%2Fwiklou.git Add fallback languages support for ApiOpenSearch. --- diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 9f2bae0fea..8b382a41a9 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -61,6 +61,21 @@ class ApiOpenSearch extends ApiBase { $srchres = PrefixSearch::titleSearch( $search, $limit, $namespaces ); + + // if the content language has variants, try to retrieve fallback results + if ( ( $fblimit = $limit - count( $srchres ) ) > 0 ) { + global $wgContLang; + $fbsearchs = $wgContLang->autoConvertToAllVariants( $search ); + $fbsearchs = array_diff( array_unique( $fbsearchs ), ( array ) $search ); + foreach ( $fbsearchs as $fbsearch ) { + $_srchres = PrefixSearch::titleSearch( $fbsearch, $fblimit, + $namespaces ); + $srchres = array_merge( $srchres, $_srchres ); + if ( ( $fblimit -= - count( $_srchres ) ) == 0 ) { + break; + } + } + } } // Set top level elements $result = $this->getResult();