MediaWiki API部分名称编码 [英] MediaWiki API section names encoding
问题描述
对于 [[Test#?]] ,我从MediaWiki API的action=parse
位获得了" Test#.3F ".这种编码是什么?如何使用 Perl 的
For [[Test#?]], I get "Test#.3F" from action=parse
bit of MediaWiki API. What is this encoding and how do I bring it to human readable format using Perl's CPAN?
URI :: Encode 适用于百分比解码,但该部分名称不适用
URI::Encode works for the percent decoding, but not the section names one.
推荐答案
采用UTF-8百分比编码,但使用.
而不是%
,并用下划线替换空格;另外,多个连续的空格被折叠,并且:
被保留(未编码为.3A
).
It is UTF-8 percent-encoding, but with .
instead of %
, and spaces replaced with underscores; additionally, multiple consecutive whitespaces are collapsed, and :
is preserved (not encoded into .3A
).
处理它的确切代码是解析器:: guessSectionNameFromWikiText(),但是如果您不想挖掘大量代码,请在
The exact code which handles it is Parser::guessSectionNameFromWikiText(), but if you do not want to dig through a lot of code, check the much simpler implementation in an older MediaWiki version (compatible except for a few edge cases), in anchorencode():
str_replace( '%', '.', str_replace('+', '_', urlencode( $text ) ) );
这篇关于MediaWiki API部分名称编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!