Index: LinkSearch.php =================================================================== --- LinkSearch.php (revision 17406) +++ LinkSearch.php (working copy) @@ -23,8 +23,19 @@ /*function*/ false, /*file*/ false ); class LinkSearchPage extends QueryPage { - function __construct( $query ) { + /// Query + private $mQuery; + /// Namespace to search + private $mNamespace; + + /// Constructor + /** + * @param $query string Query + * @param $namespace mixed Namespace to search (int) or '' for all namespaces + */ + function __construct( $query, $namespace = '' ) { $this->mQuery = $query; + $this->mNamespace = $namespace; } function getName() { @@ -50,7 +61,7 @@ } function linkParameters() { - return array( 'target' => $this->mQuery ); + return array( 'target' => $this->mQuery, 'namespace' => $this->mNamespace ); } function getSQL() { @@ -59,6 +70,12 @@ $page = $dbr->tableName( 'page' ); $externallinks = $dbr->tableName( 'externallinks' ); + if( $this->mNamespace == '' ) { + $namespace = ''; + } else { + $namespace = 'AND page_namespace = ' . intval( $this->mNamespace ); + } + $encSearch = $dbr->addQuotes( self::mungeQuery( $this->mQuery ) ); return @@ -72,7 +89,8 @@ $externallinks FORCE INDEX (el_index) WHERE page_id=el_from - AND el_index LIKE $encSearch"; + AND el_index LIKE $encSearch + $namespace"; } function formatResult( $skin, $result ) { @@ -115,6 +133,7 @@ function wfSpecialLinksearch( $par=null ) { list( $limit, $offset ) = wfCheckLimits(); $target = $GLOBALS['wgRequest']->getVal( 'target', $par ); + $namespace = $GLOBALS['wgRequest']->getVal( 'namespace', '' ); $self = Title::makeTitle( NS_SPECIAL, 'Linksearch' ); @@ -124,12 +143,14 @@ wfOpenElement( 'form', array( 'method' => 'get', 'action' => $GLOBALS['wgScript'] ) ) . wfHidden( 'title', $self->getPrefixedDbKey() ) . - wfInput( 'target', 50, $target ) . + '

' . wfInput( 'target', 50, $target ) . "

\n" . + '

' . wfMsgExt( 'namespace', array( 'parseinline') ) . + XML::namespaceSelector( $namespace, '' ) . "

\n" . wfSubmitButton( wfMsg( 'search' ) ) . wfCloseElement( 'form' ) ); if( $target != '' ) { - $searcher = new LinkSearchPage( $target ); + $searcher = new LinkSearchPage( $target, $namespace ); $searcher->doQuery( $offset, $limit ); } }