* @param int $limit Maximum items to return
* @param array $namespaces Namespaces to search
* @param bool $resolveRedir Whether to resolve redirects
- * @param array &$results Put results here
+ * @param array &$results Put results here. Keys have to be integers.
*/
protected function search( $search, $limit, $namespaces, $resolveRedir, &$results ) {
// Find matching titles as Title objects
return;
}
+ // Special pages need unique integer ids in the return list, so we just
+ // assign them negative numbers because those won't clash with the
+ // always positive articleIds that non-special pages get.
+ $nextSpecialPageId = -1;
+
if ( $resolveRedir ) {
// Query for redirects
$db = $this->getDb();
}
if ( !isset( $seen[$ns][$dbkey] ) ) {
$seen[$ns][$dbkey] = true;
- $results[$title->getArticleId()] = array(
+ $resultId = $title->getArticleId();
+ if ( $resultId === 0 ) {
+ $resultId = $nextSpecialPageId;
+ $nextSpecialPageId -= 1;
+ }
+ $results[$resultId] = array(
'title' => $title,
'redirect from' => $from,
'extract' => false,
}
} else {
foreach ( $titles as $title ) {
- $results[$title->getArticleId()] = array(
+ $resultId = $title->getArticleId();
+ if ( $resultId === 0 ) {
+ $resultId = $nextSpecialPageId;
+ $nextSpecialPageId -= 1;
+ }
+ $results[$resultId] = array(
'title' => $title,
'redirect from' => null,
'extract' => false,