Last modified: 2011-10-25 14:30:48 UTC
The code in WikiEditor for detecting "external internal" links like http://en.wikipedia.org/wiki/Foobar is broken due to an incorrect regular expression. The following code appears in ext.wikiEditor.dialogs.js in 1.17.0 (and in jquery.wikiEditor.dialogs.config.js in later MW versions): $(this).data( 'articlePathRegex', new RegExp( '^' + $.escapeRE( mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ) ) .replace( /\\\$1/g, '(.*)' ) + '$' ) ); The problem is that $.escapeRE converts this string: http://mywiki.com/wiki/$1 into: "^http\:\/\/mywiki\.com\/wiki\/\$\1$" The problem is the slash before the "1". As a result, the replacement: .replace( /\\\$1/g, '(.*)' ) + '$' fails to match, so the $1 does not get replaced by "(.*)". A quick fix would be to change the replace() call to: .replace( /\\\$\\1/g, '(.*)' ) + '$' but honestly, I don't understand why $.escapeRE turns "$1" into "\$\1". I think it should be turning it into "\$1". Maybe $1 has special meaning to $.escapeRE, as a back-reference or something?
Created attachment 9183 [details] Patch for regular expression problem
$.escapeRE() should be fixed here. I'll investigate.
>>> $.escapeRE("http://mywiki.com/wiki/$1") "http://mywiki\.com/wiki/\$1" Is what I get in trunk (where $.escapeRE() has been moved to trunk/phase3/resources/jquery/jquery.mwExtension.js). Which version did you get your results on?
I am using 1.17.0. Firebug gives the buggy results: >>> $.escapeRE("http://mywiki.com/wiki/$1"); "http\:\/\/mywiki\.com\/wiki\/\$\1" When I hit English Wikipedia and check against 1.18.0wmf, I get correct results: >>> $.escapeRE("http://mywiki.com/wiki/$1"); "http://mywiki\.com/wiki/\$1" There might still be a problem on English Wikipedia however, because of the following use case: 0. Visit en.wikipedia.org and edit any page. 1. Click the Link button in the editor. 2. Enter http://en.wikipedia.org/wiki/Dog as the link and click "Insert link". 3. You *should* get a pop-up dialog that says "The URL you specified looks like it was intended as a link to another wiki page. Do you want to make it an internal link?" (message MediaWiki:Wikieditor-toolbar-tool-link-lookslikeinternal), however no dialog appears.
(In reply to comment #4) > I am using 1.17.0. Firebug gives the buggy results: > > >>> $.escapeRE("http://mywiki.com/wiki/$1"); > "http\:\/\/mywiki\.com\/wiki\/\$\1" > > When I hit English Wikipedia and check against 1.18.0wmf, I get correct > results: > > >>> $.escapeRE("http://mywiki.com/wiki/$1"); > "http://mywiki\.com/wiki/\$1" > > There might still be a problem on English Wikipedia however, because of the > following use case: > > 0. Visit en.wikipedia.org and edit any page. > 1. Click the Link button in the editor. > 2. Enter http://en.wikipedia.org/wiki/Dog as the link and click "Insert link". > 3. You *should* get a pop-up dialog that says "The URL you specified looks like > it was intended as a link to another wiki page. Do you want to make it an > internal link?" (message > MediaWiki:Wikieditor-toolbar-tool-link-lookslikeinternal), however no dialog > appears. Hah, that's probably because wgServer is protocol-relative now: >>> mw.config.get('wgServer') "//en.wikipedia.org"
Fixed in r100699.