Add pear/Net_SMTP 1.7.3 to composer dependencies
[lhc/web/wiklou.git] / includes / LinkFilter.php
index 48d5cd8..790e2be 100644 (file)
@@ -19,6 +19,7 @@
  *
  * @file
  */
+use Wikimedia\Rdbms\LikeMatch;
 
 /**
  * Some functions to help implement an external link filter for spam control.
@@ -35,13 +36,13 @@ class LinkFilter {
        /**
         * Check whether $content contains a link to $filterEntry
         *
-        * @param $content Content: content to check
-        * @param string $filterEntry domainparts, see makeRegex() for more details
-        * @return Integer: 0 if no match or 1 if there's at least one match
+        * @param Content $content Content to check
+        * @param string $filterEntry Domainparts, see makeRegex() for more details
+        * @return int 0 if no match or 1 if there's at least one match
         */
        static function matchEntry( Content $content, $filterEntry ) {
                if ( !( $content instanceof TextContent ) ) {
-                       //TODO: handle other types of content too.
+                       // TODO: handle other types of content too.
                        //      Maybe create ContentHandler::matchFilter( LinkFilter ).
                        //      Think about a common base class for LinkFilter and MagicWord.
                        return 0;
@@ -49,7 +50,7 @@ class LinkFilter {
 
                $text = $content->getNativeData();
 
-               $regex = LinkFilter::makeRegex( $filterEntry );
+               $regex = self::makeRegex( $filterEntry );
                return preg_match( $regex, $text );
        }
 
@@ -58,7 +59,7 @@ class LinkFilter {
         *
         * @param string $filterEntry URL, if it begins with "*.", it'll be
         *        replaced to match any subdomain
-        * @return String: regex pattern, for preg_match()
+        * @return string Regex pattern, for preg_match()
         */
        private static function makeRegex( $filterEntry ) {
                $regex = '!http://';
@@ -71,7 +72,7 @@ class LinkFilter {
        }
 
        /**
-        * Make an array to be used for calls to DatabaseBase::buildLike(), which
+        * 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
@@ -87,12 +88,12 @@ class LinkFilter {
         * This function does the same as wfMakeUrlIndexes(), except it also takes care
         * of adding wildcards
         *
-        * @param String $filterEntry domainparts
-        * @param String $protocol protocol (default http://)
-        * @return Array to be passed to DatabaseBase::buildLike() or false on error
+        * @param string $filterEntry Domainparts
+        * @param string $protocol Protocol (default http://)
+        * @return array|bool Array to be passed to Database::buildLike() or false on error
         */
        public static function makeLikeArray( $filterEntry, $protocol = 'http://' ) {
-               $db = wfGetDB( DB_MASTER );
+               $db = wfGetDB( DB_REPLICA );
 
                $target = $protocol . $filterEntry;
                $bits = wfParseUrl( $target );
@@ -171,8 +172,8 @@ class LinkFilter {
         * Filters an array returned by makeLikeArray(), removing everything past first
         * pattern placeholder.
         *
-        * @param array $arr array to filter
-        * @return array filtered array
+        * @param array $arr Array to filter
+        * @return array Filtered array
         */
        public static function keepOneWildcard( $arr ) {
                if ( !is_array( $arr ) ) {