r25922 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25921‎ | r25922 | r25923 >
Date:20:14, 18 September 2007
Author:brion
Status:old
Tags:
Comment:
Fix external link queries to escape LIKE metacharacters, avoiding massive table scans
Modified paths:
  • /trunk/phase3/includes/LinkFilter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LinkFilter.php
@@ -51,6 +51,7 @@
5252 * @param $prot String: protocol
5353 */
5454 public static function makeLike( $filterEntry , $prot = 'http://' ) {
 55+ $db = wfGetDB( DB_MASTER );
5556 if ( substr( $filterEntry, 0, 2 ) == '*.' ) {
5657 $subdomains = true;
5758 $filterEntry = substr( $filterEntry, 2 );
@@ -83,23 +84,23 @@
8485 $mailparts = explode( '@', $host );
8586 $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) );
8687 $host = $domainpart . '@' . $mailparts[0];
87 - $like = "$prot$host%";
 88+ $like = $db->escapeLike( "$prot$host" ) . "%";
8889 } elseif ( $prot == 'mailto:' ) {
8990 // domainpart of email adress only. do not add '.'
9091 $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
91 - $like = "$prot$host%";
 92+ $like = $db->escapeLike( "$prot$host" ) . "%";
9293 } else {
9394 $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
9495 if ( substr( $host, -1, 1 ) !== '.' ) {
9596 $host .= '.';
9697 }
97 - $like = "$prot$host";
 98+ $like = $db->escapeLike( "$prot$host" );
9899
99100 if ( $subdomains ) {
100101 $like .= '%';
101102 }
102103 if ( !$subdomains || $path !== '/' ) {
103 - $like .= $path . '%';
 104+ $like .= $db->escapeLike( $path ) . '%';
104105 }
105106 }
106107 return $like;

Follow-up revisions

RevisionCommit summaryAuthorDate
r25932Merged revisions 25861-25931 via svnmerge from...david06:43, 19 September 2007

Status & tagging log