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

Revision: 70195
Author:   nikerabbit
Date:     2010-07-30 17:45:36 +0000 (Fri, 30 Jul 2010)

Log Message:
-----------
Change escapeLike to buildLike and restructure

This makes the minimum version 1.16 instead of 1.11

Modified Paths:
--------------
    trunk/extensions/ReplaceText/README
    trunk/extensions/ReplaceText/SpecialReplaceText.php

Modified: trunk/extensions/ReplaceText/README
===================================================================
--- trunk/extensions/ReplaceText/README 2010-07-30 17:26:17 UTC (rev 70194)
+++ trunk/extensions/ReplaceText/README 2010-07-30 17:45:36 UTC (rev 70195)
@@ -28,7 +28,7 @@
 
 == Requirements ==
 
-This version of the Replace Text extension requires MediaWiki 1.11 or higher.
+This version of the Replace Text extension requires MediaWiki 1.16 or higher.
 
 == Installation ==
 

Modified: trunk/extensions/ReplaceText/SpecialReplaceText.php
===================================================================
--- trunk/extensions/ReplaceText/SpecialReplaceText.php 2010-07-30 17:26:17 UTC 
(rev 70194)
+++ trunk/extensions/ReplaceText/SpecialReplaceText.php 2010-07-30 17:45:36 UTC 
(rev 70195)
@@ -471,61 +471,60 @@
 
        function getMatchingTitles( $str, $namespaces, $category, $prefix ) {
                $dbr = wfGetDB( DB_SLAVE );
-               $sql_str = $dbr->escapeLike( str_replace( ' ', '_', $str ) );
-               $include_ns = $dbr->makeList( $namespaces );
+               $any = $dbr->anyString();
+
+               $str = Title::newFromText( $str )->getDbKey();
+
                $tables = array( 'page' );
                $vars = array( 'page_title', 'page_namespace' );
                $conds = array(
-                       "page_title LIKE '%$sql_str%'",
-                       "page_namespace IN ($include_ns)",
+                       'page_title ' . $dbr->buildLike( $any, $str, $any ),
+                       "page_namespace IN ({$dbr->makeList( $namespaces )})",
                );
-               if ( ! empty( $category ) ) {
-                       $category = str_replace( ' ', '_', $dbr->escapeLike( 
$category ) );
-                       $tables[] = 'categorylinks';
-                       $conds[] = 'page_id = cl_from';
-                       $conds[] = "cl_to = '$category'";
-               }
-               if ( ! empty( $prefix ) ) {
-                       $prefix = $dbr->escapeLike( str_replace( ' ', '_', 
$prefix ) );
-                       $conds[] = "page_title like '$prefix%'";
-               }
 
-               return $dbr->select(
-                       $tables,
-                       $vars,
-                       $conds,
-                       __METHOD__,
-                       array( 'ORDER BY' => 'page_namespace, page_title' )
-               );
+               $this->categoryConditition( $category, $tables, $conds );
+               $this->prefixCondition( $prefix, $conds );
+               $sort = array( 'ORDER BY' => 'page_namespace, page_title' );
+
+               return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort 
);
        }
 
        function doSearchQuery( $search, $namespaces, $category, $prefix ) {
                $dbr = wfGetDB( DB_SLAVE );
+               $any = $dbr->anyString();
 
-               $search = $dbr->escapeLike( $search );
-               $include_ns = $dbr->makeList( $namespaces );
-
                $tables = array( 'page', 'revision', 'text' );
                $vars = array( 'page_id', 'page_namespace', 'page_title', 
'old_text' );
                $conds = array(
-                       "old_text like '%$search%'",
-                       "page_namespace in ($include_ns)",
+                       'old_text ' . $dbr->buildLike( $any, $search, $any ),
+                       "page_namespace IN ({$dbr->makeList( $namespaces )})",
                        'rev_id = page_latest',
                        'rev_text_id = old_id'
                );
-               if ( ! empty( $category ) ) {
-                       $category = str_replace( ' ', '_', $dbr->escapeLike( 
$category ) );
+
+               $this->categoryConditition( $category, $tables, $conds );
+               $this->prefixCondition( $prefix, $conds );
+               $sort = array( 'ORDER BY' => 'page_namespace, page_title' );
+
+               return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort 
);
+       }
+
+       protected function categoryConditition( $category, &$tables, &$conds ) {
+               if ( !empty( $category ) ) {
+                       $category = Title::newFromText( $category )->getDbKey();
                        $tables[] = 'categorylinks';
                        $conds[] = 'page_id = cl_from';
-                       $conds[] = "cl_to = '$category'";
+                       $conds['cl_to'] = $category;
                }
-               if ( ! empty( $prefix ) ) {
-                       $prefix = $dbr->escapeLike( str_replace( ' ', '_', 
$prefix ) );
-                       $conds[] = "page_title like '$prefix%'";
-               }
-               $sort = array( 'ORDER BY' => 'page_namespace, page_title' );
+       }
 
-               return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort 
);
+       protected function prefixCondition( $prefix, &$conds ) {
+               if ( !empty( $prefix ) ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $any = $dbr->anyString();
+                       $prefix = Title::newFromText( $prefix )->getDbKey();
+                       $conds[] = 'page_title ' . $dbr->buildLike( $prefix, 
$any );
+               }
        }
 
 }



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

Reply via email to