Index: trunk/phase3/includes/api/ApiQueryExtLinksUsage.php |
— | — | @@ -66,20 +66,10 @@ |
67 | 67 | $this->addWhere( 'page_id=el_from' ); |
68 | 68 | $this->addWhereFld( 'page_namespace', $params['namespace'] ); |
69 | 69 | |
70 | | - if ( !is_null( $query ) || $query != '' ) { |
71 | | - if ( is_null( $protocol ) ) { |
72 | | - $protocol = 'http://'; |
73 | | - } |
| 70 | + $whereQuery = $this->prepareUrlQuerySearchString( $db, $query, $protocol ); |
74 | 71 | |
75 | | - $likeQuery = LinkFilter::makeLikeArray( $query, $protocol ); |
76 | | - if ( !$likeQuery ) { |
77 | | - $this->dieUsage( 'Invalid query', 'bad_query' ); |
78 | | - } |
79 | | - |
80 | | - $likeQuery = LinkFilter::keepOneWildcard( $likeQuery ); |
81 | | - $this->addWhere( 'el_index ' . $db->buildLike( $likeQuery ) ); |
82 | | - } elseif ( !is_null( $protocol ) ) { |
83 | | - $this->addWhere( 'el_index ' . $db->buildLike( "$protocol", $db->anyString() ) ); |
| 72 | + if ( $whereQuery !== null ) { |
| 73 | + $this->addWhere( $whereQuery ); |
84 | 74 | } |
85 | 75 | |
86 | 76 | $prop = array_flip( $params['prop'] ); |
Index: trunk/phase3/includes/api/ApiQueryBase.php |
— | — | @@ -440,6 +440,32 @@ |
441 | 441 | return substr( $this->keyToTitle( $keyPart . 'x' ), 0, - 1 ); |
442 | 442 | } |
443 | 443 | |
| 444 | + /** |
| 445 | + * @param $query String |
| 446 | + * @param $protocol String |
| 447 | + * @return null|string |
| 448 | + */ |
| 449 | + public function prepareUrlQuerySearchString( $query = null, $protocol = null) { |
| 450 | + $db = $this->getDb(); |
| 451 | + if ( !is_null( $query ) || $query != '' ) { |
| 452 | + if ( is_null( $protocol ) ) { |
| 453 | + $protocol = 'http://'; |
| 454 | + } |
| 455 | + |
| 456 | + $likeQuery = LinkFilter::makeLikeArray( $query, $protocol ); |
| 457 | + if ( !$likeQuery ) { |
| 458 | + $this->dieUsage( 'Invalid query', 'bad_query' ); |
| 459 | + } |
| 460 | + |
| 461 | + $likeQuery = LinkFilter::keepOneWildcard( $likeQuery ); |
| 462 | + return 'el_index ' . $db->buildLike( $likeQuery ); |
| 463 | + } elseif ( !is_null( $protocol ) ) { |
| 464 | + return 'el_index ' . $db->buildLike( "$protocol", $db->anyString() ); |
| 465 | + } |
| 466 | + |
| 467 | + return null; |
| 468 | + } |
| 469 | + |
444 | 470 | public function getPossibleErrors() { |
445 | 471 | return array_merge( parent::getPossibleErrors(), array( |
446 | 472 | array( 'invalidtitle', 'title' ), |
Index: trunk/phase3/includes/api/ApiQueryExternalLinks.php |
— | — | @@ -59,21 +59,10 @@ |
60 | 60 | $this->addTables( 'externallinks' ); |
61 | 61 | $this->addWhereFld( 'el_from', array_keys( $this->getPageSet()->getGoodTitles() ) ); |
62 | 62 | |
63 | | - //TODO: Refactor out, duplicated from ApiQueryExtLinksUsage |
64 | | - if ( !is_null( $query ) || $query != '' ) { |
65 | | - if ( is_null( $protocol ) ) { |
66 | | - $protocol = 'http://'; |
67 | | - } |
| 63 | + $whereQuery = $this->prepareUrlQuerySearchString( $db, $query, $protocol ); |
68 | 64 | |
69 | | - $likeQuery = LinkFilter::makeLikeArray( $query, $protocol ); |
70 | | - if ( !$likeQuery ) { |
71 | | - $this->dieUsage( 'Invalid query', 'bad_query' ); |
72 | | - } |
73 | | - |
74 | | - $likeQuery = LinkFilter::keepOneWildcard( $likeQuery ); |
75 | | - $this->addWhere( 'el_index ' . $db->buildLike( $likeQuery ) ); |
76 | | - } elseif ( !is_null( $protocol ) ) { |
77 | | - $this->addWhere( 'el_index ' . $db->buildLike( "$protocol", $db->anyString() ) ); |
| 65 | + if ( $whereQuery !== null ) { |
| 66 | + $this->addWhere( $whereQuery ); |
78 | 67 | } |
79 | 68 | |
80 | 69 | // Don't order by el_from if it's constant in the WHERE clause |