- /**
- * Return an appropriately formatted LIKE query and the clause
- *
- * @param string $query Search pattern to search for
- * @param string $prot Protocol, e.g. 'http://'
- *
- * @return array
- */
- static function mungeQuery( $query, $prot ) {
- $field = 'el_index';
- $dbr = wfGetDB( DB_REPLICA );
-
- if ( $query === '*' && $prot !== '' ) {
- // Allow queries like 'ftp://*' to find all ftp links
- $rv = [ $prot, $dbr->anyString() ];
- } else {
- $rv = LinkFilter::makeLikeArray( $query, $prot );
- }
-
- if ( $rv === false ) {
- // LinkFilter doesn't handle wildcard in IP, so we'll have to munge here.
- $pattern = '/^(:?[0-9]{1,3}\.)+\*\s*$|^(:?[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]*\*\s*$/';
- if ( preg_match( $pattern, $query ) ) {
- $rv = [ $prot . rtrim( $query, " \t*" ), $dbr->anyString() ];
- $field = 'el_to';
- }
- }
-
- return [ $rv, $field ];
- }
-