r79649 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79648‎ | r79649 | r79650 >
Date:16:21, 5 January 2011
Author:philip
Status:resolved (Comments)
Tags:
Comment:
Add fallback languages support for ApiOpenSearch.
Modified paths:
  • /trunk/phase3/includes/api/ApiOpenSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiOpenSearch.php
@@ -61,6 +61,21 @@
6262
6363 $srchres = PrefixSearch::titleSearch( $search, $limit,
6464 $namespaces );
 65+
 66+ // if the content language has variants, try to retrieve fallback results
 67+ if ( ( $fblimit = $limit - count( $srchres ) ) > 0 ) {
 68+ global $wgContLang;
 69+ $fbsearchs = $wgContLang->autoConvertToAllVariants( $search );
 70+ $fbsearchs = array_diff( array_unique( $fbsearchs ), ( array ) $search );
 71+ foreach ( $fbsearchs as $fbsearch ) {
 72+ $_srchres = PrefixSearch::titleSearch( $fbsearch, $fblimit,
 73+ $namespaces );
 74+ $srchres = array_merge( $srchres, $_srchres );
 75+ if ( ( $fblimit -= - count( $_srchres ) ) == 0 ) {
 76+ break;
 77+ }
 78+ }
 79+ }
6580 }
6681 // Set top level elements
6782 $result = $this->getResult();

Follow-up revisions

RevisionCommit summaryAuthorDate
r79650follow r79649, move the in-block assignment outside.philip16:30, 5 January 2011
r79651Follow r79649 and r79650. Errrr, remove the redundant minusphilip16:37, 5 January 2011
r79694Minor followup to r79649. Rename variablesreedy00:31, 6 January 2011
r797201.17: MFT r79578, r79591, r79593, r79595, r79649, r79650, r79651, r79653, r79...catrope14:48, 6 January 2011

Comments

#Comment by 😂 (talk | contribs)   16:22, 5 January 2011

Please don't use the assignment in the if blocks, it's harder to read.

#Comment by PhiLiP (talk | contribs)   16:32, 5 January 2011

Sorry for overwriting the status. Moved out in r79650.

#Comment by Catrope (talk | contribs)   16:33, 5 January 2011

Setting a rev back to new when all fixme comments have been addressed is very commonly done. Setting back to new.

#Comment by PhiLiP (talk | contribs)   16:28, 5 January 2011

Add tag 1.17 because it's a minor revision to the API interface, and the function has been asked frequently on Chinese Wikipedia.

Status & tagging log