Index: trunk/extensions/ParserFunctions/ParserFunctions.i18n.magic.php |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | 'count' => array( 0, 'count' ), |
27 | 27 | 'replace' => array( 0, 'replace' ), |
28 | 28 | 'explode' => array( 0, 'explode' ), |
| 29 | + 'urldecode' => array( 0, 'urldecode' ), |
29 | 30 | ); |
30 | 31 | |
31 | 32 | $magicWords['ar'] = array( |
Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php |
— | — | @@ -767,4 +767,24 @@ |
768 | 768 | wfProfileOut( __METHOD__ ); |
769 | 769 | return $result; |
770 | 770 | } |
| 771 | + |
| 772 | + /** |
| 773 | + * {{#urldecode:string}} |
| 774 | + * |
| 775 | + * Decodes URL-encoded (like%20that) strings. |
| 776 | + */ |
| 777 | + function runUrlDecode( $parser, $inStr = '' ) { |
| 778 | + wfProfileIn( __METHOD__ ); |
| 779 | + |
| 780 | + $inStr = $this->killMarkers( $parser, (string)$inStr ); |
| 781 | + if ( !$this->checkLength( $inStr ) ) { |
| 782 | + wfProfileOut( __METHOD__ ); |
| 783 | + return $this->tooLongError(); |
| 784 | + } |
| 785 | + |
| 786 | + $result = urldecode( $inStr ); |
| 787 | + |
| 788 | + wfProfileOut( __METHOD__ ); |
| 789 | + return $result; |
| 790 | + } |
771 | 791 | } |
Index: trunk/extensions/ParserFunctions/ParserFunctions.php |
— | — | @@ -92,13 +92,14 @@ |
93 | 93 | |
94 | 94 | //String Functions |
95 | 95 | if ( $wgPFEnableStringFunctions ) { |
96 | | - $parser->setFunctionHook( 'len', array(&$this, 'runLen' )); |
97 | | - $parser->setFunctionHook( 'pos', array(&$this, 'runPos' )); |
98 | | - $parser->setFunctionHook( 'rpos', array(&$this, 'runRPos' )); |
99 | | - $parser->setFunctionHook( 'sub', array(&$this, 'runSub' )); |
100 | | - $parser->setFunctionHook( 'count', array(&$this, 'runCount' )); |
101 | | - $parser->setFunctionHook( 'replace', array(&$this, 'runReplace' )); |
102 | | - $parser->setFunctionHook( 'explode', array(&$this, 'runExplode' )); |
| 96 | + $parser->setFunctionHook( 'len', array( &$this, 'runLen' ) ); |
| 97 | + $parser->setFunctionHook( 'pos', array( &$this, 'runPos' ) ); |
| 98 | + $parser->setFunctionHook( 'rpos', array( &$this, 'runRPos' ) ); |
| 99 | + $parser->setFunctionHook( 'sub', array( &$this, 'runSub' ) ); |
| 100 | + $parser->setFunctionHook( 'count', array( &$this, 'runCount' ) ); |
| 101 | + $parser->setFunctionHook( 'replace', array( &$this, 'runReplace' ) ); |
| 102 | + $parser->setFunctionHook( 'explode', array( &$this, 'runExplode' ) ); |
| 103 | + $parser->setFunctionHook( 'urldecode', array( &$this, 'runUrlDecode' ) ); |
103 | 104 | } |
104 | 105 | |
105 | 106 | return true; |
Index: trunk/extensions/ParserFunctions/funcsParserTests.txt |
— | — | @@ -175,3 +175,17 @@ |
176 | 176 | <p>false |
177 | 177 | </p> |
178 | 178 | !! end |
| 179 | + |
| 180 | +!! test |
| 181 | +#urldecode |
| 182 | +!! input |
| 183 | +{{#urldecode:}} |
| 184 | +{{#urldecode:foo%20bar}} |
| 185 | +{{#urldecode:%D0%9C%D0%B5%D0%B4%D0%B8%D0%B0%D0%92%D0%B8%D0%BA%D0%B8}} |
| 186 | +{{#urldecode: some unescaped string}} |
| 187 | +!! result |
| 188 | +<p>foo bar |
| 189 | +МедиаВики |
| 190 | +some unescaped string |
| 191 | +</p> |
| 192 | +!! end |