Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
— | — | @@ -124,8 +124,37 @@ |
125 | 125 | return wfUrlencode( str_replace( ' ', '_', self::ns( $parser, $part1 ) ) ); |
126 | 126 | } |
127 | 127 | |
128 | | - static function urlencode( $parser, $s = '' ) { |
129 | | - return urlencode( $s ); |
| 128 | + /** |
| 129 | + * urlencodes a string according to one of three patterns: (bug 22474) |
| 130 | + * |
| 131 | + * By default (for HTTP "query" strings), spaces are encoded as '+'. |
| 132 | + * Or to encode a value for the HTTP "path", spaces are encoded as '%20'. |
| 133 | + * For links to "wiki"s, or similar software, spaces are encoded as '_', |
| 134 | + * |
| 135 | + * @param $parser. |
| 136 | + * @param $s String: The text to encode. |
| 137 | + * @param $arg String (optional): The type of encoding. |
| 138 | + */ |
| 139 | + static function urlencode( $parser, $s = '', $arg = null ) { |
| 140 | + static $magicWords = null; |
| 141 | + if ( is_null( $magicWords ) ) { |
| 142 | + $magicWords = new MagicWordArray( array( 'url_path', 'url_query', 'url_wiki' ) ); |
| 143 | + } |
| 144 | + switch( $magicWords->matchStartToEnd( $arg ) ) { |
| 145 | + |
| 146 | + // Encode as though it's a wiki page, '_' for ' '. |
| 147 | + case 'url_wiki': |
| 148 | + return wfUrlencode( str_replace( ' ', '_', $s ) ); |
| 149 | + |
| 150 | + // Encode for an HTTP Path, '%20' for ' '. |
| 151 | + case 'url_path': |
| 152 | + return rawurlencode( $s ); |
| 153 | + |
| 154 | + // Encode for HTTP query, '+' for ' '. |
| 155 | + case 'url_query': |
| 156 | + default: |
| 157 | + return urlencode( $s ); |
| 158 | + } |
130 | 159 | } |
131 | 160 | |
132 | 161 | static function lcfirst( $parser, $s = '' ) { |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -352,6 +352,9 @@ |
353 | 353 | 'staticredirect' => array( 1, '__STATICREDIRECT__' ), |
354 | 354 | 'protectionlevel' => array( 1, 'PROTECTIONLEVEL' ), |
355 | 355 | 'formatdate' => array( 0, 'formatdate', 'dateformat' ), |
| 356 | + 'url_path' => array( 0, 'PATH' ), |
| 357 | + 'url_wiki' => array( 0, 'WIKI' ), |
| 358 | + 'url_query' => array( 0, 'QUERY' ), |
356 | 359 | ); |
357 | 360 | |
358 | 361 | /** |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -41,6 +41,8 @@ |
42 | 42 | changes list |
43 | 43 | * (bug 22925) "sp-contributions-blocked-notice-anon" message now displayed when |
44 | 44 | viewing contributions of a blocked IP address |
| 45 | +* (bug 22474) {{urlencode:}} now takes an optional second paramter for type of |
| 46 | + escaping. |
45 | 47 | |
46 | 48 | === Bug fixes in 1.17 === |
47 | 49 | * (bug 17560) Half-broken deletion moved image files to deletion archive |
Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -2177,6 +2177,21 @@ |
2178 | 2178 | !! end |
2179 | 2179 | |
2180 | 2180 | |
| 2181 | +!! test |
| 2182 | +Urlencode |
| 2183 | +!! input |
| 2184 | +{{urlencode:hi world?!}} |
| 2185 | +{{urlencode:hi world?!|WIKI}} |
| 2186 | +{{urlencode:hi world?!|PATH}} |
| 2187 | +{{urlencode:hi world?!|QUERY}} |
| 2188 | +!! result |
| 2189 | +<p>hi+world%3F%21 |
| 2190 | +hi_world%3F! |
| 2191 | +hi%20world%3F%21 |
| 2192 | +hi+world%3F%21 |
| 2193 | +</p> |
| 2194 | +!! end |
| 2195 | + |
2181 | 2196 | ### |
2182 | 2197 | ### Magic links |
2183 | 2198 | ### |