summaryrefslogtreecommitdiff
path: root/includes/PrefixSearch.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
committerPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
commit222b01f5169f1c7e69762e0e8904c24f78f71882 (patch)
tree8e932e12546bb991357ec48eb1638d1770be7a35 /includes/PrefixSearch.php
parent00ab76a6b686e98a914afc1975812d2b1aaa7016 (diff)
update to MediaWiki 1.16.0
Diffstat (limited to 'includes/PrefixSearch.php')
-rw-r--r--includes/PrefixSearch.php53
1 files changed, 31 insertions, 22 deletions
diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php
index 10c85930..930b29d4 100644
--- a/includes/PrefixSearch.php
+++ b/includes/PrefixSearch.php
@@ -3,17 +3,18 @@
/**
* PrefixSearch - Handles searching prefixes of titles and finding any page
* names that match. Used largely by the OpenSearch implementation.
- *
+ *
* @ingroup Search
*/
class PrefixSearch {
/**
* Do a prefix search of titles and return a list of matching page names.
- * @param string $search
- * @param int $limit
- * @param array $namespaces - used if query is not explicitely prefixed
- * @return array of strings
+ *
+ * @param $search String
+ * @param $limit Integer
+ * @param $namespaces Array: used if query is not explicitely prefixed
+ * @return Array of strings
*/
public static function titleSearch( $search, $limit, $namespaces=array() ) {
$search = trim( $search );
@@ -21,11 +22,11 @@ class PrefixSearch {
return array(); // Return empty result
}
$namespaces = self::validateNamespaces( $namespaces );
-
+
$title = Title::newFromText( $search );
if( $title && $title->getInterwiki() == '' ) {
$ns = array($title->getNamespace());
- if($ns[0] == NS_MAIN)
+ if($ns[0] == NS_MAIN)
$ns = $namespaces; // no explicit prefix, use default namespaces
return self::searchBackend(
$ns, $title->getText(), $limit );
@@ -39,17 +40,17 @@ class PrefixSearch {
return self::searchBackend(
array($title->getNamespace()), '', $limit );
}
-
+
return self::searchBackend( $namespaces, $search, $limit );
}
/**
* Do a prefix search of titles and return a list of matching page names.
- * @param array $namespaces
- * @param string $search
- * @param int $limit
- * @return array of strings
+ * @param $namespaces Array
+ * @param $search String
+ * @param $limit Integer
+ * @return Array of strings
*/
protected static function searchBackend( $namespaces, $search, $limit ) {
if( count($namespaces) == 1 ){
@@ -69,6 +70,10 @@ class PrefixSearch {
/**
* Prefix search special-case for Special: namespace.
+ *
+ * @param $search String: term
+ * @param $limit Integer: max number of items to return
+ * @return Array
*/
protected static function specialSearch( $search, $limit ) {
global $wgContLang;
@@ -83,6 +88,9 @@ class PrefixSearch {
$keys[$wgContLang->caseFold( $page )] = $page;
}
foreach( $wgContLang->getSpecialPageAliases() as $page => $aliases ) {
+ if( !array_key_exists( $page, SpecialPage::$mList ) ) # bug 20885
+ continue;
+
foreach( $aliases as $alias ) {
$keys[$wgContLang->caseFold( $alias )] = $alias;
}
@@ -107,16 +115,16 @@ class PrefixSearch {
* be automatically capitalized by Title::secureAndSpit()
* later on depending on $wgCapitalLinks)
*
- * @param array $namespaces Namespaces to search in
- * @param string $search term
- * @param int $limit max number of items to return
- * @return array of title strings
+ * @param $namespaces Array: namespaces to search in
+ * @param $search String: term
+ * @param $limit Integer: max number of items to return
+ * @return Array of title strings
*/
protected static function defaultSearchBackend( $namespaces, $search, $limit ) {
$ns = array_shift($namespaces); // support only one namespace
if( in_array(NS_MAIN,$namespaces))
- $ns = NS_MAIN; // if searching on many always default to main
-
+ $ns = NS_MAIN; // if searching on many always default to main
+
// Prepare nested request
$req = new FauxRequest(array (
'action' => 'query',
@@ -143,11 +151,12 @@ class PrefixSearch {
return $srchres;
}
-
+
/**
* Validate an array of numerical namespace indexes
- *
- * @param array $namespaces
+ *
+ * @param $namespaces Array
+ * @return Array
*/
protected static function validateNamespaces($namespaces){
global $wgContLang;
@@ -161,7 +170,7 @@ class PrefixSearch {
if( count($valid) > 0 )
return $valid;
}
-
+
return array( NS_MAIN );
}
}