Add i18n for the infamous "Fatal exception of type MWException" errorbox
[lhc/web/wiklou.git] / includes / api / ApiQueryPrefixSearch.php
index 3c90acc..069e30b 100644 (file)
@@ -43,15 +43,21 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase {
                $search = $params['search'];
                $limit = $params['limit'];
                $namespaces = $params['namespace'];
+               $offset = $params['offset'];
 
                $searcher = new TitlePrefixSearch;
-               $titles = $searcher->searchWithVariants( $search, $limit, $namespaces );
+               $titles = $searcher->searchWithVariants( $search, $limit + 1, $namespaces, $offset );
                if ( $resultPageSet ) {
                        $resultPageSet->populateFromTitles( $titles );
+                       foreach ( $titles as $index => $title ) {
+                               $resultPageSet->setGeneratorData( $title, array( 'index' => $index + $offset + 1 ) );
+                       }
                } else {
                        $result = $this->getResult();
+                       $count = 0;
                        foreach ( $titles as $title ) {
-                               if ( !$limit-- ) {
+                               if ( ++$count > $limit ) {
+                                       $this->setContinueEnumParameter( 'offset', $offset + $params['limit'] );
                                        break;
                                }
                                $vals = array(
@@ -65,6 +71,7 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase {
                                }
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                                if ( !$fit ) {
+                                       $this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
                                        break;
                                }
                        }
@@ -97,6 +104,10 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase {
                                        ApiBase::PARAM_MAX => 100,
                                        ApiBase::PARAM_MAX2 => 200,
                                ),
+                               'offset' => array(
+                                       ApiBase::PARAM_DFLT => 0,
+                                       ApiBase::PARAM_TYPE => 'integer',
+                               ),
                        );
        }