r82915 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82914‎ | r82915 | r82916 >
Date:21:31, 27 February 2011
Author:reedy
Status:resolved
Tags:
Comment:
Refactor out the duplication I left with a TODO in r79659
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryExtLinksUsage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryExternalLinks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryExtLinksUsage.php
@@ -66,20 +66,10 @@
6767 $this->addWhere( 'page_id=el_from' );
6868 $this->addWhereFld( 'page_namespace', $params['namespace'] );
6969
70 - if ( !is_null( $query ) || $query != '' ) {
71 - if ( is_null( $protocol ) ) {
72 - $protocol = 'http://';
73 - }
 70+ $whereQuery = $this->prepareUrlQuerySearchString( $db, $query, $protocol );
7471
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 );
8474 }
8575
8676 $prop = array_flip( $params['prop'] );
Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -440,6 +440,32 @@
441441 return substr( $this->keyToTitle( $keyPart . 'x' ), 0, - 1 );
442442 }
443443
 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+
444470 public function getPossibleErrors() {
445471 return array_merge( parent::getPossibleErrors(), array(
446472 array( 'invalidtitle', 'title' ),
Index: trunk/phase3/includes/api/ApiQueryExternalLinks.php
@@ -59,21 +59,10 @@
6060 $this->addTables( 'externallinks' );
6161 $this->addWhereFld( 'el_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
6262
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 );
6864
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 );
7867 }
7968
8069 // Don't order by el_from if it's constant in the WHERE clause

Sign-offs

UserFlagDate
Bawolffinspected03:55, 27 March 2011
Bawolfftested03:55, 27 March 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r84698Remove 2 erroneous $db parameters from External links modulesreedy20:02, 24 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79659* (bug 26485) add a elextlinks param to prop=extlinks...reedy19:45, 5 January 2011

Status & tagging log