r70195 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70194‎ | r70195 | r70196 >
Date:17:45, 30 July 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Change escapeLike to buildLike and restructure

This makes the minimum version 1.16 instead of 1.11
Modified paths:
  • /trunk/extensions/ReplaceText/README (modified) (history)
  • /trunk/extensions/ReplaceText/SpecialReplaceText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ReplaceText/SpecialReplaceText.php
@@ -471,61 +471,60 @@
472472
473473 function getMatchingTitles( $str, $namespaces, $category, $prefix ) {
474474 $dbr = wfGetDB( DB_SLAVE );
475 - $sql_str = $dbr->escapeLike( str_replace( ' ', '_', $str ) );
476 - $include_ns = $dbr->makeList( $namespaces );
 475+ $any = $dbr->anyString();
 476+
 477+ $str = Title::newFromText( $str )->getDbKey();
 478+
477479 $tables = array( 'page' );
478480 $vars = array( 'page_title', 'page_namespace' );
479481 $conds = array(
480 - "page_title LIKE '%$sql_str%'",
481 - "page_namespace IN ($include_ns)",
 482+ 'page_title ' . $dbr->buildLike( $any, $str, $any ),
 483+ "page_namespace IN ({$dbr->makeList( $namespaces )})",
482484 );
483 - if ( ! empty( $category ) ) {
484 - $category = str_replace( ' ', '_', $dbr->escapeLike( $category ) );
485 - $tables[] = 'categorylinks';
486 - $conds[] = 'page_id = cl_from';
487 - $conds[] = "cl_to = '$category'";
488 - }
489 - if ( ! empty( $prefix ) ) {
490 - $prefix = $dbr->escapeLike( str_replace( ' ', '_', $prefix ) );
491 - $conds[] = "page_title like '$prefix%'";
492 - }
493485
494 - return $dbr->select(
495 - $tables,
496 - $vars,
497 - $conds,
498 - __METHOD__,
499 - array( 'ORDER BY' => 'page_namespace, page_title' )
500 - );
 486+ $this->categoryConditition( $category, $tables, $conds );
 487+ $this->prefixCondition( $prefix, $conds );
 488+ $sort = array( 'ORDER BY' => 'page_namespace, page_title' );
 489+
 490+ return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort );
501491 }
502492
503493 function doSearchQuery( $search, $namespaces, $category, $prefix ) {
504494 $dbr = wfGetDB( DB_SLAVE );
 495+ $any = $dbr->anyString();
505496
506 - $search = $dbr->escapeLike( $search );
507 - $include_ns = $dbr->makeList( $namespaces );
508 -
509497 $tables = array( 'page', 'revision', 'text' );
510498 $vars = array( 'page_id', 'page_namespace', 'page_title', 'old_text' );
511499 $conds = array(
512 - "old_text like '%$search%'",
513 - "page_namespace in ($include_ns)",
 500+ 'old_text ' . $dbr->buildLike( $any, $search, $any ),
 501+ "page_namespace IN ({$dbr->makeList( $namespaces )})",
514502 'rev_id = page_latest',
515503 'rev_text_id = old_id'
516504 );
517 - if ( ! empty( $category ) ) {
518 - $category = str_replace( ' ', '_', $dbr->escapeLike( $category ) );
 505+
 506+ $this->categoryConditition( $category, $tables, $conds );
 507+ $this->prefixCondition( $prefix, $conds );
 508+ $sort = array( 'ORDER BY' => 'page_namespace, page_title' );
 509+
 510+ return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort );
 511+ }
 512+
 513+ protected function categoryConditition( $category, &$tables, &$conds ) {
 514+ if ( !empty( $category ) ) {
 515+ $category = Title::newFromText( $category )->getDbKey();
519516 $tables[] = 'categorylinks';
520517 $conds[] = 'page_id = cl_from';
521 - $conds[] = "cl_to = '$category'";
 518+ $conds['cl_to'] = $category;
522519 }
523 - if ( ! empty( $prefix ) ) {
524 - $prefix = $dbr->escapeLike( str_replace( ' ', '_', $prefix ) );
525 - $conds[] = "page_title like '$prefix%'";
526 - }
527 - $sort = array( 'ORDER BY' => 'page_namespace, page_title' );
 520+ }
528521
529 - return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort );
 522+ protected function prefixCondition( $prefix, &$conds ) {
 523+ if ( !empty( $prefix ) ) {
 524+ $dbr = wfGetDB( DB_SLAVE );
 525+ $any = $dbr->anyString();
 526+ $prefix = Title::newFromText( $prefix )->getDbKey();
 527+ $conds[] = 'page_title ' . $dbr->buildLike( $prefix, $any );
 528+ }
530529 }
531530
532531 }
Index: trunk/extensions/ReplaceText/README
@@ -28,7 +28,7 @@
2929
3030 == Requirements ==
3131
32 -This version of the Replace Text extension requires MediaWiki 1.11 or higher.
 32+This version of the Replace Text extension requires MediaWiki 1.16 or higher.
3333
3434 == Installation ==
3535

Status & tagging log