r91869 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91868‎ | r91869 | r91870 >
Date:09:54, 11 July 2011
Author:diebuche
Status:resolved (Comments)
Tags:
Comment:
use tab name, not tab index for anchors on Special:Preferences. Bug 29672 . Patch by Jarry1250. Ping r91757
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.preferences.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -701,7 +701,7 @@
702702 }
703703 $attributes = array();
704704 if ( $displayTitle ) {
705 - $attributes["title"] = $key;
 705+ $attributes["title"] = Sanitizer::escapeId( $key );
706706 }
707707 $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n";
708708 }
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.preferences.js
@@ -17,14 +17,15 @@
1818 if ( i === 0 ) {
1919 $(legend).parent().show();
2020 }
 21+ var ident = $(legend).parent().attr( 'title' );
2122 $( '#preftoc' ).append(
2223 $( '<li></li>' )
2324 .addClass( i === 0 ? 'selected' : null )
2425 .append(
2526 $( '<a></a>')
2627 .text( $(legend).text() )
27 - .attr( 'id', 'preftab-' + i + '-tab' )
28 - .attr( 'href', '#preftab-' + i ) // Use #preftab-N instead of #prefsection-N to avoid jumping on click
 28+ .attr( 'id', 'preftab-' + ident + '-tab' )
 29+ .attr( 'href', '#preftab-' + ident ) // Use #preftab-N instead of #prefsection-N to avoid jumping on click
2930 .click( function() {
3031 $(this).parent().parent().find( 'li' ).removeClass( 'selected' );
3132 $(this).parent().addClass( 'selected' );
@@ -41,7 +42,7 @@
4243 // On document ready:
4344 $( function() {
4445 var hash = window.location.hash;
45 - if( hash.match( /^#preftab-[\d]+$/ ) ) {
 46+ if( hash.match( /^#preftab-/ ) ) {
4647 var $tab = $( hash + '-tab' );
4748 $tab.click();
4849 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r91929followup r91869: validate id chars for incoming prefs tabs in hash ([\w-]+ is...brion23:51, 11 July 2011
r92155Restructure tab code of mediawiki.special.preferences.js . * 10 levels of ind...diebuche12:49, 14 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91757HTMLForm: Add option to output a title for a fieldset & activate it for Speci...diebuche21:12, 8 July 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   23:48, 11 July 2011

This puts unvalidated input into the creation of a jQuery selector; while it may not be exploitable, it's sloppy. Recommend validating with a basic ascii id regex.

#Comment by Brion VIBBER (talk | contribs)   23:51, 11 July 2011

did that real quick in r91929 -- otherwise looks good!

#Comment by Duplicatebug (talk | contribs)   17:07, 12 July 2011

Not backward compatible. If needed, you can reach that with adding 'preftab-' + i + '-tab' also as id and allow \d in javascript.

#Comment by Brion VIBBER (talk | contribs)   17:14, 12 July 2011

I'm quite willing to lose back-compatibility on the prefs tab links -- they're nonessential, easily worked around, and only started being linkable quite recently; the digit paging makes such links inherently unstable (as a code change, extension or configuration change may add and re-order tabs quite legitimately). Switching to symbolic names makes the new links actually stable -- as long as we don't change the name key, the order of other tabs won't make a difference to future link-followers.

#Comment by Nikerabbit (talk | contribs)   10:38, 14 July 2011

Not sure if it was introduced in this revision but now I get the tab name as tooltip when hovering preferences.

#Comment by DieBuche (talk | contribs)   12:50, 14 July 2011

Status & tagging log