* (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.
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;
+ }
}
/**
--- /dev/null
+<?php
+
+class ParserOutputTest extends MediaWikiTestCase {
+
+ function dataIsLinkInternal() {
+ return array(
+ // Different domains
+ array( false, 'http://example.org', 'http://mediawiki.org' ),
+ // Same domains
+ array( true, 'http://example.org', 'http://example.org' ),
+ array( true, 'https://example.org', 'https://example.org' ),
+ array( true, '//example.org', '//example.org' ),
+ // Same domain different cases
+ array( true, 'http://example.org', 'http://EXAMPLE.ORG' ),
+ // Paths, queries, and fragments are not relevant
+ array( true, 'http://example.org', 'http://example.org/wiki/Main_Page' ),
+ array( true, 'http://example.org', 'http://example.org?my=query' ),
+ array( true, 'http://example.org', 'http://example.org#its-a-fragment' ),
+ // Different protocols
+ array( false, 'http://example.org', 'https://example.org' ),
+ array( false, 'https://example.org', 'http://example.org' ),
+ // Protocol relative servers always match http and https links
+ array( true, '//example.org', 'http://example.org' ),
+ array( true, '//example.org', 'https://example.org' ),
+ // But they don't match strange things like this
+ array( false, '//example.org', 'irc://example.org' ),
+ );
+ }
+
+ /**
+ * Test to make sure ParserOutput::isLinkInternal behaves properly
+ * @dataProvider dataIsLinkInternal
+ */
+ function testIsLinkInternal( $shouldMatch, $server, $url ) {
+
+ $this->assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
+ }
+}