r96555 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96554‎ | r96555 | r96556 >
Date:12:23, 8 September 2011
Author:svemir
Status:resolved (Comments)
Tags:
Comment:
streamlined preparePrefixRegexp and used preg_quote when building a regexp
Modified paths:
  • /trunk/extensions/SphinxSearch/SphinxMWSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php
@@ -19,7 +19,6 @@
2020 var $db;
2121 var $sphinx_client = null;
2222 var $prefix_handlers = array(
23 - 'all' => 'searchAllNamespaces',
2423 'intitle' => 'filterByTitle',
2524 'incategory' => 'filterByCategory',
2625 'prefix' => 'filterByPrefix',
@@ -216,28 +215,25 @@
217216 function preparePrefixRegexp() {
218217 global $wgContLang, $wgCanonicalNamespaceNames, $wgNamespaceAliases;
219218
220 - $nsNamesRaw = array_merge(
 219+ // "search everything" keyword
 220+ $allkeyword = wfMsgForContent( 'searchall' );
 221+ $this->prefix_handlers[ $allkeyword ] = 'searchAllNamespaces';
 222+
 223+ $all_prefixes = array_merge(
221224 $wgContLang->getNamespaces(),
222225 $wgCanonicalNamespaceNames,
223 - array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) )
 226+ array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) ),
 227+ array_keys( $this->prefix_handlers )
224228 );
225229
226 - // add all namespace names w/o spaces
227 - $nsNames = array();
228 - foreach ( $nsNamesRaw as $ns ) {
229 - if ( $ns != '' ) {
230 - $nsNames[] = str_replace( ' ', '_', $ns );
 230+ $regexp_prefixes = array();
 231+ foreach ( $all_prefixes as $prefix ) {
 232+ if ( $prefix != '' ) {
 233+ $regexp_prefixes[] = preg_quote( str_replace( ' ', '_', $prefix ) );
231234 }
232235 }
233236
234 - // "search everything" keyword
235 - $allkeyword = wfMsgForContent( 'searchall' );
236 - $this->prefix_handlers[ $allkeyword ] = 'searchAllNamespaces';
237 -
238 - // add other kinds of prefixes we support
239 - $nsNames = array_merge( $nsNames, array_keys( $this->prefix_handlers ) );
240 -
241 - return implode( '|', array_unique( $nsNames ) );
 237+ return implode( '|', array_unique( $regexp_prefixes ) );
242238 }
243239
244240 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r96558pass the delimiter to preg_quotesvemir12:45, 8 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96534Added support for intitle:, incategory:, and prefix: searches...svemir00:55, 8 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   12:41, 8 September 2011

You should also pass the delimiter character to preg_quote. In this case it seems to be /

#Comment by Svemir Brkic (talk | contribs)   12:46, 8 September 2011

Fixed in r96558

Status & tagging log