Fixup for r57989: removed artifacts of the previous version of my patch, improved code reuse.
This commit is contained in:
parent
b25db35904
commit
eb8b230abc
2 changed files with 8 additions and 53 deletions
|
|
@ -53,63 +53,18 @@ class LinkFilter {
|
|||
*/
|
||||
public static function makeLike( $filterEntry , $prot = 'http://' ) {
|
||||
wfDeprecated( __METHOD__ );
|
||||
$db = wfGetDB( DB_MASTER );
|
||||
if ( substr( $filterEntry, 0, 2 ) == '*.' ) {
|
||||
$subdomains = true;
|
||||
$filterEntry = substr( $filterEntry, 2 );
|
||||
if ( $filterEntry == '' ) {
|
||||
// We don't want to make a clause that will match everything,
|
||||
// that could be dangerous
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$subdomains = false;
|
||||
}
|
||||
// No stray asterisks, that could cause confusion
|
||||
// It's not simple or efficient to handle it properly so we don't
|
||||
// handle it at all.
|
||||
if ( strpos( $filterEntry, '*' ) !== false ) {
|
||||
|
||||
$like = self::makeLikeArray( $filterEntry , $prot );
|
||||
if ( !$like ) {
|
||||
return false;
|
||||
}
|
||||
$slash = strpos( $filterEntry, '/' );
|
||||
if ( $slash !== false ) {
|
||||
$path = substr( $filterEntry, $slash );
|
||||
$host = substr( $filterEntry, 0, $slash );
|
||||
} else {
|
||||
$path = '/';
|
||||
$host = $filterEntry;
|
||||
}
|
||||
// Reverse the labels in the hostname, convert to lower case
|
||||
// For emails reverse domainpart only
|
||||
if ( $prot == 'mailto:' && strpos($host, '@') ) {
|
||||
// complete email adress
|
||||
$mailparts = explode( '@', $host );
|
||||
$domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) );
|
||||
$host = $domainpart . '@' . $mailparts[0];
|
||||
$like = $db->escapeLike( "$prot$host" ) . "%";
|
||||
} elseif ( $prot == 'mailto:' ) {
|
||||
// domainpart of email adress only. do not add '.'
|
||||
$host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
|
||||
$like = $db->escapeLike( "$prot$host" ) . "%";
|
||||
} else {
|
||||
$host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
|
||||
if ( substr( $host, -1, 1 ) !== '.' ) {
|
||||
$host .= '.';
|
||||
}
|
||||
$like = $db->escapeLike( "$prot$host" );
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
|
||||
if ( $subdomains ) {
|
||||
$like .= '%';
|
||||
}
|
||||
if ( !$subdomains || $path !== '/' ) {
|
||||
$like .= $db->escapeLike( $path ) . '%';
|
||||
}
|
||||
}
|
||||
return $like;
|
||||
return $dbw->buildLike( $like );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an array to be used for calls to Database::like(), which will match the specified
|
||||
* Make an array to be used for calls to Database::buildLike(), which will match the specified
|
||||
* string. There are several kinds of filter entry:
|
||||
* *.domain.com - Produces http://com.domain.%, matches domain.com
|
||||
* and www.domain.com
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ function compressWithConcat( $startId, $maxChunkSize, $beginDate,
|
|||
# overwriting bulk storage concat rows. Don't compress external references, because
|
||||
# the script doesn't yet delete rows from external storage.
|
||||
$conds = array(
|
||||
'old_flags NOT ' . $dbr->buildLike( MATCH_STRING, 'object', MATCH_STRING ) . ' AND old_flags NOT '
|
||||
. $dbr->buildLike( MATCH_STRING, 'external', MATCH_STRING ) );
|
||||
'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'object', $dbr->anyString() ) . ' AND old_flags NOT '
|
||||
. $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) );
|
||||
|
||||
if ( $beginDate ) {
|
||||
if ( !preg_match( '/^\d{14}$/', $beginDate ) ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue