DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:nodisp

nodisp Plugin

Compatible with DokuWiki

  • 2016-06-26 "Elenor Of Tsort" unknown
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" yes
  • 2014-05-05 "Ponder Stibbons" unknown

plugin Hide text from view except from admin or manager

Last updated on
2016-01-16
Provides
Syntax

Similar to ifauth

Tagged with comment, hide

Installation

Download syntax.php from the source code below and install it in the folder: plugins/nodisp

Refer to Plugins on how to install plugins manually.

Examples/Usage

This plugin will conceal text from all viewers except users who are logged in and belong to either the admin or manager group. The text is still on the page, but not displayed. For true hiding, you would have to use the include plugin and set the appropritate ACLs.

Syntax

<nodisp> your text here </nodisp>
<nodisp>
your text here
and your text here
and here
etc
</nodisp>

Development

Source Code

To download, click on syntax.php at the top of the code block below.

syntax.php
<?php
 
    // must be run within DokuWiki
    if(!defined('DOKU_INC')) die();
 
    if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
    require_once(DOKU_PLUGIN.'syntax.php');
 
    /**
     * All DokuWiki plugins to extend the parser/rendering mechanism
     * need to inherit from this class
     */
    class syntax_plugin_nodisp extends DokuWiki_Syntax_Plugin {
 
        /**
         * return some info
         */
        function getInfo(){
            return array(
                'author' => 'Myron Turner',
                'email'  => 'turnermm02 AT shaw DOT ca',
                'date'   => '2016-01-16',
                'name'   => 'nodisp Plugin',
                'desc'   => 'hides display of enclosed text',
                'url'    => 'http://www.mturner.org',
            );
        }
 
        function getType(){ return 'formatting'; }
        function getPType(){ return 'stack'; }
        function getAllowedTypes() { return array('formatting', 'substition', 'disabled', 'protected', 'container', 'paragraphs' ); }   
        function getSort(){ return 168; }
        function connectTo($mode) { $this->Lexer->addEntryPattern('<nodisp.*?>(?=.*?</nodisp>)',$mode,'plugin_nodisp'); }
        function postConnect() { $this->Lexer->addExitPattern('</nodisp>','plugin_nodisp'); }
 
 
        /**
         * Handle the match
         */
        function handle($match, $state, $pos, Doku_Handler $handler){
 
 
            switch ($state) {
              case DOKU_LEXER_ENTER : 
               return array($state, false);
 
              case DOKU_LEXER_UNMATCHED :  return array($state, $match);
              case DOKU_LEXER_EXIT :       return array($state, '');
            }
 
            return array();
        }
 
        /**
         * Create output
         */
        function render($mode, Doku_Renderer $renderer, $data) {
            global $INFO;
            if($mode == 'xhtml'){
                $renderer->nocache(); // disable caching
                list($state, $match) = $data;
                switch ($state) {
                  case DOKU_LEXER_ENTER :  
                    if($INFO['isadmin'] || $INFO['ismanager'] ) break;   
                    $renderer->doc .= "<div style='display:none'>"; 
                    break;
 
                  case DOKU_LEXER_UNMATCHED :  $renderer->doc .= $renderer->_xmlEntities($match); break;
                  case DOKU_LEXER_EXIT : 
                    if($INFO['isadmin'] || $INFO['ismanager'] ) break;   
                    $renderer->doc .= "</div>"; break;
                }
                return true;
            }
            return false;
        }
 
 
 
}

Change Log

    • Fix method signature compatibility for PHP 7.0
    • Cache is automatically disabled now, no need for ~~NOCACHE~~ anymore
    • The plugin uses a <div>-Element now as it had the paragraph type stack anyway which meant that a new paragraph was opened inside the plugin and thus the plugin worked on block level and using a <span>-element produced invalid HTML.
    • Allows more syntax (paragraphs, lists, tables, …) inside the plugin

Known Bugs and Issues

Can you add this warning in the description of your plugin? Thanks. The page source is always visibile clicking the “show pagesource” button. — anto1945 2013/07/22 07:25

This is true for all the plugins which “hide” material. The only way to get true hiding is to use the include plugin. See the forum for this thread: https://forum.dokuwiki.org/post/39559
plugin/nodisp.txt · Last modified: 2016-01-16 22:12 by Michitux