Page MenuHomePhabricator

Add {{hashencode:}}
Closed, ResolvedPublic

Description

While need to link to other wikimedia projects using querystring (?) and section
(#) there's need to encode the section name properly.

{{urlencode:}} as well as {{fullurl:}} as well as automatical url encoding in
browswer's address bar replaces "á" with "%C3%A1" but the element id in xhtml
source is ".C3.A1"

Therefore {{hashencode:}} (or choose another name you want) would do just regexp
substitution % -> . in {{urlencode:}}d string

Example:
[{{localurl:Commons:{{{1}}}}}?uselang=cs{{#if:
{{{section|}}}|#{{hashencode:{{{section}}}}}}} {{{2}}}]
would be able to point to such section on commons page and set the proper language.


Version: unspecified
Severity: enhancement

Details

Reference
bz7059

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:25 PM
bzimport set Reference to bz7059.
bzimport added a subscriber: Unknown Object (MLST).

ayg wrote:

Trivial, of course:
static function anchorencode( $parser, $s = '' ) {

		return str_replace('%','.',urlencode( $s ));

}

robchur wrote:

Added "anchorencode" colon function in SVN trunk, r16279.

Reopening - it needs one more replace ("+" → "_"):

static function anchorencode( $parser, $s = '' ) {
return str_replace('%','.',str_replace('+','_',urlencode( $s )));
}

jimmy.collins wrote:

(In reply to comment #3)

Reopening - it needs one more replace ("+" → "_"):

Done in r16675.