From: umherirrender Date: Sat, 29 Sep 2012 10:36:33 +0000 (+0200) Subject: (bug 32951) Do not register absolute internal externals X-Git-Tag: 1.31.0-rc.0~22175 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=a2e470ee686fd0e011a7b6225ca53a933e33b9a0;p=lhc%2Fweb%2Fwiklou.git (bug 32951) Do not register absolute internal externals Setting $wgRegisterInternalExternals = false for proto server should not store the http/https links in externallinks table Also fix detection of own links for links with query or anchor or nothing new also detected: //localhost //localhost?query //localhost#anchor already detected: //localhost/path Change-Id: Idd03d309cc3b71728a8cbea460efa12b10348d64 --- diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 0548946a09..50c3b2d83e 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -20,6 +20,8 @@ production. * (bug 40352) fixDoubleRedirects.php should support interwiki redirects. * (bug 9237) SpecialBrokenRedirect should not list interwiki redirects. * (bug 34960) Drop unused fields rc_moved_to_ns and rc_moved_to_title from recentchanges table. +* (bug 32951) Do not register internal externals with absolute protocol, + when server has relative protocol. === API changes in 1.21 === * (bug 35693) ApiQueryImageInfo now suppresses errors when unserializing metadata. diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 41b4a38550..be629d378a 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -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; + } } /** diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php new file mode 100644 index 0000000000..2244fdb932 --- /dev/null +++ b/tests/phpunit/includes/parser/ParserOutputTest.php @@ -0,0 +1,38 @@ +assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) ); + } +}