From 233fb62e225b3b5494959c9bcd85c927e2f2f598 Mon Sep 17 00:00:00 2001 From: Philip Tzou Date: Wed, 5 Jan 2011 16:21:01 +0000 Subject: [PATCH] Add fallback languages support for ApiOpenSearch. --- includes/api/ApiOpenSearch.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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(); -- 2.20.1