r106054 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106053‎ | r106054 | r106055 >
Date:18:30, 13 December 2011
Author:yaron
Status:deferred
Tags:
Comment:
Follow-up to r106028 and r106032 - code cleanup
Modified paths:
  • /trunk/extensions/HeaderTabs/HeaderTabs.php (modified) (history)
  • /trunk/extensions/HeaderTabs/HeaderTabs_body.jq.php (modified) (history)
  • /trunk/extensions/HeaderTabs/skins-jquery/ext.headertabs.bare.css (modified) (history)
  • /trunk/extensions/HeaderTabs/skins-jquery/ext.headertabs.core.js (modified) (history)
  • /trunk/extensions/HeaderTabs/skins-jquery/ext.headertabs.jquery-large.css (modified) (history)

Diff [purge]

Index: trunk/extensions/HeaderTabs/skins-jquery/ext.headertabs.bare.css
@@ -1,5 +1,5 @@
22 /**
3 - * A more Vector like tabs with normal sized text, blue links, and shiny tabs.
 3+ * More Vector-like tabs, with normal sized text, blue links, and shiny tabs.
44 *
55 * @file
66 * @ingroup Extensions
@@ -11,7 +11,7 @@
1212 /* JQuery UI tabs clearing styles by Olivier Finlay Beaton and 70.189.238.136 */
1313 #headertabs.bare.ui-widget {
1414 font-family: inherit;
15 - font-size: 1em; /* ie doesn't like inherit here */
 15+ font-size: 1em; /* IE doesn't like inherit here */
1616 }
1717
1818 #headertabs.bare.ui-widget-content {
@@ -37,14 +37,14 @@
3838 border-bottom-color: #cccccc;
3939 }
4040
41 -/* section by 70.189.238.136, for things I forgot, thanks! */
 41+/* section by 70.189.238.136 */
4242 #headertabs.bare .ui-widget input, #headertabs.bare .ui-widget select, #headertabs.bare .ui-widget textarea, #headertabs.bare .ui-widget button { font-family: inherit; font-size: 1em; } /* ie doesn't like inherit here */
4343 #headertabs.bare .ui-widget-content a { color:#0645AD; }
4444 #headertabs.bare .ui-widget-content a:visited { color:#0b0080; }
4545 #headertabs.bare .ui-widget-content a.new { color:#CC2200; }
4646 #headertabs.bare .ui-widget-content a.new:visited { color:#A55858; }
4747 #headertabs.bare .ui-widget-content a.extiw { color:#3366BB; }
48 -#headertabs.bare .ui-widget-content a.redirect { color:#308050; } /*Color redirect links*/
49 -#headertabs.bare .ui-widget-content a.redirect:visited { color:#3070A0; } /*Color redirect links*/
 48+#headertabs.bare .ui-widget-content a.redirect { color:#308050; }
 49+#headertabs.bare .ui-widget-content a.redirect:visited { color:#3070A0; }
5050
51 -/* end JQuery UI tabs style clearer */
\ No newline at end of file
 51+/* end JQuery UI tabs style clearer */
Index: trunk/extensions/HeaderTabs/skins-jquery/ext.headertabs.core.js
@@ -1,5 +1,5 @@
22 /**
3 - * Version of the HeaderTabs class that uses jQuery and the ResourceLoader.
 3+ * Javascript code for Header Tabs extension for MW 1.17+
44 *
55 * @file
66 * @ingroup Extensions
@@ -26,16 +26,16 @@
2727 /* follow a # anchor to a tab OR a heading */
2828 var curHash = window.location.hash;
2929 if ( curHash.indexOf( "#tab=" ) == 0 ) {
30 - // remove the fragment identifier, we're using it for the name of the tab in the jquery ui tabs
31 - var tabName = curHash.replace( "#tab=", "" );
32 - $tabs.tabs('select', tabName);
 30+ // remove the fragment identifier, we're using it for the name of the tab in the jquery ui tabs
 31+ var tabName = curHash.replace( "#tab=", "" );
 32+ $tabs.tabs('select', tabName);
3333 } else if (curHash != '') {
3434 /* select tab in a fragment
3535 thanks kboudloche, Alphos
3636 http://forum.jquery.com/topic/jquery-ui-tabs-create-an-anchor-to-content-within-tab#14737000001187015
3737 */
38 - var tabName = $(curHash).closest('.ui-tabs-panel').attr('id');
39 - $tabs.tabs('select', tabNameEscape(tabName));
 38+ var tabName = $(curHash).closest('.ui-tabs-panel').attr('id');
 39+ $tabs.tabs('select', tabNameEscape(tabName));
4040 }
4141
4242 function tabEditTabLink(hash) {
@@ -85,4 +85,4 @@
8686 var href = $(this).attr('href');
8787 $tabs.tabs('select', tabNameEscape(href));
8888 return false;
89 -} );
\ No newline at end of file
 89+} );
Index: trunk/extensions/HeaderTabs/skins-jquery/ext.headertabs.jquery-large.css
@@ -1,5 +1,6 @@
22 /**
3 - * Default jquery styling with normal sized font and blue links.
 3+ * Default jQuery styling, but with normal-sized font and blue (instead of
 4+ * black)links.
45 *
56 * @file
67 * @ingroup Extensions
@@ -8,20 +9,19 @@
910 * @author Olivier Beaton
1011 */
1112
12 -/* JQuery UI tabs clearing styles by Olivier Finlay Beaton and 70.189.238.136 */
1313 #headertabs.jquery-large.ui-widget {
1414 font-family: inherit;
15 - font-size: 1em; /* ie doesn't like inherit here */
 15+ font-size: 1em; /* IE doesn't like inherit here */
1616 }
1717
18 -/* section by 70.189.238.136, for things I forgot, thanks! */
19 -#headertabs.jquery-large .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: inherit; font-size: 1em; } /* ie doesn't like inherit here */
 18+/* section by 70.189.238.136 */
 19+#headertabs.jquery-large .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: inherit; font-size: 1em; } /* IE doesn't like inherit here */
2020 #headertabs.jquery-large .ui-widget-content a { color:#0645AD; }
2121 #headertabs.jquery-large .ui-widget-content a:visited { color:#0b0080; }
2222 #headertabs.jquery-large .ui-widget-content a.new { color:#CC2200; }
2323 #headertabs.jquery-large .ui-widget-content a.new:visited { color:#A55858; }
2424 #headertabs.jquery-large .ui-widget-content a.extiw { color:#3366BB; }
25 -#headertabs.jquery-large .ui-widget-content a.redirect { color:#308050; } /*Color redirect links*/
26 -#headertabs.jquery-large .ui-widget-content a.redirect:visited { color:#3070A0; } /*Color redirect links*/
 25+#headertabs.jquery-large .ui-widget-content a.redirect { color:#308050; }
 26+#headertabs.jquery-large .ui-widget-content a.redirect:visited { color:#3070A0; }
2727
28 -/* end JQuery UI tabs style clearer */
\ No newline at end of file
 28+/* end JQuery UI tabs style clearer */
Index: trunk/extensions/HeaderTabs/HeaderTabs.php
@@ -17,7 +17,7 @@
1818 // the file loaded depends on whether the ResourceLoader exists, which in
1919 // turn depends on what version of MediaWiki this is - for MW 1.17+,
2020 // HeaderTabs_body.jq.php will get loaded
21 -$jquery = is_callable( array( 'OutputPage', 'addModules' ) );
 21+$useJQuery = is_callable( array( 'OutputPage', 'addModules' ) );
2222
2323 $wgExtensionCredits['parserhook'][] = array(
2424 'path' => __FILE__,
@@ -42,9 +42,9 @@
4343 $htEditTabLink = true;
4444
4545 // Extension:Configure
46 -if (isset($wgConfigureAdditionalExtensions) && is_array($wgConfigureAdditionalExtensions)) {
 46+if ( isset( $wgConfigureAdditionalExtensions ) && is_array( $wgConfigureAdditionalExtensions ) ) {
4747
48 - /* (not our var to doc)
 48+ /**
4949 * attempt to tell Extension:Configure how to web configure our extension
5050 * @since 2011-09-22, 0.2
5151 */
@@ -69,13 +69,13 @@
7070
7171 } // $wgConfigureAdditionalExtensions exists
7272
73 -// used by both jquery and yui
 73+// used by both jQuery and YUI
7474 $wgHooks['ParserFirstCallInit'][] = 'headerTabsParserFunctions';
7575 $wgHooks['LanguageGetMagic'][] = 'headerTabsLanguageGetMagic';
7676 $wgHooks['BeforePageDisplay'][] = 'HeaderTabs::addHTMLHeader';
7777 $wgHooks['ParserAfterTidy'][] = 'HeaderTabs::replaceFirstLevelHeaders';
7878
79 -if ($jquery) {
 79+if ( $useJQuery ) {
8080 $wgAutoloadClasses['HeaderTabs'] = "$dir/HeaderTabs_body.jq.php";
8181
8282 $wgHooks['ResourceLoaderGetConfigVars'][] = 'HeaderTabs::addConfigVarsToJS';
@@ -96,9 +96,7 @@
9797 'remoteExtPath' => 'HeaderTabs',
9898 );
9999
100 - //end if jquery
101 -} else {
102 - // we are pre 1.17 and doing yui
 100+} else { // if ! $useJQuery
103101 $wgAutoloadClasses['HeaderTabs'] = "$dir/HeaderTabs_body.yui.php";
104102 }
105103
@@ -116,8 +114,8 @@
117115 //! @todo implement in tab parsing code instead... but problems like nowiki (2011-12-12, ofb)
118116 // if you make them here, it will be article wide instead of tab-wide
119117 // __NOTABTOC__, __TABTOC__, __NOEDITTAB__
120 - // and oneday with a special page: __NEWTABLINK__, __NONEWTABLINK__
121 - // and oneday if we can force toc generation: __FORCETABTOC__
 118+ // and one day with a special page: __NEWTABLINK__, __NONEWTABLINK__
 119+ // and one day if we can force toc generation: __FORCETABTOC__
122120
123121 //! @todo make this load a custom name from i18n file (2011-12-12, ofb)
124122 // ensure to keep this name too for backwards compat
@@ -126,4 +124,4 @@
127125 $magicWords['switchtablink'] = array ( 0, 'switchtablink' );
128126 }
129127 return true;
130 -}
\ No newline at end of file
 128+}
Index: trunk/extensions/HeaderTabs/HeaderTabs_body.jq.php
@@ -22,7 +22,7 @@
2323
2424 //! @todo handle __NOTABTOC__, __TABTOC__, __FORCETABTOC__ here (2011-12-12, ofb)
2525
26 - // where do we stop rendering tabs, and what is bellow it?
 26+ // Where do we stop rendering tabs, and what is below it?
2727 // if we don't have a stop point, then bail out
2828 $aboveandbelow = explode( '<div id="nomoretabs"></div>', $text, 2 );
2929 if ( count( $aboveandbelow ) <= 1 ) {
@@ -38,7 +38,7 @@
3939 wfDebugLog('headertabs', __METHOD__.': detected header handling, checking');
4040
4141 if ($below !== '') {
42 - wfDebugLog('headertabs', __METHOD__.': we have text bellow our tabs');
 42+ wfDebugLog('headertabs', __METHOD__.': we have text below our tabs');
4343 }
4444
4545 // grab the TOC
@@ -182,20 +182,20 @@
183183 $tabtocraw = $tabtocmatches[0];
184184 $tabtoc = $tabtocraw;
185185 $itempattern = '/<li class="toclevel-[0-9]+"><a href="(#[^"]+)"><span class="tocnumber">[0-9]+<\/span> <span class="toctext">([^<]+)<\/span><\/a><\/li>/';
186 - if (preg_match_all ( $itempattern , $tabtocraw, $tabtocitemmatches, PREG_SET_ORDER) > 0 ) {
187 - foreach($tabtocitemmatches as $match) {
 186+ if ( preg_match_all( $itempattern , $tabtocraw, $tabtocitemmatches, PREG_SET_ORDER ) > 0 ) {
 187+ foreach( $tabtocitemmatches as $match ) {
188188 $newitem = $match[0];
189189
190 - // 1.17 behaviour
191 - if (strpos($match[2], '[edit] ') === 0) {
192 - $newitem = str_replace($match[1], '#'.substr($match[1], 12), $newitem);
193 - $newitem = str_replace($match[2], substr($match[2], 7), $newitem);
194 - // 1.18+ behaviour
195 - } elseif (trim(substr($match[2], 0, strlen($match[2])/2)) == trim(substr($match[2], strlen($match[2])/2))) {
196 - $newitem = str_replace($match[1], '#'.trim(substr($match[1], (strlen($match[1])/2)+1)), $newitem);
197 - $newitem = str_replace($match[2], trim(substr($match[2], strlen($match[2])/2)), $newitem);
 190+ // 1.17 behavior
 191+ if ( strpos( $match[2], '[edit] ' ) === 0 ) {
 192+ $newitem = str_replace( $match[1], '#' . substr( $match[1], 12 ), $newitem );
 193+ $newitem = str_replace( $match[2], substr( $match[2], 7 ), $newitem );
 194+ // 1.18+ behavior
 195+ } elseif ( trim( substr( $match[2], 0, strlen( $match[2] ) / 2 ) ) == trim( substr( $match[2], strlen( $match[2] ) / 2 ) ) ) {
 196+ $newitem = str_replace( $match[1], '#' . trim( substr( $match[1], ( strlen( $match[1] ) / 2 ) + 1 ) ), $newitem );
 197+ $newitem = str_replace( $match[2], trim( substr( $match[2], strlen( $match[2] ) / 2 ) ), $newitem );
198198 }
199 - $tabtoc = str_replace($match[0], $newitem, $tabtoc);
 199+ $tabtoc = str_replace( $match[0], $newitem, $tabtoc );
200200 }
201201 $content = $tabtoc.$content;
202202 }
@@ -210,13 +210,11 @@
211211 ) );
212212 }
213213
214 - //! @todo see if we can't add the SMW factorbox stuff back in (2011-12-12, ofb)
 214+ //! @todo see if we can't add the SMW factbox stuff back in (2011-12-12, ofb)
215215
216216 wfDebugLog('headertabs', __METHOD__.': generated '.count($tabs).' tabs');
217217
218 - $tabhtml = '';
219 -
220 - $tabhtml .= '<div id="headertabs"';
 218+ $tabhtml = '<div id="headertabs"';
221219 if (!empty($htStyle) && $htStyle !== 'jquery') {
222220 $tabhtml .= ' class="'.$htStyle.'"';
223221 }
@@ -248,8 +246,6 @@
249247 public static function addConfigVarsToJS( &$vars ) {
250248 global $htUseHistory, $htEditTabLink;
251249
252 - wfDebugLog('headertabs', __METHOD__.': adding globals');
253 -
254250 $vars['htUseHistory'] = $htUseHistory;
255251 $vars['htEditTabLink'] = $htEditTabLink;
256252
@@ -263,16 +259,13 @@
264260 public static function addHTMLHeader( &$out ) {
265261 global $htScriptPath,$htStyle;
266262
267 - wfDebugLog('headertabs', __METHOD__.': loading javascript');
268 -
269263 //! @todo we might be able to only load our js and styles if we are rendering tabs, speeding up pages that don't use it? but what about cached pages? (2011-12-12, ofb)
270264
271265 $out->addModules( 'ext.headertabs' );
272266
273 - // add the stylesheet for our perticular style
274 - if (!empty($htStyle) && $htStyle !== 'jquery') {
275 - $styleFile = $htScriptPath.'/skins-jquery/ext.headertabs.'.$htStyle.'.css';
276 - wfDebugLog('headertabs', __METHOD__.': including style file: '.$styleFile);
 267+ // Add the CSS file for the specified style.
 268+ if ( !empty( $htStyle ) && $htStyle !== 'jquery' ) {
 269+ $styleFile = $htScriptPath . '/skins-jquery/ext.headertabs.' . $htStyle . '.css';
277270 $out->addExtensionStyle( $styleFile );
278271 }
279272

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106028* added Extension:Configure support...finlay15:38, 13 December 2011
r106032Seriously, don't use "wgOut" as a function parameter namereedy15:47, 13 December 2011

Status & tagging log