http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96555
Revision: 96555
Author: svemir
Date: 2011-09-08 12:23:06 +0000 (Thu, 08 Sep 2011)
Log Message:
-----------
streamlined preparePrefixRegexp and used preg_quote when building a regexp
Modified Paths:
--------------
trunk/extensions/SphinxSearch/SphinxMWSearch.php
Modified: trunk/extensions/SphinxSearch/SphinxMWSearch.php
===================================================================
--- trunk/extensions/SphinxSearch/SphinxMWSearch.php 2011-09-08 11:21:14 UTC
(rev 96554)
+++ trunk/extensions/SphinxSearch/SphinxMWSearch.php 2011-09-08 12:23:06 UTC
(rev 96555)
@@ -19,7 +19,6 @@
var $db;
var $sphinx_client = null;
var $prefix_handlers = array(
- 'all' => 'searchAllNamespaces',
'intitle' => 'filterByTitle',
'incategory' => 'filterByCategory',
'prefix' => 'filterByPrefix',
@@ -216,28 +215,25 @@
function preparePrefixRegexp() {
global $wgContLang, $wgCanonicalNamespaceNames,
$wgNamespaceAliases;
- $nsNamesRaw = array_merge(
+ // "search everything" keyword
+ $allkeyword = wfMsgForContent( 'searchall' );
+ $this->prefix_handlers[ $allkeyword ] = 'searchAllNamespaces';
+
+ $all_prefixes = array_merge(
$wgContLang->getNamespaces(),
$wgCanonicalNamespaceNames,
- array_keys( array_merge( $wgNamespaceAliases,
$wgContLang->getNamespaceAliases() ) )
+ array_keys( array_merge( $wgNamespaceAliases,
$wgContLang->getNamespaceAliases() ) ),
+ array_keys( $this->prefix_handlers )
);
- // add all namespace names w/o spaces
- $nsNames = array();
- foreach ( $nsNamesRaw as $ns ) {
- if ( $ns != '' ) {
- $nsNames[] = str_replace( ' ', '_', $ns );
+ $regexp_prefixes = array();
+ foreach ( $all_prefixes as $prefix ) {
+ if ( $prefix != '' ) {
+ $regexp_prefixes[] = preg_quote( str_replace( '
', '_', $prefix ) );
}
}
- // "search everything" keyword
- $allkeyword = wfMsgForContent( 'searchall' );
- $this->prefix_handlers[ $allkeyword ] = 'searchAllNamespaces';
-
- // add other kinds of prefixes we support
- $nsNames = array_merge( $nsNames, array_keys(
$this->prefix_handlers ) );
-
- return implode( '|', array_unique( $nsNames ) );
+ return implode( '|', array_unique( $regexp_prefixes ) );
}
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs