merge latest master into Wikidata branch
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
index cf8b4a9..3bf510f 100644 (file)
@@ -150,11 +150,35 @@ class ParserOutput extends CacheTime {
                return (bool)$this->mNewSection;
        }
 
+       /**
+        * Checks, if a url is pointing to the own server
+        *
+        * @param $internal String the server to check against
+        * @param $url String the url to check
+        * @return bool
+        */
+       static function isLinkInternal( $internal, $url ) {
+               return (bool)preg_match( '/^' .
+                       # If server is proto relative, check also for http/https links
+                       ( substr( $internal, 0, 2 ) === '//' ? '(?:https?:)?' : '' ) .
+                       preg_quote( $internal, '/' ) .
+                       # check for query/path/anchor or end of link in each case
+                       '(?:[\?\/\#]|$)/i',
+                       $url
+               );
+       }
+
        function addExternalLink( $url ) {
                # We don't register links pointing to our own server, unless... :-)
                global $wgServer, $wgRegisterInternalExternals;
-               if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
+
+               $registerExternalLink = true;
+               if( !$wgRegisterInternalExternals ) {
+                       $registerExternalLink = !self::isLinkInternal( $wgServer, $url );
+               }
+               if( $registerExternalLink ) {
                        $this->mExternalLinks[$url] = 1;
+               }
        }
 
        /**