MediaWiki talk:Common.js/Archive 4: Difference between revisions

Content deleted Content added
Shadowbot3 (talk | contribs)
m Automated archival of 1 sections from MediaWiki talk:Common.js
Shadowbot3 (talk | contribs)
m Automated archival of 1 sections from MediaWiki talk:Common.js
Line 21:
 
::Thanks Ruud! For the explanation and the fix. [[User:Grouse|Grouse]] 16:19, 3 March 2007 (UTC)
<span id="63298430893" />
== escape() and replace() in importScript function ==
 
I read this [[MediaWiki_talk:Common.js/Archive_2#Import_Module|December discussion about import module]] but I still don't see why <tt>escape()</tt> is there in the first place. Can you please give me an example when it's really needed? As far as I can see, it doesn't work for 2-byte Unicode characters anyway, so in [[:ru:MediaWiki:Common.js]] we had to remove it so far.
Same question for <tt>replace()</tt>: everything seems to work fine without it, even with spaces in the script path.
— [[User:Alex Smotrov|Alex Smotrov]] 20:48, 3 March 2007 (UTC)
 
:The only reason for <code>escape()</code> to be there is to avoid problems with ampersands and percent signs. You're right that <code>escape()</code> produces weird results with non-ASCII Unicode (e.g. "Б" becomes "%u0411", which makes Apache choke). It looks like the appropriate function may actually be <code>encodeURIComponent()</code>. Using that function instead of <code>escape()</code>, "Б" is encoded as "%D0%91" instead of "%u0411", which Apache and MediaWiki interpret correctly as the UTF-8 encoding of "Б". (Tested on Galeon/Mozilla 1.7, Firefox 2.0, and IE 6.0) [[User talk:Mike Dillon|Mike Dillon]] 21:02, 3 March 2007 (UTC)
 
:: Thank you for the answer. I've yet to see any real users with & or % (and they can always specify the correct way to call their modules in their documentation). But since our version of <code>importScript()</code> can import from other Wikipedias, I guess it's better to be consistent and I'll recommend our admins to use <code>encodeURIComponent</code> [http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&curid=763577&diff=112423294&oldid=112202941 as well]. Still <code>page.replace</code> was not and is not necessary unless there is slight perfomance difference for Mediawiki servers or we're simply willing to save 2 bytes in URL ( _ vs %20 ). — [[User:Alex Smotrov|Alex Smotrov]] 00:11, 4 March 2007 (UTC)
 
::: I ''may'' avoid a HTTP redirect from "Page%20name" (from the escaped/URI-component encoded "Page name") to "Page_name". I'm not entirely sure yet which mechanism is used to rewrite those URLs, but the performance gain/loss of the replace is very likely insignificant. —''[[User:Ruud Koot|Ruud]]'' 00:50, 4 March 2007 (UTC)
 
::::You're correct that it avoids an HTTP redirect. I just tested it. [[User talk:Mike Dillon|Mike Dillon]] 17:28, 5 March 2007 (UTC)