Wiki source for PageHeadings

Show raw source

The code below is for an action called ""{{headings}}"". It uses the css modification for the floating boxes suggested by DotMG (see bottom of this page). Use is "">>{{headings}}>>"" where it'll provide a list of headings on the page on the right hand side of the page. The exception to this is that any heading (such as a page title) with 6 "=" signs will not be on the list. Original code (before considerable modification) was from a suggestion at wikini for TOC code.

Save the following code as ##actions/headings.php##...
+ REVISED 12May05 (c) GMBowen to turn into a headings lister for the page. This modification +
+ ignores titles between 6 equal signs, removes the active links, etc. Released under GPL +

Originally obtained from on 11May05 as Table of
Contents code

toc.php : Affiche le sommaire de la page en cours

Copyright 2003 Jeremie COOK

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

// Load the page content into a variable

$page = $this->LoadPage($this->getPageTag());
$toc = $page["body"];

// remove some characters

$toc = str_replace("\r", "", $toc);
$toc = chop($toc)."\n";

// Removes all but the titles

$nonEgEg = "([^=]*=?[^=]+)*"; // Suite de caractères sans == Continuation of characters without ==

$toc = preg_replace("($nonEgEg((=){2,6})$nonEgEg((=){2,6})$nonEgEg)ms", "\\2#NumTitre#\\4\\2 ", $toc);

// Puts the headings in order

$toc = preg_replace_callback("(#NumTitre#)ms",
create_function (
'static $numTitre = 0; return "#".++$numTitre."#";'
, $toc);

// Creating the bulleted list

$toc = preg_replace("((=){6}#(([0-9]+))#($nonEgEg)(=){6} )", "", $toc);
$toc = preg_replace("((=){5}#(([0-9]+))#($nonEgEg)(=){5} )", "<li><strong>\\4</strong></li>\n", $toc);
$toc = preg_replace("((=){4}#(([0-9]+))#($nonEgEg)(=){4} )", "<ul><li><strong><i>\\4</i></strong></li></ul>\n", $toc);
$toc = preg_replace("((=){3}#(([0-9]+))#($nonEgEg)(=){3} )", "<ul><ul><li><i>\\4</i></li></ul></ul>\n", $toc);
$toc = preg_replace("((=){2}#(([0-9]+))#($nonEgEg)(=){2} )", "<ul><ul><ul><li>\\4</li></ul></ul></ul>\n", $toc);

$toc = preg_replace("/<br \/>$/","", trim($toc));

// Posts the formatted code

echo '<div id="headings">';
echo '<h4>Page Headings</h4>'."\n";
echo "\n";
echo $toc;
echo "\n\n";
echo '</div>';

DotMG's suggestion for changing the css code (from WikkaCSS) is....
==min-width and max-width==
You should not use fixed width in .floatr and .floatl classes. Instead, I suggest the use of max-width and min-width :
%%(css).floatl {float: left; margin: 0.5%; padding: 0.5%; background: #EEE; min-width: 100px; max-width: 300px;}
.floatr {float: right; margin: 0.5%; padding: 0.5%; background: #EEE; min-width: 100px; max-width: 300px;}%%
Try with the code ""<<{{calendar}}<< ""
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki