MediaWiki REL1_31
ReplaceTextSearch.php
Go to the documentation of this file.
1<?php
23
25
34 public static function doSearchQuery(
35 $search, $namespaces, $category, $prefix, $use_regex = false
36 ) {
38 $tables = [ 'page', 'revision', 'text' ];
39 $vars = [ 'page_id', 'page_namespace', 'page_title', 'old_text' ];
40 if ( $use_regex ) {
41 $comparisonCond = self::regexCond( $dbr, 'old_text', $search );
42 } else {
43 $any = $dbr->anyString();
44 $comparisonCond = 'old_text ' . $dbr->buildLike( $any, $search, $any );
45 }
46 $conds = [
47 $comparisonCond,
48 'page_namespace' => $namespaces,
49 'rev_id = page_latest',
50 'rev_text_id = old_id'
51 ];
52
53 self::categoryCondition( $category, $tables, $conds );
54 self::prefixCondition( $prefix, $conds );
55 $options = [
56 'ORDER BY' => 'page_namespace, page_title',
57 // 250 seems like a reasonable limit for one screen.
58 // @TODO - should probably be a setting.
59 'LIMIT' => 250
60 ];
61
62 return $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
63 }
64
70 public static function categoryCondition( $category, &$tables, &$conds ) {
71 if ( strval( $category ) !== '' ) {
72 $category = Title::newFromText( $category )->getDbKey();
73 $tables[] = 'categorylinks';
74 $conds[] = 'page_id = cl_from';
75 $conds['cl_to'] = $category;
76 }
77 }
78
83 public static function prefixCondition( $prefix, &$conds ) {
84 if ( strval( $prefix ) === '' ) {
85 return;
86 }
87
89 $title = Title::newFromText( $prefix );
90 if ( !is_null( $title ) ) {
91 $prefix = $title->getDbKey();
92 }
93 $any = $dbr->anyString();
94 $conds[] = 'page_title ' . $dbr->buildLike( $prefix, $any );
95 }
96
103 public static function regexCond( $dbr, $column, $regex ) {
104 if ( $dbr->getType() == 'postgres' ) {
105 $op = '~';
106 } else {
107 $op = 'REGEXP';
108 }
109 return "$column $op " . $dbr->addQuotes( $regex );
110 }
111}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static categoryCondition( $category, &$tables, &$conds)
static regexCond( $dbr, $column, $regex)
static doSearchQuery( $search, $namespaces, $category, $prefix, $use_regex=false)
static prefixCondition( $prefix, &$conds)
Relational database abstraction object.
Definition Database.php:48
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2228
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1015
namespace and then decline to actually register it & $namespaces
Definition hooks.txt:934
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2001
Result wrapper for grabbing data queried from an IDatabase object.
const DB_REPLICA
Definition defines.php:25