DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:pageindex

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:pageindex [2015-09-27 22:32] Aleksandrplugin:pageindex [2023-12-16 23:13] (current) – new download url Aleksandr
Line 6: Line 6:
 email      : kite@puzzlers.org email      : kite@puzzlers.org
 type       : syntax type       : syntax
-lastupdate : 2006-08-01+lastupdate : 2021-03-17
 compatible : compatible :
 depends    : depends    :
Line 13: Line 13:
 tags       : navigation, menu, listing, namespace tags       : navigation, menu, listing, namespace
  
-downloadurl: http://www.dokuwiki.org/_export/code/plugin:pageindex?codeblock=0+downloadurl: https://trello.com/1/cards/5d51a62cd417f934264631d5/attachments/5d51a760270fe1276a8bf0d0/download/pageindex.zip 
 +bugtracker :  
 +sourcerepo :  
 +donationurl:  
 + 
 +screenshot_img: 
 ---- ----
 +
 +===== Notes on this Updated Version (2021-03-17) =====
 +
 +The download link above is for the version released on 2006-08-01.
 +
 +Below, I have added my 1.3 version, and I have also uploaded the code for //syntax.php// to github:
 +
 +https://gist.github.com/jeffmikels/2b1d0948ffdbed600418a2492a98cfeb/archive/b569f90ab7a4498c06e1a6f30dd6e7439597c74d.zip
 +
 +<jeff@mikels.cc>
 +
  
 ===== Usage ===== ===== Usage =====
  
-You can use one of two tag styles:+You can use one of four tag styles:
  
-  * ''~~PAGEINDEX=section:namespace~~''  <-  Lists the specified namespace. +  * ''%%~~PAGEINDEX=section:namespace;except1;except2,desc~~%%''  <-  Lists the specified namespace, excludes //except1// and //except2//, sorts descending
-  * ''~~PAGEINDEX~~''  <-  Lists the current namespace.+  * ''%%~~PAGEINDEX=section:namespace;except1;except2~~%%''  <-  Lists the specified namespace, excludes //except1// and //except2//, sorts ascending. 
 +  * ''%%~~PAGEINDEX=section:namespace~~%%''  <-  Lists the specified namespace. 
 +  * ''%%~~PAGEINDEX~~%%''  <-  Lists the current namespace.
  
-I found that on the [[http://www.puzzlers.org]] website, we have sections which get lots of pages over a short time and cross-referencing was a chore since some users aren't as wiki-oriented as others. Now I just add a tag to each page and they automatically update over time.+I found that on the [[http://www.puzzlers.org/]] website, we have sections which get lots of pages over a short time and cross-referencing was a chore since some users aren't as wiki-oriented as others. Now I just add a tag to each page and they automatically update over time.
  
-The list will //not// include the current page, either, to reduce confusion.+The list will //never// include the current page, either, to reduce confusion
 + 
 +**NOTE:** To keep your index up to date, you might want to add %%~~NOCACHE~~%% to pages where you use it.
  
 ===== Installation ===== ===== Installation =====
Line 32: Line 52:
  
 ===== The Code ===== ===== The Code =====
 +
 +==== Version 1.3 ====
 +
 +<file php syntax.php>
 +<?php
 +/**
 + * Plugin page index: index table for pages in a name space
 + *
 + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 + * @author     Kite <Kite@puzzlers.org>
 + * @based_on   "externallink" plugin by Otto Vainio <plugins@valjakko.net>
 + */
 + 
 +if(!defined('DOKU_INC')) {
 + define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
 +}
 +if(!defined('DOKU_PLUGIN')) {
 + define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 +}
 +
 +require_once(DOKU_PLUGIN.'syntax.php');
 +require_once(DOKU_INC.'inc/search.php');
 +
 +
 +function search_list_index(&$data,$base,$file,$type,$lvl,$opts){
 + global $ID;
 + //we do nothing with directories
 + if($type == 'd') return false;
 + if(preg_match('#\.txt$#',$file)){
 + //check ACL
 + $id = pathID($file);
 + if(auth_quickaclcheck($id) < AUTH_READ){
 + return false;
 + }
 + if($opts['ns'].":$id" <> $ID) {
 + $data[] = array( 
 + 'id'    => $opts['ns'].":$id",
 + 'type'  => $type,
 + 'level' => $lvl );
 + }
 + }
 + return false;
 +}
 +
 +
 +
 +
 +/**
 + * All DokuWiki plugins to extend the parser/rendering mechanism
 + * need to inherit from this class
 + */
 +class syntax_plugin_pageindex extends DokuWiki_Syntax_Plugin {
 + 
 +    /**
 +     * return some info
 +     */
 +    function getInfo(){
 +        return array(
 +            'author' => 'Kite',
 +            'email'  => 'kite@puzzlers.org',
 +            'date'   => '2009-02-01',
 +            'name'   => 'Page Index',
 +            'desc'   => 'Presents an index list of files in the current namespace',
 +            'url'    => 'http://www.dokuwiki.org/plugin:pageindex',
 +        );
 +    }
 + 
 +    /**
 +     * What kind of syntax are we?
 +     */
 +    function getType(){
 +        return 'substition';
 +    }
 + 
 +    // Just before build in links
 +    function getSort(){ return 299; }
 + 
 +    /**
 +     * What about paragraphs?
 +     */
 +    function getPType(){
 +        return 'block';
 +    }
 +
 + function connectTo($mode) {
 +       $this->Lexer->addSpecialPattern('~~PAGEINDEX[^~]*~~',$mode,'plugin_pageindex');
 +       //$this->Lexer->addSpecialPattern('~~PAGEINDEX~~',$mode,'plugin_pageindex');
 +    }
 + 
 + 
 +    /**
 +     * Handle the match
 +     */
 +    function handle($match, $state, $pos, &$handler){
 +    $match = preg_replace("%~~PAGEINDEX(=(.*))?~~%", "\\2", $match);
 +    //echo "\n\t<!-- syntax_plugin_pageindex.handle() found >> $match << -->\n";
 +        return $match;
 +    }
 + 
 +    /**
 +     * Create output
 +     */
 +    function render($mode, &$renderer, $data) {
 +        if($mode == 'xhtml'){
 +            $text=$this->_pageindex($renderer, $data);
 +            $renderer->doc .= $text;
 +            return true;
 +        }
 +        return false;
 +    }
 + 
 + 
 + function _pageindex(&$renderer, $data) {
 + global $conf;
 + global $ID;
 +        
 + //$renderer->doc .= "\n\n<!-- syntax_plugin_pageindex._pageindex(\$renderer, \"$data\") -->\n";
 +
 + /*
 + MODIFIED BY JEFF MIKELS TO CHANGE THE WAY THE PARAMETERS ARE HANDLED
 + ~~PAGEINDEX[=namespace[;excluded-pages][,DESC]]~~
 + where excluded-pages are a semicolon-separated list of pages to exclude
 + and DESC (case insensitive) will reverse the sort order of the rendered index
 + */
 + $dataparams = explode(',', $data);
 + $parameters = explode(';', $dataparams[0]);
 + $ns  = cleanID(getNS("$parameters[0]:dummy"));
 +
 + #fixme use appropriate function
 + if(empty($ns)){
 + $ns = dirname(str_replace(':',DIRECTORY_SEPARATOR,$ID));  // 2007/12/30 Kite - use localized constant
 + if($ns == '.') $ns ='';
 + }
 + //$ns  = utf8_encodeFN(str_replace(':',DIRECTORY_SEPARATOR,$ns));   // 2007/12/30 Kite - use localized constant
 + //$ns  = utf8_encodeFN($ns);
 +
 + $search_data = array();   // Oct 3, 2006 renamed $data to $search_data for clarity
 + $dir = $conf['datadir']. DIRECTORY_SEPARATOR .str_replace(':',DIRECTORY_SEPARATOR,$ns);   // 2007/12/30 Kite - use localized constant
 + $ns = str_replace(DIRECTORY_SEPARATOR,':',$ns);
 + $renderer->doc .= "\n<!-- \$dir = $dir  \$ns = $ns -->\n";
 + search($search_data,     // results   == renamed $data to $search_data
 + $dir,                  // folder root
 + 'search_list_index',   // handler
 + array('ns' => $ns)     // options
 + );
 +
 + $checked = [];
 +
 + // Remove the items not wanted in the list
 + if(is_array($parameters)) {
 + $skipitems = array_slice($parameters, 1);
 + foreach($search_data as $item) {
 + $found = false;
 + // Add ns if user didn't
 + foreach($skipitems as $skip) {
 + $skip = strpos($skip,":") ? $skip : "$ns:$skip"; 
 + if($item['id'] == $skip) {
 + $found = true;
 + break;
 + }
 + }
 + if(!$found) {
 + // Pass this one through
 + $checked[] = $item;
 + } else {
 + //$renderer->doc .= "<!-- rejected entry ".$item['id']." -->\n";
 + }
 + }
 + }
 +
 + // use the filtered data rather than $search_data
 + if(count($checked)) {
 +
 + // sort properly
 + if (!empty($dataparams[1]) && strtolower($dataparams[1]) == 'desc') {
 + $checked = array_reverse($checked);
 + }
 +
 +/* Option to use an HTML List */
 + $renderer->doc .= html_buildlist($checked,
 + 'idx',
 + 'html_list_index',
 + 'html_li_index'
 + );
 +
 +/* Option to use the PageList plugin */
 +/*
 + $pages = $checked;
 + $pagelist =& plugin_load('helper', 'pagelist');
 + if (!$pagelist) return false; // failed to load plugin
 + $pagelist->startList();
 + foreach ($pages as $page){
 + $pagelist->addPage($page);
 + }
 + $renderer->doc .= $pagelist->finishList();
 +*/
 + } else {
 + $renderer->doc .= "\n\t<p>There are no documents to show.</p>\n";
 + }
 + } // _pageindex()
 +} // syntax_plugin_pageindex
 +</file>
  
 ==== Version 1.2 ==== ==== Version 1.2 ====
Line 215: Line 437:
  
 </file> </file>
 +
  
 ==== Version 1 ==== ==== Version 1 ====
Line 402: Line 625:
  
 ===== Updates ===== ===== Updates =====
 +
 +==== March 17, 2021 ====
 +
 +I added another option to the pageindex code to change the page sorting of the generated indexes.
 +
 +You can now write your pageindex code like this:
 +
 +%%~~pageindex=namespace;except1;except2,desc~~%%
 +
 +to get all the pages in //namespace// other than //except1// or //except2// and sort the results in descending alphabetical order. \\ <jeff@mikels.cc>
 +
  
 ==== Oct 3, 2006 ==== ==== Oct 3, 2006 ====
plugin/pageindex.1443385949.txt.gz · Last modified: 2015-09-27 22:32 by Aleksandr

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki