Yaron Koren has uploaded a new change for review.
https://gerrit.wikimedia.org/r/231410
Change subject: Moved some functions into new file, HeaderTabs.hooks.php
......................................................................
Moved some functions into new file, HeaderTabs.hooks.php
Change-Id: If132889628badebb226cdcacdb2b142ae906fca1
---
A HeaderTabs.hooks.php
M HeaderTabs.php
M HeaderTabs_body.php
3 files changed, 91 insertions(+), 62 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/HeaderTabs
refs/changes/10/231410/1
diff --git a/HeaderTabs.hooks.php b/HeaderTabs.hooks.php
new file mode 100644
index 0000000..7ee6f71
--- /dev/null
+++ b/HeaderTabs.hooks.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * File for the HeaderTabs class.
+ *
+ * @file
+ * @ingroup Extensions
+ *
+ * @author Sergey Chernyshev
+ * @author Yaron Koren
+ * @author Olivier Finlay Beaton
+ */
+
+class HeaderTabsHooks {
+
+ public static function registerParserFunctions( $parser ) {
+ $parser->setHook( 'headertabs', array( 'HeaderTabs', 'tag' ) );
+ $parser->setFunctionHook( 'switchtablink', array( 'HeaderTabs',
'renderSwitchTabLink' ) );
+ return true;
+ }
+
+ /**
+ * A wrapper around HeaderTabs::replaceFirstLevelHeaders(), which does
+ * most of the actual work.
+ * This function mostly just determines if there are any header tabs
+ * on the cuurrent page, and exits if not.
+ */
+ public static function replaceFirstLevelHeaders( &$parser, &$text ) {
+ global $htAutomaticNamespaces;
+
+ // Remove spans added if "auto-number headings" is enabled.
+ $simplifiedText = preg_replace( '/\<span
class="mw-headline-number"\>\d*\<\/span\>/', '', $text );
+
+ // Where do we stop rendering tabs, and what is below it?
+ // if we don't have a stop point, then bail out
+ $aboveandbelow = explode( '<div id="nomoretabs"></div>',
$simplifiedText, 2 );
+ if ( count( $aboveandbelow ) <= 1 ) {
+ if ( in_array( $parser->getTitle()->getNamespace(),
$htAutomaticNamespaces ) ) {
+ // We'll act as if the end of article is
+ // nomoretabs.
+ $aboveandbelow[] = '';
+ } else {
+ return true; // <headertabs/> tag is not found
+ }
+ }
+
+ return HeaderTabs::replaceFirstLevelHeaders( $parser, $text,
$aboveandbelow );
+ }
+
+ public static function addConfigVarsToJS( &$vars ) {
+ global $htUseHistory, $htEditTabLink;
+
+ $vars['htUseHistory'] = $htUseHistory;
+ $vars['htEditTabLink'] = $htEditTabLink;
+
+ return true;
+ }
+
+ /**
+ * @param $out OutputPage
+ * @return bool
+ */
+ public static function addHTMLHeader( &$out ) {
+ global $htScriptPath, $htStyle;
+
+ //! @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)
+
+ $out->addModules( 'ext.headertabs' );
+
+ // Add the CSS file for the specified style.
+ if ( !empty( $htStyle ) && $htStyle !== 'jquery' ) {
+ $styleFile = $htScriptPath . '/skins/ext.headertabs.' .
$htStyle . '.css';
+ $out->addExtensionStyle( $styleFile );
+ }
+
+ return true;
+ }
+
+ static function setGlobalJSVariables( &$vars ) {
+ global $htTabIndexes;
+ $vars['htTabIndexes'] = $htTabIndexes;
+ return true;
+ }
+}
diff --git a/HeaderTabs.php b/HeaderTabs.php
index c03289d..47d7e89 100644
--- a/HeaderTabs.php
+++ b/HeaderTabs.php
@@ -75,12 +75,13 @@
} // $wgConfigureAdditionalExtensions exists
-$wgHooks['ParserFirstCallInit'][] = 'headerTabsParserFunctions';
-$wgHooks['BeforePageDisplay'][] = 'HeaderTabs::addHTMLHeader';
-$wgHooks['ParserAfterTidy'][] = 'HeaderTabs::replaceFirstLevelHeaders';
-$wgHooks['ResourceLoaderGetConfigVars'][] = 'HeaderTabs::addConfigVarsToJS';
-$wgHooks['MakeGlobalVariablesScript'][] = 'HeaderTabs::setGlobalJSVariables';
+$wgHooks['ParserFirstCallInit'][] = 'HeaderTabsHooks::registerParserFunctions';
+$wgHooks['BeforePageDisplay'][] = 'HeaderTabsHooks::addHTMLHeader';
+$wgHooks['ParserAfterTidy'][] = 'HeaderTabsHooks::replaceFirstLevelHeaders';
+$wgHooks['ResourceLoaderGetConfigVars'][] =
'HeaderTabsHooks::addConfigVarsToJS';
+$wgHooks['MakeGlobalVariablesScript'][] =
'HeaderTabsHooks::setGlobalJSVariables';
+$wgAutoloadClasses['HeaderTabsHooks'] = "$dir/HeaderTabs.hooks.php";
$wgAutoloadClasses['HeaderTabs'] = "$dir/HeaderTabs_body.php";
$wgResourceModules['ext.headertabs'] = array(
@@ -98,10 +99,3 @@
'localBasePath' => dirname( __FILE__ ),
'remoteExtPath' => 'HeaderTabs',
);
-
-# Parser function to insert a link changing a tab.
-function headerTabsParserFunctions( $parser ) {
- $parser->setHook( 'headertabs', array( 'HeaderTabs', 'tag' ) );
- $parser->setFunctionHook( 'switchtablink', array( 'HeaderTabs',
'renderSwitchTabLink' ) );
- return true;
-}
diff --git a/HeaderTabs_body.php b/HeaderTabs_body.php
index 19deece..dde7e8e 100644
--- a/HeaderTabs_body.php
+++ b/HeaderTabs_body.php
@@ -17,27 +17,13 @@
return '<div id="nomoretabs"></div>';
}
- public static function replaceFirstLevelHeaders( &$parser, &$text ) {
+ public static function replaceFirstLevelHeaders( &$parser, &$text,
$aboveandbelow ) {
global $wgVersion;
- global $htRenderSingleTab, $htAutomaticNamespaces,
$htDefaultFirstTab, $htDisableDefaultToc, $htGenerateTabTocs, $htStyle,
$htEditTabLink;
+ global $htRenderSingleTab, $htDefaultFirstTab,
$htDisableDefaultToc, $htGenerateTabTocs, $htStyle, $htEditTabLink;
global $htTabIndexes;
//! @todo handle __NOTABTOC__, __TABTOC__, __FORCETABTOC__ here
(2011-12-12, ofb)
- // Remove spans added if "auto-number headings" is enabled.
- $simplifiedText = preg_replace( '/\<span
class="mw-headline-number"\>\d*\<\/span\>/', '', $text );
-
- // Where do we stop rendering tabs, and what is below it?
- // if we don't have a stop point, then bail out
- $aboveandbelow = explode( '<div id="nomoretabs"></div>',
$simplifiedText, 2 );
- if ( count( $aboveandbelow ) <= 1 ) {
- if ( in_array( $parser->getTitle()->getNamespace(),
$htAutomaticNamespaces ) === FALSE ) {
- return true; // <headertabs/> tag is not found
- } else {
- // assume end of article is nomoretabs
- $aboveandbelow[] = '';
- }
- }
$below = $aboveandbelow[1];
wfDebugLog('headertabs', __METHOD__.': detected header
handling, checking');
@@ -279,35 +265,6 @@
return true;
}
- public static function addConfigVarsToJS( &$vars ) {
- global $htUseHistory, $htEditTabLink;
-
- $vars['htUseHistory'] = $htUseHistory;
- $vars['htEditTabLink'] = $htEditTabLink;
-
- return true;
- }
-
- /**
- * @param $out OutputPage
- * @return bool
- */
- public static function addHTMLHeader( &$out ) {
- global $htScriptPath, $htStyle;
-
- //! @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)
-
- $out->addModules( 'ext.headertabs' );
-
- // Add the CSS file for the specified style.
- if ( !empty( $htStyle ) && $htStyle !== 'jquery' ) {
- $styleFile = $htScriptPath . '/skins/ext.headertabs.' .
$htStyle . '.css';
- $out->addExtensionStyle( $styleFile );
- }
-
- return true;
- }
-
public static function renderSwitchTabLink( &$parser, $tabName,
$linkText, $anotherTarget = '' ) {
// The cache unfortunately needs to be disabled for the
// JavaScript for such links to work.
@@ -329,9 +286,4 @@
return $parser->insertStripItem( $output, $parser->mStripState
);
}
- static function setGlobalJSVariables( &$vars ) {
- global $htTabIndexes;
- $vars['htTabIndexes'] = $htTabIndexes;
- return true;
- }
}
--
To view, visit https://gerrit.wikimedia.org/r/231410
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If132889628badebb226cdcacdb2b142ae906fca1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/HeaderTabs
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits