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 [2009-10-10 16:28] – tag cleanup layneeplugin:pageindex [2023-12-16 23:13] (current) – new download url Aleksandr
Line 1: Line 1:
-====== plugin:pageindex ======+====== pageindex Plugin ======
  
 ---- plugin ---- ---- plugin ----
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 12: Line 12:
 similar    : nstoc similar    : nstoc
 tags       : navigation, menu, listing, namespace tags       : navigation, menu, listing, namespace
 +
 +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~~  <-  Lists the current namespace.+
  
-I found that on the [[http://www.puzzlers.org]] websitewe 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 othersNow I just add a tag to each page and they automatically update over time.+  * ''%%~~PAGEINDEX=section:namespace;except1;except2,desc~~%%''  <-  Lists the specified namespace, excludes //except1// and //except2//, sorts descending. 
 +  * ''%%~~PAGEINDEX=section:namespace;except1;except2~~%%''  <-  Lists the specified namespaceexcludes //except1// and //except2//, sorts ascending. 
 +  * ''%%~~PAGEINDEX=section:namespace~~%%''  < Lists the specified namespace. 
 +  * ''%%~~PAGEINDEX~~%%''  <-  Lists the current namespace.
  
-The list will //not// include the current page, either, to reduce confusion.+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 //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 29: Line 51:
 Put the following code into **lib/plugins/pageindex/syntax.php** in your DokuWiki site.  Then you can add the tags above into any page you want a namespace index. Put the following code into **lib/plugins/pageindex/syntax.php** in your DokuWiki site.  Then you can add the tags above into any page you want a namespace index.
  
 +===== 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;
 +}
  
-===== The Code =====+ 
 + 
 + 
 +/** 
 + * 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'
 + 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 ====
  
-<code php>+<file php syntax.php>
 <?php <?php
 /** /**
Line 99: Line 317:
             'name'   => 'Page Index',             'name'   => 'Page Index',
             'desc'   => 'Presents an index list of files in the current namespace',             'desc'   => 'Presents an index list of files in the current namespace',
-            'url'    => 'http://www.dokuwiki.org/wiki:plugins',+            'url'    => 'http://www.dokuwiki.org/plugin:pageindex',
         );         );
     }     }
Line 218: Line 436:
 } // syntax_plugin_pageindex } // syntax_plugin_pageindex
  
-</code>+</file> 
  
 ==== Version 1 ==== ==== Version 1 ====
  
-<code php>+<file php syntax.php>
 <?php <?php
 /** /**
Line 282: Line 501:
             'name'   => 'Page Index',             'name'   => 'Page Index',
             'desc'   => 'Presents an index list of files in the current namespace',             'desc'   => 'Presents an index list of files in the current namespace',
-            'url'    => 'http://www.dokuwiki.org/wiki:plugins',+            'url'    => 'http://www.dokuwiki.org/plugin:pageindex',
         );         );
     }     }
Line 402: Line 621:
 } // syntax_plugin_pageindex } // syntax_plugin_pageindex
  
-</code>+</file>
  
  
 ===== 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 ====
  
Line 421: Line 652:
 I need also a listing of the namespace under the current namespace. How i have to modify the code? Can you show me an example. Thanks, Johann.  I need also a listing of the namespace under the current namespace. How i have to modify the code? Can you show me an example. Thanks, Johann. 
  
-<code>+<code diff>
 *** syntax.php  2006/12/16 19:27:01     1.1 *** syntax.php  2006/12/16 19:27:01     1.1
 --- syntax.php  2006/12/16 19:37:06 --- syntax.php  2006/12/16 19:37:06
Line 460: Line 691:
  
 ---- ----
- 
- 
- 
- 
  
  
Line 470: Line 697:
 We had to replace the line We had to replace the line
  
-<code lang="php">+<code php>
 // New Oct 3, 2006 -- end // New Oct 3, 2006 -- end
 $ns  = cleanID(getNS("$data:dummy")); $ns  = cleanID(getNS("$data:dummy"));
Line 477: Line 704:
 with  with 
  
-<code lang="php">+<code php>
 // New Oct 3, 2006 -- end // New Oct 3, 2006 -- end
 $ns  = cleanID(getNS("{$parameters[0]}:dummy")); $ns  = cleanID(getNS("{$parameters[0]}:dummy"));
Line 512: Line 739:
  - Stephen (stephen-dot-leedle-at-gmx-dot-de)  - Stephen (stephen-dot-leedle-at-gmx-dot-de)
 ---- ----
-I prefer the [[http://www.dokuwiki.org/plugin:pagelist|pagelist plugin]] for rendering. It's easy to add :+I prefer the [[plugin:pagelist|pagelist plugin]] for rendering. It's easy to add :
 Just replace theses lines : Just replace theses lines :
 <code> <code>
Line 556: Line 783:
  
 ---------------- ----------------
 +
 +:!: It's not a bug, it's a feature
 +
 +If you use some templates that make a sitemap on the right or on the left ... beware of redefinition of function search_list_index()
 +workaround is vi regexp in the pasted syntax.php :
 +<code bash>
 +:%s/search_list_index/search_list_index_whateveryouwant/
 +</code>
 +
 +
 +----------------
 +
 +
 +
 :!: Possible bug: No unicode (cyrillics, for example) support. :!: Possible bug: No unicode (cyrillics, for example) support.
 +
 +----------------
 +
 +:!: Possible bug: Not obeying config:hidepages.
  
plugin/pageindex.1255184896.txt.gz · Last modified: 2009-10-10 16:28 by laynee

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