Index: trunk/extensions/ReplaceText/SpecialReplaceText.php |
— | — | @@ -471,61 +471,60 @@ |
472 | 472 | |
473 | 473 | function getMatchingTitles( $str, $namespaces, $category, $prefix ) { |
474 | 474 | $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 | + |
477 | 479 | $tables = array( 'page' ); |
478 | 480 | $vars = array( 'page_title', 'page_namespace' ); |
479 | 481 | $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 )})", |
482 | 484 | ); |
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 | | - } |
493 | 485 | |
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 ); |
501 | 491 | } |
502 | 492 | |
503 | 493 | function doSearchQuery( $search, $namespaces, $category, $prefix ) { |
504 | 494 | $dbr = wfGetDB( DB_SLAVE ); |
| 495 | + $any = $dbr->anyString(); |
505 | 496 | |
506 | | - $search = $dbr->escapeLike( $search ); |
507 | | - $include_ns = $dbr->makeList( $namespaces ); |
508 | | - |
509 | 497 | $tables = array( 'page', 'revision', 'text' ); |
510 | 498 | $vars = array( 'page_id', 'page_namespace', 'page_title', 'old_text' ); |
511 | 499 | $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 )})", |
514 | 502 | 'rev_id = page_latest', |
515 | 503 | 'rev_text_id = old_id' |
516 | 504 | ); |
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(); |
519 | 516 | $tables[] = 'categorylinks'; |
520 | 517 | $conds[] = 'page_id = cl_from'; |
521 | | - $conds[] = "cl_to = '$category'"; |
| 518 | + $conds['cl_to'] = $category; |
522 | 519 | } |
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 | + } |
528 | 521 | |
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 | + } |
530 | 529 | } |
531 | 530 | |
532 | 531 | } |
Index: trunk/extensions/ReplaceText/README |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | |
30 | 30 | == Requirements == |
31 | 31 | |
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. |
33 | 33 | |
34 | 34 | == Installation == |
35 | 35 | |