At 2010-08-24 15:44, lampak wrote: > On 24/08/10 15:25, Tgr wrote: >> lampak<llampak<at> gmail.com> writes: >> >>> Hi. I'm working on a script which edits a page, adds a section to it and >>> then redirects to this page. >>> >>> It would be nice if it went straight to the newly-created section. So I >>> need to create a link with # in it. >>> >>> The problem appears when the title of the section contains some >>> diacritics. For example, link to "bażant królewski" looks like >>> "Ba.C5.BCant_kr.C3.B3lewski". >>> >>> How can I generate in JavaScript such a link which would be identical to >>> the one generated by MediaWiki? Has somebody written such a function? Or >>> at least, do you know where it is done in MediaWiki php code? >> It is pretty simple as long as there is no wikitext or html in the title: >> convert it to urlencoded UTF-8 (encodeURIComponent does that), replace >> percent >> signs with dots, replace spaces with underscores. > I have tried encodeURIComponent before. Bażant królewski becomes > Bażant_królewski. Diacritics are not converted. At least not under Firefox. For basic examples you could use this: var txt = 'Zażółć'; txt = encodeURIComponent(encodeURI(txt).replace(/%/g, '.')).replace(/%/g, '.');
Not sure if encodeURI was in old IE (if you care ;-)), but it works with new browsers. Note that this will not work if the section contains mark up code. But as I understood you are not looking for something bulletproof. Regards, Nux. _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l