54 return preg_match( $regex, $text );
66 if ( substr( $filterEntry, 0, 2 ) ==
'*.' ) {
67 $regex .=
'(?:[A-Za-z0-9.-]+\.|)';
68 $filterEntry = substr( $filterEntry, 2 );
70 $regex .= preg_quote( $filterEntry,
'!' ) .
'!Si';
95 public static function makeLikeArray( $filterEntry, $protocol =
'http://' ) {
98 $target = $protocol . $filterEntry;
101 if ( $bits ==
false ) {
106 if ( substr( $bits[
'host'], 0, 2 ) ==
'*.' ) {
108 $bits[
'host'] = substr( $bits[
'host'], 2 );
109 if ( $bits[
'host'] ==
'' ) {
120 if ( $bits[
'scheme'] ===
'mailto' && strpos( $bits[
'host'],
'@' ) ) {
122 $mailparts = explode(
'@', $bits[
'host'] );
123 $domainpart = strtolower( implode(
'.', array_reverse( explode(
'.', $mailparts[1] ) ) ) );
124 $bits[
'host'] = $domainpart .
'@' . $mailparts[0];
125 } elseif ( $bits[
'scheme'] ===
'mailto' ) {
127 $bits[
'host'] = strtolower( implode(
'.', array_reverse( explode(
'.', $bits[
'host'] ) ) ) );
129 $bits[
'host'] = strtolower( implode(
'.', array_reverse( explode(
'.', $bits[
'host'] ) ) ) );
130 if ( substr( $bits[
'host'], -1, 1 ) !==
'.' ) {
131 $bits[
'host'] .=
'.';
135 $like[] = $bits[
'scheme'] . $bits[
'delimiter'] . $bits[
'host'];
138 $like[] = $db->anyString();
141 if ( isset( $bits[
'port'] ) ) {
142 $like[] =
':' . $bits[
'port'];
144 if ( isset( $bits[
'path'] ) ) {
145 $like[] = $bits[
'path'];
146 } elseif ( !$subdomains ) {
149 if ( isset( $bits[
'query'] ) ) {
150 $like[] =
'?' . $bits[
'query'];
152 if ( isset( $bits[
'fragment'] ) ) {
153 $like[] =
'#' . $bits[
'fragment'];
157 foreach ( $like as $likepart ) {
158 if ( !( $likepart instanceof
LikeMatch ) && strpos( $likepart,
'*' ) !==
false ) {
163 if ( !( $like[count( $like ) - 1] instanceof
LikeMatch ) ) {
165 $like[] = $db->anyString();
179 if ( !is_array( $arr ) ) {
183 foreach ( $arr as $key =>
$value ) {
185 return array_slice( $arr, 0, $key + 1 );
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Some functions to help implement an external link filter for spam control.
static makeLikeArray( $filterEntry, $protocol='http://')
Make an array to be used for calls to Database::buildLike(), which will match the specified string.
static makeRegex( $filterEntry)
Builds a regex pattern for $filterEntry.
static matchEntry(Content $content, $filterEntry)
Check whether $content contains a link to $filterEntry.
static keepOneWildcard( $arr)
Filters an array returned by makeLikeArray(), removing everything past first pattern placeholder.
Content object implementation for representing flat text.
Base interface for content objects.
getNativeData()
Returns native representation of the data.