Last modified: 2012-08-29 16:45:47 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T32471, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 30471 - MediaWiki should not generate ids that are hard to select
MediaWiki should not generate ids that are hard to select
Status: REOPENED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.20.x
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-08-20 01:03 UTC by Helder
Modified: 2012-08-29 16:45 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Helder 2011-08-20 01:03:33 UTC
If a page has a section such as[1]
    = Português =

or[2]
    == mediaWiki.loader ==

then the ids generated by MediaWiki are "Portugu.C3.AAs" and "mediaWiki.loader" respectively. This makes it impossible to select those specific sections by using
    jQuery( '#Portugu.C3.AAs' );
or
    jQuery( '#mediaWiki.loader' );
or equivalently in CSS,
    #Portugu.C3.AAs {
        color: red;
    }
since the dot "." is interpreted as a class selector.

* Why does MW adds those dots in the first example?
* Would it be possible to fix this?


[1] http://pt.wiktionary.org/w/index.php?title=escudismo&oldid=278201&uselang=en
[2] [[mw:RL/DM#mediaWiki.loader]]
Comment 1 Roan Kattouw 2011-08-20 07:11:46 UTC
(In reply to comment #0)
> If a page has a section such as[1]
>     = Português =
> 
> or[2]
>     == mediaWiki.loader ==
> 
> then the ids generated by MediaWiki are "Portugu.C3.AAs" and "mediaWiki.loader"
> respectively. This makes it impossible to select those specific sections by
> using
>     jQuery( '#Portugu.C3.AAs' );
> or
>     jQuery( '#mediaWiki.loader' );
> or equivalently in CSS,
>     #Portugu.C3.AAs {
>         color: red;
>     }
> since the dot "." is interpreted as a class selector.
> 
You can escape dots in ID selectors. In CSS:
#mediaWiki\.loader { color: red; }

in jQuery:
$( '#mediaWiki\\.loader );  // double \ needed to produce one \ in the string
Comment 2 Krinkle 2012-08-29 13:04:45 UTC
(In reply to comment #1)
> You can escape dots in ID selectors. In CSS:
> #mediaWiki\.loader { color: red; }
> 
> in jQuery:
> $( '#mediaWiki\\.loader );  // double \ needed to produce one \ in the string

I agree it is indeed not impossible. But looking at the wider picture: MediaWIki sanitizes the textual content of the heading and creates an ID that doesn't contain illegal characters. But since it is somewhat sanitized already (just like we do for class names, though we do a better job there) I think it is perfectly reasonable to make this sanitize dots and other charaters as well.

It doesn't have to be impossible, but making it convenient and optimized for usage in CSS is just as important. Since the only reason we output them is for usage in CSS (and by JavaScript, and for anchor-jumping), it makes perfect sense to optimize for that usage and not require escaping in 2/3 use cases.

[[Sandbox.js]]
> Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() )
> <body class=" .... page-Sandbox_js ..">

Looks nice.

== Sandbox.js {foo[test]} ==

> .. class="mw-headline" id="Sandbox.js_.7Bfoo.5Btest.5D.7D"> Sandbox.js {foo[test]} ..

That's pretty horrible and not justifiable in my opinion.


> .. class="mw-headline" id="Sandbox_js_foo_test_"> Sandbox.js {foo[test]} ..

The above would be much better (stripping unwanted characters, non-repeating, uniqueness would be enforced with incrementing numbers appended, like we do already for similar headings).

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links