r81220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81219‎ | r81220 | r81221 >
Date:22:34, 30 January 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Part of bug 27041, removing all calls to escapeLike in extensions
Modified paths:
  • /trunk/extensions/IndexFunction/SpecialIndex.php (modified) (history)
  • /trunk/extensions/InterwikiList/InterwikiList_body.php (modified) (history)
  • /trunk/extensions/Renameuser/Renameuser_body.php (modified) (history)
  • /trunk/extensions/ReplaceText/SpecialReplaceText.php (modified) (history)
  • /trunk/extensions/SubPageList/SubPageList.class.php (modified) (history)
  • /trunk/extensions/SubPageList3/SubPageList3.php (modified) (history)
  • /trunk/extensions/TitleKey/TitleKey_body.php (modified) (history)
  • /trunk/extensions/Transliterator/Transliterator_body.php (modified) (history)
  • /trunk/extensions/WatchSubpages/WatchSubpages_body.php (modified) (history)
  • /trunk/extensions/WebDAV/WebDavServer.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogComment.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogQuery.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/TestWikiRC.php (modified) (history)

Diff [purge]

Index: trunk/extensions/InterwikiList/InterwikiList_body.php
@@ -42,7 +42,7 @@
4343
4444 $conds = array();
4545 if ( !is_null( $prefix ) ) {
46 - $conds[] = "iw_prefix LIKE " . $dbr->addQuotes( $dbr->escapeLike( $prefix ) . "%" );
 46+ $conds[] = "iw_prefix " . $dbr->buildLike( $prefix, $dbr->anyString() );
4747 }
4848
4949 $results = $dbr->select( 'interwiki', array( 'iw_prefix', 'iw_url' ), $conds );
Index: trunk/extensions/Renameuser/Renameuser_body.php
@@ -296,8 +296,7 @@
297297 array( 'page_namespace', 'page_title' ),
298298 array(
299299 'page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')',
300 - '(page_title LIKE ' .
301 - $dbr->addQuotes( $dbr->escapeLike( $oldusername->getDBkey() ) . '/%' ) .
 300+ '(page_title ' . $dbr->buildLike( $oldusername->getDBkey() . '/', $dbr->anyString() ) .
302301 ' OR page_title = ' . $dbr->addQuotes( $oldusername->getDBkey() ) . ')'
303302 ),
304303 __METHOD__
Index: trunk/extensions/SubPageList/SubPageList.class.php
@@ -210,7 +210,7 @@
211211 $conditions['page_is_redirect'] = 0;
212212
213213 // TODO: this is rather resource heavy
214 - $conditions[] = '`page_title` LIKE ' . $dbr->addQuotes( $dbr->escapeLike( $title->getDBkey() ) . '/%' );
 214+ $conditions[] = '`page_title` ' . $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
215215
216216 $fields = array();
217217 $fields[] = 'page_title';
@@ -218,7 +218,7 @@
219219
220220 $res = $dbr->select( 'page', $fields, $conditions, __METHOD__, $options );
221221
222 - while( $row = $dbr->fetchObject( $res ) ) {
 222+ foreach( $res as $row ) {
223223 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
224224 if( is_object( $title ) ) {
225225 $titles[] = $title;
Index: trunk/extensions/WebDAV/WebDavServer.php
@@ -602,7 +602,7 @@
603603 $entryCondition = null;
604604 foreach ( $entryConditions as $path => $revisionCondition ) {
605605 if ( !empty( $path ) ) {
606 - $pathCondition = '(page_title = ' . $dbr->addQuotes( $path ) . ' OR page_title LIKE \'' . $dbr->escapeLike( $path ) . '/%\')';
 606+ $pathCondition = '(page_title = ' . $dbr->addQuotes( $path ) . ' OR page_title ' . $dbr->buildLike( $path . '/', $dbr->anyString() ) . ')';
607607
608608 if ( !empty( $revisionCondition ) ) {
609609 $revisionCondition = ' AND ' . $revisionCondition;
Index: trunk/extensions/SubPageList3/SubPageList3.php
@@ -45,6 +45,7 @@
4646 * Function called by the Hook, returns the wiki text
4747 */
4848 function efRenderSubpageList3( $input, $args, $parser ) {
 49+ global $wgVersion;
4950 // This function has been deprecated in 1.16, but needed for earlier versions.
5051 // It's present in 1.16 as a stub, but lets check if it exists in case it gets removed at some point.
5152 if ( version_compare( $wgVersion, '1.15', '<=' ) ) {
@@ -403,7 +404,7 @@
404405
405406 if (strlen($nsi)>0) $conditions['page_namespace'] = $nsi; // don't let list cross namespaces
406407 $conditions['page_is_redirect'] = 0;
407 - $conditions[] = '`page_title` LIKE ' . $dbr->addQuotes( $dbr->escapeLike($parent) . '/%' );
 408+ $conditions[] = '`page_title` ' . $dbr->buildLike( $parent . '/', $dbr->anyString() );
408409
409410 $fields = array();
410411 $fields[] = 'page_title';
Index: trunk/extensions/TitleKey/TitleKey_body.php
@@ -208,7 +208,7 @@
209209 array(
210210 'tk_page=page_id',
211211 'tk_namespace' => $ns,
212 - 'tk_key LIKE \'' . $dbr->escapeLike( $key ) . '%\'',
 212+ 'tk_key ' . $dbr->buildLike( $key, $dbr->anyString() ),
213213 ),
214214 __METHOD__,
215215 array(
Index: trunk/extensions/Wikilog/WikilogQuery.php
@@ -674,8 +674,7 @@
675675 if ( $this->mItem !== null ) {
676676 $q_conds['wlc_post'] = $this->mItem->getID();
677677 if ( $this->mThread ) {
678 - $thread = $db->escapeLike( $this->mThread );
679 - $q_conds[] = "wlc_thread LIKE '{$thread}/%'";
 678+ $q_conds[] = "wlc_thread " . $db->buildLike( $this->mThread . '/', $db->anyString() );
680679 }
681680 } elseif ( $this->mWikilog !== null ) {
682681 $join_wlp = true;
Index: trunk/extensions/Wikilog/WikilogComment.php
@@ -478,9 +478,8 @@
479479 if ( is_array( $thread ) ) {
480480 $thread = implode( '/', $thread );
481481 }
482 - $thread = $dbr->escapeLike( $thread );
483482 return self::fetchFromConds( $dbr,
484 - array( 'wlc_post' => $itemid, "wlc_thread LIKE '{$thread}/%'" ),
 483+ array( 'wlc_post' => $itemid, "wlc_thread " . $dbr->buildLike( $thread . '/', $dbr->anyString() ) ),
485484 array( 'ORDER BY' => 'wlc_thread, wlc_id' )
486485 );
487486 }
Index: trunk/extensions/IndexFunction/SpecialIndex.php
@@ -112,12 +112,13 @@
113113 $indexconds[] = 'in_title' . $operator . $this->mDb->addQuotes( $offset );
114114 }
115115 $ns = $this->mSearchTitle->getNamespace();
116 - $like = $this->mDb->escapeLike( $this->mSearchTitle->getDBkey() ) . '%';
 116+
 117+ $like = $this->mDb->buildLike( $this->mSearchTitle->getDBkey(), $this->mDb->anyString() );
117118
118119 $pageconds[] = "page_namespace = $ns";
119 - $pageconds[] = "page_title LIKE '$like'";
 120+ $pageconds[] = "page_title " . $like;
120121 $indexconds[] = "in_namespace = $ns";
121 - $indexconds[] = "in_title LIKE '$like'";
 122+ $indexconds[] = "in_title " . $like;
122123
123124
124125 $pagequery = $this->mDb->selectSQLText( 'page',
Index: trunk/extensions/WatchSubpages/WatchSubpages_body.php
@@ -254,7 +254,7 @@
255255 array( 'page_namespace', 'page_title', 'page_id', 'page_is_redirect' ),
256256 array(
257257 'page_namespace' => $prefixNS,
258 - 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
 258+ 'page_title ' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
259259 ),
260260 __METHOD__,
261261 array(
Index: trunk/extensions/WikimediaIncubator/TestWikiRC.php
@@ -25,7 +25,7 @@
2626 $dbr = wfGetDB( DB_SLAVE );
2727 $namespaces = array( NS_MAIN, NS_TALK, NS_TEMPLATE, NS_TEMPLATE_TALK, NS_CATEGORY, NS_CATEGORY_TALK );
2828 $conds[] = 'rc_namespace IN (' . $dbr->makeList( $namespaces ) . ')';
29 - $conds[] = 'rc_title like ' . $dbr->addQuotes( $dbr->escapeLike( $fullprefix ) . '/%' ) .
 29+ $conds[] = 'rc_title ' . $dbr->buildLike( $fullprefix . '/', $dbr->anyString() ) .
3030 ' OR rc_title = ' . $dbr->addQuotes( $fullprefix );
3131 return true;
3232 }
Index: trunk/extensions/Transliterator/Transliterator_body.php
@@ -141,7 +141,7 @@
142142 array( 'page_title', 'page_id' ),
143143 array(
144144 'page_namespace' => NS_MEDIAWIKI,
145 - 'page_title LIKE \'' . $dbr->escapeLike( self::getMapPagePrefix() ) . '%\''
 145+ 'page_title ' . $dbr->buildLike( self::getMapPagePrefix(), $dbr->anyString() )
146146 ),
147147 __METHOD__
148148 );
Index: trunk/extensions/ReplaceText/SpecialReplaceText.php
@@ -515,10 +515,10 @@
516516 'rev_text_id = old_id'
517517 );
518518 } else {
519 - $search = $dbr->escapeLike( $search );
 519+ $any = $dbr->anyString();
520520 $include_ns = $dbr->makeList( $namespaces );
521521 $conds = array(
522 - "old_text LIKE '%$search%'",
 522+ "old_text " . $dbr->buildLike( $any, $search, $any ),
523523 "page_namespace IN ($include_ns)",
524524 'rev_id = page_latest',
525525 'rev_text_id = old_id'

Follow-up revisions

RevisionCommit summaryAuthorDate
r81241bug 27041, fixup usages of userMailer()reedy12:21, 31 January 2011
r81242Per bug 27041, remove calls to $dbr->immediateBegin();...reedy12:24, 31 January 2011
r81243bug 27041, replace call to SiteStats::admins() to SiteStats::numberingroup( '...reedy12:26, 31 January 2011
r81244bug 27041, swap Database::newFromParams to DatabaseBase::newFromType()reedy12:34, 31 January 2011
r81245bug 27041, kill Image::__constructreedy12:45, 31 January 2011
r81248bug 27041, SpecialPage:addPage is deprecated...reedy13:17, 31 January 2011
r813941.17: MFT r81026, r81116, r81155, r81201, r81204, r81205, r81220, r81235, r81...catrope15:33, 2 February 2011

Comments

#Comment by MarkAHershberger (talk | contribs)   02:40, 31 January 2011

awesome! Thanks for spotting this problem and dealing with it!

Status & tagging log