r60162 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60161‎ | r60162 | r60163 >
Date:15:39, 17 December 2009
Author:maxsem
Status:resolved
Tags:
Comment:
Fixup for r57989: removed artifacts of the previous version of my patch, improved code reuse.
Modified paths:
  • /trunk/phase3/includes/LinkFilter.php (modified) (history)
  • /trunk/phase3/maintenance/storage/compressOld.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/storage/compressOld.inc
@@ -105,8 +105,8 @@
106106 # overwriting bulk storage concat rows. Don't compress external references, because
107107 # the script doesn't yet delete rows from external storage.
108108 $conds = array(
109 - 'old_flags NOT ' . $dbr->buildLike( MATCH_STRING, 'object', MATCH_STRING ) . ' AND old_flags NOT '
110 - . $dbr->buildLike( MATCH_STRING, 'external', MATCH_STRING ) );
 109+ 'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'object', $dbr->anyString() ) . ' AND old_flags NOT '
 110+ . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) );
111111
112112 if ( $beginDate ) {
113113 if ( !preg_match( '/^\d{14}$/', $beginDate ) ) {
Index: trunk/phase3/includes/LinkFilter.php
@@ -53,63 +53,18 @@
5454 */
5555 public static function makeLike( $filterEntry , $prot = 'http://' ) {
5656 wfDeprecated( __METHOD__ );
57 - $db = wfGetDB( DB_MASTER );
58 - if ( substr( $filterEntry, 0, 2 ) == '*.' ) {
59 - $subdomains = true;
60 - $filterEntry = substr( $filterEntry, 2 );
61 - if ( $filterEntry == '' ) {
62 - // We don't want to make a clause that will match everything,
63 - // that could be dangerous
64 - return false;
65 - }
66 - } else {
67 - $subdomains = false;
68 - }
69 - // No stray asterisks, that could cause confusion
70 - // It's not simple or efficient to handle it properly so we don't
71 - // handle it at all.
72 - if ( strpos( $filterEntry, '*' ) !== false ) {
 57+
 58+ $like = self::makeLikeArray( $filterEntry , $prot );
 59+ if ( !$like ) {
7360 return false;
7461 }
75 - $slash = strpos( $filterEntry, '/' );
76 - if ( $slash !== false ) {
77 - $path = substr( $filterEntry, $slash );
78 - $host = substr( $filterEntry, 0, $slash );
79 - } else {
80 - $path = '/';
81 - $host = $filterEntry;
82 - }
83 - // Reverse the labels in the hostname, convert to lower case
84 - // For emails reverse domainpart only
85 - if ( $prot == 'mailto:' && strpos($host, '@') ) {
86 - // complete email adress
87 - $mailparts = explode( '@', $host );
88 - $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) );
89 - $host = $domainpart . '@' . $mailparts[0];
90 - $like = $db->escapeLike( "$prot$host" ) . "%";
91 - } elseif ( $prot == 'mailto:' ) {
92 - // domainpart of email adress only. do not add '.'
93 - $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
94 - $like = $db->escapeLike( "$prot$host" ) . "%";
95 - } else {
96 - $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
97 - if ( substr( $host, -1, 1 ) !== '.' ) {
98 - $host .= '.';
99 - }
100 - $like = $db->escapeLike( "$prot$host" );
 62+ $dbw = wfGetDB( DB_MASTER );
10163
102 - if ( $subdomains ) {
103 - $like .= '%';
104 - }
105 - if ( !$subdomains || $path !== '/' ) {
106 - $like .= $db->escapeLike( $path ) . '%';
107 - }
108 - }
109 - return $like;
 64+ return $dbw->buildLike( $like );
11065 }
11166
11267 /**
113 - * Make an array to be used for calls to Database::like(), which will match the specified
 68+ * Make an array to be used for calls to Database::buildLike(), which will match the specified
11469 * string. There are several kinds of filter entry:
11570 * *.domain.com - Produces http://com.domain.%, matches domain.com
11671 * and www.domain.com

Follow-up revisions

RevisionCommit summaryAuthorDate
r60198Fix breakage of LinkFilter::makeLike() due to attempted rewrite in r60162. It...tstarling02:49, 18 December 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r57989(bug 20275) Fixed LIKE queries on SQLite backend...maxsem19:53, 21 October 2009

Status & tagging log