r90869 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90868‎ | r90869 | r90870 >
Date:05:07, 27 June 2011
Author:yaron
Status:deferred
Tags:
Comment:
Follow-up to r90863 - changed tab-name handling to work for all special characters in tab names, not just slashes
Modified paths:
  • /trunk/extensions/HeaderTabs/HeaderTabs_body.jq.php (modified) (history)

Diff [purge]

Index: trunk/extensions/HeaderTabs/HeaderTabs_body.jq.php
@@ -35,13 +35,14 @@
3636
3737 for ( $i = 0; $i < ( count( $parts ) / 2 ); $i++ ) {
3838 preg_match( '/id="(.*?)"/', $parts[$i * 2], $matches );
39 - // Forward slashes in tab IDs cause a problem
40 - // in the jQuery UI tabs() function -
41 - // replace them with two underlines (two, to
42 - // avoid conflicting with another tab that
43 - // might have the same name, but with a space
44 - // instead of a slash).
45 - $tabid = str_replace('.2F', '__', $matches[1]);
 39+ // Almost all special characters in tab IDs
 40+ // cause a problem in the jQuery UI tabs()
 41+ // function - in the URLs they already come out
 42+ // as URL-encoded, which is good, but for some
 43+ // reason it's as ".2F", etc., instead of
 44+ // "%2F" - so replace all "." with "_", and
 45+ // everything should be fine.
 46+ $tabid = str_replace('.', '_', $matches[1]);
4647
4748 preg_match( '/<span.*?class="mw-headline".*?>\s*(.*?)\s*<\/h1>/', $parts[$i * 2], $matches );
4849 $tabtitle = $matches[1];
@@ -77,8 +78,6 @@
7879 }
7980
8081 public static function addHTMLHeader( &$wgOut ) {
81 - global $htUseHistory; // unused, for now
82 -
8382 $wgOut->addModules( 'jquery.ui.tabs' );
8483 $js_text =<<<END
8584 <script type="text/javascript">
@@ -94,8 +93,18 @@
9594 $(".tabLink").click( function() {
9695 var href = $(this).attr('href');
9796 var tabName = href.replace( "#tab=", "" );
98 - // Fix for tabs with slashes in their name.
99 - tabName = tabName.replace( "/", "__" );
 97+ // Almost all non-alphanumeric characters in tab names cause
 98+ // problems for jQuery UI tabs, including '.'. The solution:
 99+ // URL-encode all the characters, then replace the resulting
 100+ // '%', plus '.', with '_'.
 101+ tabName = escape( tabName );
 102+ // For some reason, the JS escape() function doesn't handle
 103+ // '+', '/' or '@' - take care of these manually.
 104+ tabName = tabName.replace( /\+/g, "%2B" );
 105+ tabName = tabName.replace( /\//g, "%2F" );
 106+ tabName = tabName.replace( /@/g, "%40" );
 107+ tabName = tabName.replace( /%/g, "_" );
 108+ tabName = tabName.replace( /\./g, "_" );
100109 $("#headertabs").tabs('select', tabName);
101110 return false; //$htUseHistory;
102111 } );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90863Follow-up to r82583 - this time, an actual fix (I think) for slashes in tab n...yaron23:36, 26 June 2011

Status & tagging log