http://www.mediawiki.org/wiki/Special:Code/MediaWiki/56286
Revision: 56286
Author: sergeychernyshev
Date: 2009-09-14 01:51:47 +0000 (Mon, 14 Sep 2009)
Log Message:
-----------
Migrating from original hosting on Google Code.
Release v0.6.6 - Fixed compatibility issues with MW 1.16
Added Paths:
-----------
trunk/extensions/HeaderTabs/
trunk/extensions/HeaderTabs/HeaderTabs.php
trunk/extensions/HeaderTabs/LICENSE
trunk/extensions/HeaderTabs/skins/
trunk/extensions/HeaderTabs/skins/blank.html
trunk/extensions/HeaderTabs/skins/headertabs.css
trunk/extensions/HeaderTabs/skins/headertabs.js
trunk/extensions/HeaderTabs/skins/headertabs_hide_factbox.css
Added: trunk/extensions/HeaderTabs/HeaderTabs.php
===================================================================
--- trunk/extensions/HeaderTabs/HeaderTabs.php (rev 0)
+++ trunk/extensions/HeaderTabs/HeaderTabs.php 2009-09-14 01:51:47 UTC (rev
56286)
@@ -0,0 +1,223 @@
+<?php
+$htScriptPath = $wgScriptPath . '/extensions/HeaderTabs';
+
+$wgExtensionFunctions[] = 'htSetupExtension';
+$wgExtensionCredits['parserhook'][] = array(
+ 'name' => 'Header Tabs',
+ 'description' => 'Adds tabs to the page separating top-level sections.
Originally developed for [http://www.ardorado.com Ardorado.com]',
+ 'version' => '0.6.6',
+ 'author' => '[http://www.sergeychernyshev.com Sergey Chernyshev] (for
[http://www.semanticcommunities.com Semantic Communities LLC.])',
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Header_Tabs'
+);
+
+$htYUIBase = 'http://yui.yahooapis.com/2.5.1/build/';
+$htUseHistory = true;
+
+function htSetupExtension()
+{
+ global $wgHooks;
+ global $wgParser;
+
+ $wgHooks['BeforePageDisplay'][] = 'htAddHTMLHeader';
+ $wgHooks['ParserAfterTidy'][] = 'htReplaceFirstLevelHeaders';
+ $wgParser->setHook('headertabs', 'htTag' );
+
+ return true;
+}
+
+function htTag( $input, $args, $parser ) {
+ global $wgOut, $htScriptPath;
+
+ $wgOut->addLink(array(
+ 'rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'media' => 'screen, projection',
+ 'href' => $htScriptPath.'/skins/headertabs_hide_factbox.css'
+ ));
+
+ // this tag besides just enabling tabs, also designates end of tabs
+ // TOC doesn't make sense where tabs are used
+ return '<div id="nomoretabs"></div>';
+}
+
+function htReplaceFirstLevelHeaders(&$parser, &$text)
+{
+ global $htUseHistory, $htScriptPath, $wgVersion;
+
+ $aboveandbelow = explode('<div id="nomoretabs"></div>', $text, 2);
+
+ if (count($aboveandbelow) <= 1)
+ {
+ return true; // <headertabs/> tag is not found
+ }
+ $below = $aboveandbelow[1];
+
+ $aboveandtext = preg_split('/(<a
name=".*?"><\/a>)?<h1.*?class="mw-headline".*?<\/h1>/', $aboveandbelow[0], 2);
+ if (count($aboveandtext) > 1)
+ {
+ $above = $aboveandtext[0];
+
+ $tabs = array();
+
+ $v = explode('.', $wgVersion);
+ if ($v[0] > 1 || ($v[0] == 1 && $v[1] >= 16))
+ {
+ $parts =
preg_split('/(<h1.*?class="mw-headline".*?<\/h1>)/', $aboveandbelow[0], -1,
PREG_SPLIT_DELIM_CAPTURE);
+ array_shift($parts); // don't need above part anyway
+
+ for ( $i = 0; $i<(count($parts)/2); $i++)
+ {
+ preg_match('/id="(.*?)"/', $parts[$i*2],
$matches);
+ $tabid = $matches[1];
+
+
preg_match('/<span.*?class="mw-headline".*?>\s*(.*?)\s*<\/h1>/', $parts[$i*2],
$matches);
+ $tabtitle = $matches[1];
+
+ array_push($tabs, array(
+ 'tabid' => $tabid,
+ 'title' => $tabtitle,
+ 'tabcontent' => $parts[$i*2+1]
+ ));
+ }
+ }
+ else
+ {
+ $parts = preg_split('/<a name="(.*?)"><\/a><h1>.*?<span
class="mw-headline">\s*(.*?)\s*<\/span><\/h1>/', $aboveandbelow[0], -1,
PREG_SPLIT_DELIM_CAPTURE);
+ array_shift($parts); // don't need above part anyway
+
+ for ( $i = 0; $i<(count($parts)/3); $i++)
+ {
+ array_push($tabs, array(
+ 'tabid' => $parts[$i*3],
+ 'title' => $parts[$i*3+1],
+ 'tabcontent' => $parts[$i*3+2]
+ ));
+ }
+ }
+
+ $tabhtml = '<div id="headertabs" class="yui-navset">';
+
+ $tabhtml .= '<ul class="yui-nav">';
+ $firsttab = true;
+ foreach ($tabs as $tab)
+ {
+ $tabhtml .= '<li';
+ if ($firsttab)
+ {
+ $tabhtml .= ' class="selected"';
+ $firsttab = false;
+ }
+ $tabhtml .= '><a id="headertab_'.$tab['tabid'].'"
tabid="#'.$tab['tabid'].'"><em>'.$tab['title']."</em></a></li>\n";
+ }
+ $tabhtml .= '</ul>';
+
+ $tabhtml .= '<div class="yui-content">';
+ $firsttab = true;
+ foreach ($tabs as $tab)
+ {
+ if ($firsttab)
+ {
+ $style = '';
+ $firsttab = false;
+ }
+ else
+ {
+ $style = ' style="display:none"';
+ }
+ $tabhtml .= '<div
id="'.$tab['tabid'].'"'.$style.'><p>'.$tab['tabcontent'].'</p></div>';
+ }
+ $tabhtml .= '</div></div>';
+
+ if ($htUseHistory)
+ {
+ $text = '<iframe id="yui-history-iframe"
src="'.$htScriptPath.'/skins/blank.html" style="position:absolute; top:0;
left:0; width:1px; height:1px; visibility:hidden;"></iframe><input
id="yui-history-field" type="hidden">';
+ }
+ else
+ {
+ $text = '';
+ }
+ $text .= '<script>HeaderTabs.init('.($htUseHistory ? 'true' :
'false').');</script>';
+ $text .= $above.$tabhtml.$below;
+ }
+
+ return true;
+}
+
+function htAddHTMLHeader(&$wgOut)
+{
+ global $htScriptPath, $htYUIBase, $htUseHistory;
+
+ $wgOut->addScript('<script type="text/javascript"
src="'.$htYUIBase.'utilities/utilities.js"></script>');
+ $wgOut->addScript('<script type="text/javascript"
src="'.$htYUIBase.'tabview/tabview-min.js"></script>');
+ $wgOut->addScript('<script type="text/javascript"
src="'.$htYUIBase.'event/event-min.js"></script>');
+
+ if ($htUseHistory)
+ {
+ // TODO Rewrite it using latest History package so we can
update $htYUIBase to latest version
+ $wgOut->addScript('<script type="text/javascript"
src="'.$htYUIBase.'history/history-min.js"></script>');
+ }
+
+ $wgOut->addLink(array(
+ 'rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'media' => 'screen, projection',
+ 'href' => $htYUIBase.'fonts/fonts-min.css'
+ ));
+
+ $wgOut->addScript('<script type="text/javascript"
src="'.$htScriptPath.'/skins/headertabs.js"></script>');
+
+ $wgOut->addLink(array(
+ 'rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'media' => 'screen, projection',
+ 'href' => $htYUIBase.'tabview/assets/skins/sam/tabview.css'
+ ));
+
+ $wgOut->addLink(array(
+ 'rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'media' => 'screen, projection',
+ 'href' => $htScriptPath.'/skins/headertabs.css'
+ ));
+
+ return true;
+}
+
+# Parser function to insert a link changing a tab:
+$wgExtensionFunctions[] = 'headerTabsParserFunctions';
+$wgHooks['LanguageGetMagic'][] = 'headerTabsLanguageGetMagic';
+
+function headerTabsParserFunctions()
+{
+ global $wgParser;
+ $wgParser->setFunctionHook('switchtablink', 'renderSwitchTabLink');
+}
+
+function headerTabsLanguageGetMagic( &$magicWords, $langCode = "en" )
+{
+ switch ( $langCode ) {
+ default:
+ $magicWords['switchtablink'] = array ( 0, 'switchtablink' );
+ }
+ return true;
+}
+
+function renderSwitchTabLink(&$parser, $tabName, $linkText, $anotherTarget =
'')
+{
+ $tabTitle = Title::newFromText($tabName);
+ $tabKey = $tabTitle->getDBkey();
+
+ if ($anotherTarget != '')
+ {
+ $targetTitle = Title::newFromText($anotherTarget);
+ $targetURL = $targetTitle->getFullURL();
+
+ $output = '<a
href="'.$targetURL.'#tab='.$tabKey.'">'.$linkText.'</a>';
+ }
+ else
+ {
+ $output = '<a href="#tab='.$tabKey.'" onclick="return
HeaderTabs.switchTab(\''.$tabKey.'\')">'.$linkText.'</a>';
+ }
+
+ return $parser->insertStripItem( $output, $parser->mStripState );
+}
Property changes on: trunk/extensions/HeaderTabs/HeaderTabs.php
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/extensions/HeaderTabs/LICENSE
===================================================================
--- trunk/extensions/HeaderTabs/LICENSE (rev 0)
+++ trunk/extensions/HeaderTabs/LICENSE 2009-09-14 01:51:47 UTC (rev 56286)
@@ -0,0 +1,25 @@
+Copyright (c) 2008 Sergey Chernyshev
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
Property changes on: trunk/extensions/HeaderTabs/skins/blank.html
___________________________________________________________________
Added: svn:keywords
+ Id Rev
Added: trunk/extensions/HeaderTabs/skins/headertabs.css
===================================================================
--- trunk/extensions/HeaderTabs/skins/headertabs.css
(rev 0)
+++ trunk/extensions/HeaderTabs/skins/headertabs.css 2009-09-14 01:51:47 UTC
(rev 56286)
@@ -0,0 +1,180 @@
+.yui-skin-sam .yui-navset .yui-content {
+ background: transparent; /* content background color */
+}
+
+/*
+ All the definitions below are intended to replicate the look of the "Sam"
+ skin, for sites that don't have a yui-skin-sam class declaration anywhere.
+*/
+
+.yui-navset .yui-content {
+ background: transparent; /* content background color */
+}
+
+.yui-navset .yui-nav, .yui-navset .yui-navset-top .yui-nav {
+ border-color:#2647A0;
+ border-style:solid;
+ border-width:0pt 0pt 5px;
+}
+
+.yui-navset .yui-nav li, .yui-skin-sam .yui-navset .yui-navset-top .yui-nav li
{
+ margin:0pt 0.16em 0pt 0pt;
+ padding:1px 0pt 0pt;
+}
+.yui-navset .yui-nav .selected, .yui-skin-sam .yui-navset .yui-navset-top
.yui-nav .selected {
+ margin:0pt 0.16em -1px 0pt;
+}
+
+.yui-navset .yui-nav a, .yui-navset .yui-navset-top .yui-nav a {
+ background:#D8D8D8;
+ border-color:#A3A3A3;
+ border-style:solid;
+ border-width:0pt 1px;
+ color:#000000;
+ position:relative;
+ text-decoration:none;
+}
+
+.yui-navset .yui-nav a em, .yui-navset .yui-navset-top .yui-nav a em {
+ border-color:#A3A3A3;
+ border-style:solid;
+ border-width:1px 0pt 0pt;
+ bottom:0pt;
+ left:0pt;
+ padding:0.25em 0.75em;
+ position:relative;
+ right:0pt;
+ top:-1px;
+}
+
+.yui-navset .yui-nav .selected a, .yui-navset .yui-nav .selected a:focus,
.yui-navset .yui-nav .selected a:hover {
+ background:#2647A0;
+ color:#FFFFFF;
+}
+
+.yui-navset .yui-nav a:hover, .yui-navset .yui-nav a:focus {
+ background:#BFDAFF;
+ outline-color:invert;
+ outline-style:none;
+ outline-width:0pt;
+}
+
+.yui-navset .yui-nav .selected a em {
+ padding:0.35em 0.75em;
+}
+
+.yui-navset .yui-nav .selected a, .yui-navset .yui-nav .selected a em {
+ border-color:#243356;
+}
+
+.yui-navset .yui-nav .selected a em {
+ padding:0.35em 0.75em;
+}
+
+.yui-navset .yui-content, .yui-navset .yui-navset-top .yui-content {
+ border-color:#243356 rgb(128, 128, 128) rgb(128, 128, 128);
+ border-style:solid;
+ border-width:1px;
+ padding:0.25em 0.5em;
+}
+.yui-navset-left .yui-nav, .yui-navset .yui-navset-left .yui-nav, .yui-navset
.yui-navset-right .yui-nav, .yui-navset-right .yui-nav {
+ border-width:0pt 5px 0pt 0pt;
+ bottom:0pt;
+ top:0pt;
+}
+.yui-navset .yui-navset-right .yui-nav, .yui-navset-right .yui-nav {
+ border-width:0pt 0pt 0pt 5px;
+}
+.yui-navset-left .yui-nav li, .yui-navset .yui-navset-left .yui-nav li,
.yui-navset-right .yui-nav li {
+ margin:0pt 0pt 0.16em;
+ padding:0pt 0pt 0pt 1px;
+}
+.yui-navset-right .yui-nav li {
+ padding:0pt 1px 0pt 0pt;
+}
+.yui-navset-left .yui-nav .selected, .yui-navset .yui-navset-left .yui-nav
.selected {
+ margin:0pt -1px 0.16em 0pt;
+}
+.yui-navset-right .yui-nav .selected {
+ margin:0pt 0pt 0.16em -1px;
+}
+.yui-navset-left .yui-nav a, .yui-navset-right .yui-nav a {
+ border-width:1px 0pt;
+}
+.yui-navset-left .yui-nav a em, .yui-navset .yui-navset-left .yui-nav a em,
.yui-navset-right .yui-nav a em {
+ border-width:0pt 0pt 0pt 1px;
+ left:-1px;
+ padding:0.2em 0.75em;
+ top:auto;
+}
+.yui-navset-right .yui-nav a em {
+ border-width:0pt 1px 0pt 0pt;
+ left:auto;
+ right:-1px;
+}
+.yui-navset-left .yui-nav a, .yui-navset-left .yui-nav .selected a,
.yui-navset-left .yui-nav a:hover, .yui-navset-right .yui-nav a,
.yui-navset-right .yui-nav .selected a, .yui-navset-right .yui-nav a:hover,
.yui-navset-bottom .yui-nav a, .yui-navset-bottom .yui-nav .selected a,
.yui-navset-bottom .yui-nav a:hover {
+ background-image:none;
+}
+.yui-navset-left .yui-content {
+ border-color:#808080 rgb(128, 128, 128) rgb(128, 128, 128) rgb(36, 51,
86);
+ border-style:solid;
+ border-width:1px;
+}
+.yui-navset-bottom .yui-nav, .yui-navset .yui-navset-bottom .yui-nav {
+ border-width:5px 0pt 0pt;
+}
+.yui-navset .yui-navset-bottom .yui-nav .selected, .yui-navset-bottom .yui-nav
.selected {
+ margin:-1px 0.16em 0pt 0pt;
+}
+.yui-navset .yui-navset-bottom .yui-nav li, .yui-navset-bottom .yui-nav li {
+ padding:0pt 0pt 1px;
+ vertical-align:top;
+}
+.yui-navset .yui-navset-bottom .yui-nav li a, .yui-navset-bottom .yui-nav li a
{
+}
+.yui-navset .yui-navset-bottom .yui-nav a em, .yui-navset-bottom .yui-nav a em
{
+ border-width:0pt 0pt 1px;
+ bottom:-1px;
+ top:auto;
+}
+.yui-navset-bottom .yui-content, .yui-navset .yui-navset-bottom .yui-content {
+ border-color:#808080 rgb(128, 128, 128) rgb(36, 51, 86);
+ border-style:solid;
+ border-width:1px;
+}
+
+.yui-navset .yui-nav a em, .yui-navset .yui-navset-top .yui-nav a em {
+ border-color:#A3A3A3;
+ border-style:solid;
+ border-width:1px 0pt 0pt;
+ bottom:0pt;
+ left:0pt;
+ padding:0.25em 0.75em;
+ position:relative;
+ right:0pt;
+ top:-1px;
+}
+.yui-navset .yui-nav li a em, .yui-navset-top .yui-nav li a em,
.yui-navset-bottom .yui-nav li a em {
+ display:block;
+}
+
+.yui-navset .yui-nav a em, .yui-navset .yui-navset-top .yui-nav a em {
+ border-color:#A3A3A3;
+ border-style:solid;
+ border-width:1px 0pt 0pt;
+ bottom:0pt;
+ left:0pt;
+ padding:0.25em 0.75em;
+ position:relative;
+ right:0pt;
+ top:-1px;
+}
+
+.yui-navset .yui-nav li a em, .yui-navset-top .yui-nav li a em,
.yui-navset-bottom .yui-nav li a em {
+ display:block;
+}
+
+.yui-navset .yui-nav a, .yui-navset .yui-navset-top .yui-nav a {
+ color:#000000;
+ text-decoration:none;
+}
Property changes on: trunk/extensions/HeaderTabs/skins/headertabs.css
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/extensions/HeaderTabs/skins/headertabs.js
===================================================================
--- trunk/extensions/HeaderTabs/skins/headertabs.js
(rev 0)
+++ trunk/extensions/HeaderTabs/skins/headertabs.js 2009-09-14 01:51:47 UTC
(rev 56286)
@@ -0,0 +1,119 @@
+// Tabs code
+if (typeof HeaderTabs == "undefined") {
+ var HeaderTabs = { };
+}
+
+HeaderTabs.tabView = null;
+HeaderTabs.tabids = [];
+HeaderTabs.init = function(useHistory) {
+
+ if (useHistory)
+ {
+ var bookmarkedtab =
YAHOO.util.History.getBookmarkedState('tab') || '--no-tab--';
+
+ YAHOO.util.History.register('tab', bookmarkedtab,
function(tabid)
+ {
+ for (var i = 0; i<HeaderTabs.tabids.length; i++)
+ {
+ if (HeaderTabs.tabids[i] == tabid)
+ {
+ HeaderTabs.tabView.set('activeIndex',
i);
+ return;
+ }
+ }
+ });
+
+ try {
+ YAHOO.util.History.initialize("yui-history-field",
"yui-history-iframe");
+ }
+ catch (e)
+ {
+ useHistory = false;
+ }
+ }
+
+ if (useHistory)
+ {
+ YAHOO.util.History.onReady(function()
+ {
+ var tabid = YAHOO.util.History.getCurrentState("tab");
+ for (var i = 0; i<HeaderTabs.tabids.length; i++)
+ {
+ if (HeaderTabs.tabids[i] == tabid)
+ {
+ HeaderTabs.tabView.set('activeIndex',
i);
+ return;
+ }
+ }
+ });
+ }
+
+ YAHOO.util.Event.onContentReady('headertabs', function()
+ {
+ HeaderTabs.tabView = new YAHOO.widget.TabView('headertabs');
+
+ var tabs = new
YAHOO.util.Element('headertabs').getElementsByClassName('yui-content')[0].childNodes;
+
+ YAHOO.util.Dom.batch(tabs, function(tab) {
+ HeaderTabs.tabids.push(tab.id);
+ });
+
+ HeaderTabs.tabView.set('activeIndex', 0);
+
+ if (useHistory)
+ {
+ HeaderTabs.tabView.addListener('activeTabChange',
function(e)
+ {
+ if (e.prevValue != e.newValue)
+ {
+ YAHOO.util.History.navigate('tab',
HeaderTabs.tabids[HeaderTabs.tabView.get('activeIndex')]);
+ }
+ });
+ }
+ });
+
+ YAHOO.util.Event.onContentReady('bodyContent', function()
+ {
+ // don't try adding tabs if there is no tabview
+ if (typeof HeaderTabs.tabView == "undefined")
+ {
+ return;
+ }
+
+ // Adding Factbox tab
+ var factboxdiv = new
YAHOO.util.Element('bodyContent').getElementsByClassName('smwfact')[0];
+ if (factboxdiv)
+ {
+ HeaderTabs.tabView.addTab(new YAHOO.widget.Tab({
+ label: 'Factbox',
+ id: 'headertabs_Factbox_tab',
+ contentEl: factboxdiv
+ }));
+
+ HeaderTabs.tabids.push('Factbox');
+
+
document.getElementById('headertabs_Factbox_tab').getElementsByTagName('a')[0].id
= 'headertab_Factbox';
+ }
+ });
+};
+
+HeaderTabs.switchTab = function(tabid) {
+ if (typeof HeaderTabs.tabView == "undefined")
+ {
+ return false;
+ }
+
+ for (var i = 0; i<HeaderTabs.tabids.length; i++)
+ {
+ if (HeaderTabs.tabids[i] == tabid)
+ {
+ HeaderTabs.tabView.set('activeIndex', i);
+
+ document.getElementById('headertab_'+tabid).focus();
+
+ return false;
+ }
+ }
+
+ return false;
+}
Property changes on: trunk/extensions/HeaderTabs/skins/headertabs.js
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/extensions/HeaderTabs/skins/headertabs_hide_factbox.css
===================================================================
--- trunk/extensions/HeaderTabs/skins/headertabs_hide_factbox.css
(rev 0)
+++ trunk/extensions/HeaderTabs/skins/headertabs_hide_factbox.css
2009-09-14 01:51:47 UTC (rev 56286)
@@ -0,0 +1,3 @@
+.smwfact {
+ display: none;
+}
Property changes on:
trunk/extensions/HeaderTabs/skins/headertabs_hide_factbox.css
___________________________________________________________________
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs