}
}
- $target2 = $target;
+ $target2 = Parser::normalizeLinkUrl( $target );
// Get protocol, default is http://
$protocol = 'http://';
$bits = wfParseUrl( $target );
if ( $target != '' ) {
$this->setParams( [
- 'query' => Parser::normalizeLinkUrl( $target2 ),
+ 'query' => $target2,
'namespace' => $namespace,
'protocol' => $protocol ] );
parent::execute( $par );
return false;
}
- /**
- * Return an appropriately formatted LIKE query and the clause
- *
- * @param string $query Search pattern to search for
- * @param string $prot Protocol, e.g. 'http://'
- *
- * @return array
- */
- static function mungeQuery( $query, $prot ) {
- $field = 'el_index';
- $dbr = wfGetDB( DB_REPLICA );
-
- if ( $query === '*' && $prot !== '' ) {
- // Allow queries like 'ftp://*' to find all ftp links
- $rv = [ $prot, $dbr->anyString() ];
- } else {
- $rv = LinkFilter::makeLikeArray( $query, $prot );
- }
-
- if ( $rv === false ) {
- // LinkFilter doesn't handle wildcard in IP, so we'll have to munge here.
- $pattern = '/^(:?[0-9]{1,3}\.)+\*\s*$|^(:?[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]*\*\s*$/';
- if ( preg_match( $pattern, $query ) ) {
- $rv = [ $prot . rtrim( $query, " \t*" ), $dbr->anyString() ];
- $field = 'el_to';
- }
- }
-
- return [ $rv, $field ];
- }
-
function linkParameters() {
$params = [];
$params['target'] = $this->mProt . $this->mQuery;
public function getQueryInfo() {
$dbr = wfGetDB( DB_REPLICA );
- // strip everything past first wildcard, so that
- // index-based-only lookup would be done
- list( $this->mungedQuery, $clause ) = self::mungeQuery( $this->mQuery, $this->mProt );
+
+ if ( $this->mQuery === '*' && $this->mProt !== '' ) {
+ $this->mungedQuery = [
+ 'el_index_60' . $dbr->buildLike( $this->mProt, $dbr->anyString() ),
+ ];
+ } else {
+ $this->mungedQuery = LinkFilter::getQueryConditions( $this->mQuery, [
+ 'protocol' => $this->mProt,
+ 'oneWildcard' => true,
+ 'db' => $dbr
+ ] );
+ }
if ( $this->mungedQuery === false ) {
// Invalid query; return no results
return [ 'tables' => 'page', 'fields' => 'page_id', 'conds' => '0=1' ];
}
- $stripped = LinkFilter::keepOneWildcard( $this->mungedQuery );
- $like = $dbr->buildLike( $stripped );
+ $orderBy = [];
+ if ( !isset( $this->mungedQuery['el_index_60'] ) ) {
+ $orderBy[] = 'el_index_60';
+ }
+ $orderBy[] = 'el_id';
+
$retval = [
'tables' => [ 'page', 'externallinks' ],
'fields' => [
'value' => 'el_index',
'url' => 'el_to'
],
- 'conds' => [
- 'page_id = el_from',
- "$clause $like"
- ],
- 'options' => [ 'USE INDEX' => $clause ]
+ 'conds' => array_merge(
+ [
+ 'page_id = el_from',
+ ],
+ $this->mungedQuery
+ ),
+ 'options' => [ 'ORDER BY' => $orderBy ]
];
if ( $this->mNs !== null && !$this->getConfig()->get( 'MiserMode' ) ) {
/**
* Override to squash the ORDER BY.
- * We do a truncated index search, so the optimizer won't trust
- * it as good enough for optimizing sort. The implicit ordering
- * from the scan will usually do well enough for our needs.
+ * Not much point in descending order here.
* @return array
*/
function getOrderFields() {