http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82915

Revision: 82915
Author:   reedy
Date:     2011-02-27 21:31:47 +0000 (Sun, 27 Feb 2011)
Log Message:
-----------
Refactor out the duplication I left with a TODO in r79659

Modified Paths:
--------------
    trunk/phase3/includes/api/ApiQueryBase.php
    trunk/phase3/includes/api/ApiQueryExtLinksUsage.php
    trunk/phase3/includes/api/ApiQueryExternalLinks.php

Modified: trunk/phase3/includes/api/ApiQueryBase.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryBase.php  2011-02-27 21:11:45 UTC (rev 
82914)
+++ trunk/phase3/includes/api/ApiQueryBase.php  2011-02-27 21:31:47 UTC (rev 
82915)
@@ -440,6 +440,32 @@
                return substr( $this->keyToTitle( $keyPart . 'x' ), 0, - 1 );
        }
 
+       /**
+        * @param $query String
+        * @param $protocol String
+        * @return null|string
+        */
+       public function prepareUrlQuerySearchString( $query = null, $protocol = 
null) {
+               $db = $this->getDb();
+               if ( !is_null( $query ) || $query != '' ) {
+                       if ( is_null( $protocol ) ) {
+                               $protocol = 'http://';
+                       }
+
+                       $likeQuery = LinkFilter::makeLikeArray( $query, 
$protocol );
+                       if ( !$likeQuery ) {
+                               $this->dieUsage( 'Invalid query', 'bad_query' );
+                       }
+
+                       $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
+                       return 'el_index ' . $db->buildLike( $likeQuery );
+               } elseif ( !is_null( $protocol ) ) {
+                       return 'el_index ' . $db->buildLike( "$protocol", 
$db->anyString() );
+               }
+
+               return null;
+       }
+
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'invalidtitle', 'title' ),

Modified: trunk/phase3/includes/api/ApiQueryExtLinksUsage.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryExtLinksUsage.php 2011-02-27 21:11:45 UTC 
(rev 82914)
+++ trunk/phase3/includes/api/ApiQueryExtLinksUsage.php 2011-02-27 21:31:47 UTC 
(rev 82915)
@@ -66,20 +66,10 @@
                $this->addWhere( 'page_id=el_from' );
                $this->addWhereFld( 'page_namespace', $params['namespace'] );
 
-               if ( !is_null( $query ) || $query != '' ) {
-                       if ( is_null( $protocol ) ) {
-                               $protocol = 'http://';
-                       }
+               $whereQuery = $this->prepareUrlQuerySearchString( $db, $query, 
$protocol );
 
-                       $likeQuery = LinkFilter::makeLikeArray( $query, 
$protocol );
-                       if ( !$likeQuery ) {
-                               $this->dieUsage( 'Invalid query', 'bad_query' );
-                       }
-
-                       $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
-                       $this->addWhere( 'el_index ' . $db->buildLike( 
$likeQuery ) );
-               } elseif ( !is_null( $protocol ) ) {
-                       $this->addWhere( 'el_index ' . $db->buildLike( 
"$protocol", $db->anyString() ) );
+               if ( $whereQuery !== null ) {
+                       $this->addWhere( $whereQuery );
                }
 
                $prop = array_flip( $params['prop'] );

Modified: trunk/phase3/includes/api/ApiQueryExternalLinks.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryExternalLinks.php 2011-02-27 21:11:45 UTC 
(rev 82914)
+++ trunk/phase3/includes/api/ApiQueryExternalLinks.php 2011-02-27 21:31:47 UTC 
(rev 82915)
@@ -59,21 +59,10 @@
                $this->addTables( 'externallinks' );
                $this->addWhereFld( 'el_from', array_keys( 
$this->getPageSet()->getGoodTitles() ) );
 
-               //TODO: Refactor out, duplicated from ApiQueryExtLinksUsage
-               if ( !is_null( $query ) || $query != '' ) {
-                       if ( is_null( $protocol ) ) {
-                               $protocol = 'http://';
-                       }
+               $whereQuery = $this->prepareUrlQuerySearchString( $db, $query, 
$protocol );
 
-                       $likeQuery = LinkFilter::makeLikeArray( $query, 
$protocol );
-                       if ( !$likeQuery ) {
-                               $this->dieUsage( 'Invalid query', 'bad_query' );
-                       }
-
-                       $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
-                       $this->addWhere( 'el_index ' . $db->buildLike( 
$likeQuery ) );
-               } elseif ( !is_null( $protocol ) ) {
-                       $this->addWhere( 'el_index ' . $db->buildLike( 
"$protocol", $db->anyString() ) );
+               if ( $whereQuery !== null ) {
+                       $this->addWhere( $whereQuery );
                }
 
                // Don't order by el_from if it's constant in the WHERE clause


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to