{{FILEPATH:{{PAGENAME}} }} doesn't work for filenames containing characters that get escaped to HTML entities
OpenPublic

Description

Author: phoenixct

Description:
The command {{FILEPATH:{{PAGENAME}} }} in page with non-ASCII characters in name doesn't work.


Version: unspecified
Severity: major
URL: http://commons.wikimedia.org/wiki/Image:Aci_Sant'Antonio.svg

bzimport added a project: MediaWiki-Templates.Via ConduitNov 21 2014, 10:29 PM
bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz16474.
bzimport created this task.Via LegacyNov 27 2008, 7:27 PM
bzimport added a comment.Via ConduitNov 28 2008, 5:48 AM

herd wrote:

It isn't unicode, which works fine, it happens with the following characters (which are allowed in page titles): & " ' which, in {{PAGENAME}} and related magic words, get escaped to their HTML entities before parser function expansion: " & ' ... renaming but to reflect this.

A workaround is to use [[Special:Filepath/{{PAGENAME}}]].
http://en.wikipedia.org/wiki/Special:ExpandTemplates?contexttitle=Image%3AAci_Sant%27Antonio.svg&input=%23-+%7B%7BPAGENAME%7D%7D%0D%0A%23-+%7B%7Bfilepath%3A%7B%7BPAGENAMEE%7D%7D%7D%7D%0D%0A%23-+%5B%5BSpecial%3AFilepath%2F%7B%7BPAGENAME%7D%7D%5D%5D%0D%0A&removecomments=1&generate_xml=1

This might be a dupe of an existing magic word/entity bug?

bzimport added a comment.Via ConduitNov 28 2008, 9:41 AM

phoenixct wrote:

Workaround can't be used in template like http://commons.wikimedia.org/wiki/Template:ValidSVG, because it doesn't work well inside "[" "]" url address.

bzimport added a comment.Via ConduitNov 28 2008, 6:41 PM

herd wrote:

That workaround can still be used, you just have to use urlencode and fullurl (admittedly uglier URLs though).
http://commons.wikimedia.org/w/index.php?title=Template:ValidSVG&diff=16376628&oldid=15911588

That seems to work, at least temporarily until {{PAGENAME}} gets fixed?

brion added a comment.Via ConduitDec 18 2008, 7:51 PM

Looks like the same base problem as bug 14779...

Rich_Farmbrough added a comment.Via ConduitOct 2 2009, 6:28 PM

Also seems to apply to the output of other magic Words, even simple ones like LC. We risk getting into the situation where people are relying on the broken behaviour, and fixing it will then break stuff.

bzimport added a comment.Via ConduitMar 11 2010, 7:19 AM
Umherirrender added a comment.Via ConduitApr 21 2010, 6:23 PM
  • Bug 23253 has been marked as a duplicate of this bug. ***
duplicatebug added a comment.Via ConduitAug 30 2010, 7:46 PM
  • Bug 24938 has been marked as a duplicate of this bug. ***
bzimport added a comment.Via ConduitOct 15 2010, 4:23 PM

a.d.bergi wrote:

I'm not sure whether it was already posted, but
{{NAMESPACE:xyz}} and
{{PAGENAME:xyz}}
are also not working with "<", ">" or their html-escaped equivalents &amp;lt; and &amp;gt;. The quote characters (",') are OK in here.
I think it belongs to this bug, please fix me.

Umherirrender added a comment.Via ConduitOct 26 2010, 7:21 PM

(In reply to comment #9)

I'm not sure whether it was already posted, but
{{NAMESPACE:xyz}} and
{{PAGENAME:xyz}}
are also not working with "<", ">" or their html-escaped equivalents &amp;lt;
and &amp;gt;. The quote characters (",') are OK in here.
I think it belongs to this bug, please fix me.

"<" and ">" are not allow inside titles, see [[mw:Manual:$wgLegalTitleChars]], so there are cannot work with NAMESPACE or PAGENAME.

Umherirrender added a comment.Via ConduitOct 26 2010, 7:35 PM

(In reply to comment #4)

Looks like the same base problem as bug 14779...

No, using "$title = Title::newFromText( $name );" and give the $title to wfFindFile works (with or without "File:"-prefix). But that doesnot work with urlencode title, that is bug 14779.

wfFindFile is using Title::makeTitleSafe, which use Tilte::makeTitle for the mDbkeyform. Title::newFromText use Sanitizer::decodeCharReferencesAndNormalize and that normalize the &quot; &amp; &#39;.

It looks like, newFromText should used for all Titles from Wikitext and makeTitleSafe should used for form given titles. So this parser function use the wrong method.

Umherirrender added a comment.Via ConduitOct 26 2010, 7:37 PM

(In reply to comment #6)

Related issue:
{{PAGESINCATEGORY:{{PAGENAME}}}} doesn't work on categories with a '

PAGESINCATEGORY used Category::newFromName which use Title::makeTitleSafe -> see comment 11

Umherirrender added a comment.Via ConduitOct 27 2010, 1:20 PM

(In reply to comment #11)

... ([wfFindFile works] with or without "File:"-prefix). ...

reported as bug 25670

MarkAHershberger added a comment.Via ConduitApr 4 2012, 3:09 PM

See also bug 35628

Verdy_p added a comment.Via ConduitFeb 15 2014, 8:35 AM

Workaround:

  • filter the fiven file name / page name / category name, containing HTML entities as returned by various parser functions (like lc:, uc:, #if:, #switch:...), through #titleparts to convert back these HTML entities to plain characters
  • this returned value can be passed to parsers functions that do not like these HTML entities: PAGESINCATEGORY, FILEPATH, #ifexist...

The HTML entities we need to handle are notably those characters:

' " &

which are valid in page names (the < and > characters are not valid in
pagenames, they will remain encoded after calling #titleparts).

For details about te various encodings used in page names, see

[[mw:Manual:PAGENAMEE encoding]]

which details how characters may get encoded.
This covers the full ASCII set, and the first printable non-ASCII characters (tested with UTF-8 assumed for their plain-text encoding).
This also covers some other contextual changes that may occur for some characters which are not encoded except in leading positions where they may be changed, or dropped, as well as those few charaters that get transformed within specific subsequences anywhere in the string (such as the slash and periods).

But I agree that functions like PAGESINCATEGORY, FILEPATH... should properly decode these HTML entities (and notably the 3 characters above; the most frequent one encountered being the ASCII apostrophe-quote).

gerritbot added a comment.Via ConduitJul 11 2014, 11:48 PM

Change 145724 had a related patch set uploaded by Brian Wolff:
Have Title::makeTitleSafe decode html entities.

https://gerrit.wikimedia.org/r/145724

Add Comment