r91663 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91662‎ | r91663 | r91664 >
Date:18:26, 7 July 2011
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
(bug 29497) To support protocol-relative URLs in external links, add '//' to $wgUrlProtocols and remove a useless \b in the bracketed external link regex in the parser that prevented the former from working outright. With this change, things like [//example.com/wiki/Foo Bar] are now supported, and [[{fullurl:Foo|action=edit}} Bar] no longer breaks if $wgServer is set to '//example.com' but produces a protocol-relative link instead. Protocol-relative URLs in free text are not picked up and turned into [1] links like URLs with protcols are; this is probably due to another \b somewhere, but I think this is a good thing.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -183,7 +183,7 @@
184184 public function __construct( $conf = array() ) {
185185 $this->mConf = $conf;
186186 $this->mUrlProtocols = wfUrlProtocols();
187 - $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'.
 187+ $this->mExtLinkBracketedRegex = '/\[((' . wfUrlProtocols() . ')'.
188188 '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S';
189189 if ( isset( $conf['preprocessorClass'] ) ) {
190190 $this->mPreprocessorClass = $conf['preprocessorClass'];
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2790,6 +2790,7 @@
27912791 'svn://',
27922792 'git://',
27932793 'mms://',
 2794+ '//', // for protocol-relative URLs
27942795 );
27952796
27962797 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r92006Parser tests for protocol-relative URLs, for r91663 and r92005catrope20:56, 12 July 2011
r921721.17wmf1: MFT protocol-relative URL fixes: r91663, r92024, r92028, r92036, r9...catrope17:48, 14 July 2011

Comments

#Comment by MZMcBride (talk | contribs)   20:41, 7 July 2011

Are there parser tests for this?

#Comment by Catrope (talk | contribs)   16:44, 12 July 2011

Good point.

#Comment by Catrope (talk | contribs)   01:28, 13 July 2011

Added parser tests. This even exposed a bug in the handling of protocol-relative URLs that was traced back to 2006, so thanks for that suggestion :)

Status & tagging log