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...
<?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 http://www.wikini.net/wakka.php?wiki=ActionSommaire 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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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 (
         '$matches',
         '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 :
.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}}<<
--DotMG

CategoryUserContributions
Comments
Comment by 194.223.231.1
2005-07-01 08:17:38
I'm using a virtually unmodified Wikka Wakka Wiki 1.1.6.0 and this doesn't work for me. When I write ""{{headings}}"" or "">>{{headings}}>>"" and then press 'store' I get a "page can not be found for PageName/edit, and then viewing the page gets the same, so I have to revert to an older version.
Comment by GmBowen
2005-07-02 01:38:18
um, hmmm. I too am using it on a virtually unmodified version of wikka 1.1.6.0 (well, the header and footer have been modded since I installed "headings" but it did work before). I'm afraid I don't have any suggestions. Did you change the CSS code as recommended (and ya, I know that shouldn't matter if you're not doing it using the > brackets). If you figure out what's goofing up, I'd appreciate it if you posted it here. Thanks.
Comment by 194.223.231.1
2005-07-04 16:17:27
I didn't change the CSS code as I realised it didn't matter...
Comment by 194.223.231.1
2005-07-04 16:29:38
What appears to be the problem is that if I put ""{{headings}}"" anywhere after text on the page (except after the header), it gives me a "page not found" error.

Also it doesn't just show the forced link text, it shows the link and the forced link text
Comment by AC5-Webproxy48.direcpc.com
2005-07-04 22:27:44
What happens if you put {{headings}} at the very top of the page (which is the only place I've tried it actually....and my server is currently unreachable from where I am so I can't play with it) and then different headings (=====hiya=====, ====there====, ===stranger===....on different lines of course). Oh, and the links aren't supposed to be "live".....it's just a list. Live links require edits to wikka core and I was just trying to get a list. If you're looking for TOC stuff, see MindWikiTOC that was just posted today. It creates live links. gmb
Comment by host86-128-52-188.range86-128.btcentralplus.com
2005-07-05 00:27:39
If I put {{headings}} at the top it's fine, if i put it below a header it's fine. If it's after normal plain old text, the page fails.

What I meant by forced link text is that if you have a forced link as part of a header it shows something like [[http://www.blah.com/ blah]], in the list, rather than just "blah". I don't know whether that would require changes to core though.

I'll have a look at MindWikiTOC too, thanks for the heads-up.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki