--- a/mediawiki/skins/cmo.php
+++ b/mediawiki/skins/cmo.php
@@ -57,17 +57,17 @@ class CMOTemplate extends QuickTemplate
*
* @access private
*/
function execute() {
global $wgRequest;
$this->skin = $skin = $this->data['skin'];
$this->action = $wgRequest->getText( 'action' );
$this->stylepath = $this->data['stylepath'].'/'.$this->data['stylename'];
-
+
// Suppress warnings to prevent notices about missing indexes in $this->data
wfSuppressWarnings();
$this->drawpage();
wfRestoreWarnings();
} // end of execute() method
/*************************************************************************************************/
@@ -193,35 +193,39 @@ class CMOTemplate extends QuickTemplate
foreach($arr as $v) {
print('<a href="'.$v[0].'">'.$v[1].'</a> / ');
}
print('</p>');
}
/*************************************************************************************************/
function title_crumbs($title) {
- $elems = explode(':',$this->data['thispage']);
+ $elems = explode('/',$this->data['titletext']);
$elems2 = Array();
$url = Array();
foreach($elems as $v) {
$url[] = str_replace(' ','_',$v);
- $elems2[] = Array(str_replace('$1',implode(':',$url),$this->data['articlepath']), $v);
+ $elems2[] = Array(str_replace('$1',implode('/',$url),$this->data['articlepath']), $v);
}
$title = array_pop($elems); // take last element as title
array_pop($elems2); // and remove the last element from crumbs
return Array($elems2, $title);
}
/*************************************************************************************************/
function body() {
- $menu = false;
$ar = $this->title_crumbs($this->data['title']);
$title = $ar[1];
$crumbs = $ar[0];
$this->crumbs($crumbs);
+ $mix = $this->extractTOC($this->data['bodytext']);
+ $body = $mix[0];
+ $toc = $mix[1];
+ $menu = $toc?True:False;
+
if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php }
?>
<ul id="ptools">
<?php foreach($this->data['personal_urls'] as $key => $item) {
if (in_array($key, Array('anontalk','anonuserpage','userpage','mytalk','preferences','watchlist','mycontris')))
continue;
?>
<li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
@@ -265,26 +269,26 @@ class CMOTemplate extends QuickTemplate
<h1 id="page-title"><?php print($title);?></h1>
<div id="main"<?php if($menu)print(' class="with-menu"');?>><div id="main-content">
<h3 id="siteSub"><?php $this->msg('tagline') ?></h3>
<div id="contentSub"><?php $this->html('subtitle') ?></div>
<?php if($this->data['undelete']) { ?><div id="contentSub2"><?php $this->html('undelete') ?></div><?php } ?>
<?php if($this->data['newtalk'] ) { ?><div class="usermessage"><?php $this->html('newtalk') ?></div><?php } ?>
<?php if($this->data['showjumplinks']) { ?><div id="jump-to-nav"><?php $this->msg('jumpto') ?> <a href="#column-one"><?php $this->msg('jumptonavigation') ?></a>, <a href="#searchInput"><?php $this->msg('jumptosearch') ?></a></div><?php } ?>
<!-- start content -->
- <?php $this->html('bodytext') ?>
+ <?php print $body ?>
<?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
<!-- end content -->
<?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?>
<div class="visualClear"></div>
</div>
<?php
if($menu)
- $this->menu();
+ $this->toc($toc);
}
/*************************************************************************************************/
function footer() {
?>
</div><!-- end #main -->
<div id="footer-wrap">
<div id="footer" class="cols">
@@ -358,17 +362,32 @@ class CMOTemplate extends QuickTemplate
</div>
</div><!-- end #footer -->
</div><!-- end #footer-wrap -->
<?php
}
/*************************************************************************************************/
- function menu() {
+ function toc($toc) {
+?>
+<div id="localnav">
+ <ul class="first">
+ <li class="first"><a href="">Content</a>
+ <ul>
+ <?php print($this->hackTOC($toc)) ?>
+ </ul>
+ </li>
+ </ul>
+</div>
+<?php
+ }
+
+ /*************************************************************************************************/
+ function menu($toc) {
?>
<div id="localnav">
<ul class="first">
<li class="first"><a href="/community/">Community</a>
<ul>
<li class="first"><a href="/community/blogs.html">Blogs and Feeds</a></li>
<li><a href="/community/chat.html">Chat Servers</a></li>
@@ -382,11 +401,32 @@ class CMOTemplate extends QuickTemplate
<li><a href="/community/wikis.html">Wikis</a></li>
</ul>
</li>
</ul>
</div>
<?php
}
+ function extractTOC(&$body) {
+ $toc = '';
+ $toc_pattern = '/<table id="toc".*?<\/table>/sim';
+ $elems = preg_split($toc_pattern, $body,-1, PREG_SPLIT_OFFSET_CAPTURE);
+ if (count($elems)<2)
+ return Array($body, $toc);
+
+ $toc = substr($body,strlen($elems[0][0]), $elems[1][1]-strlen($elems[0][0]));
+ $body = substr($body,0, strlen($elems[0][0])) . substr($body, $elems[1][1]);
+ return Array($body, $toc);
+ }
+
+ function hackTOC(&$toc) {
+ $pattern = '/<table id="toc".*?<\/h2><\/div>\s+<ul>/sim';
+ $toc = preg_replace($pattern, '', $toc);
+ #<li class="toclevel-1"><a href="#Overview"><span class="tocnumber">1</span> <span class="toctext">Overview</span></a></li>
+ $pattern = '/<li class="toclevel-[0-9]">/sim';
+ $toc = preg_replace($pattern, '<li>', $toc);
+ return $toc;
+ }
+
} // end of class