DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:skill

Skill Plugin

Compatible with DokuWiki

No compatibility info given!

plugin Show Skill level for a page

Last updated on
2005-10-13
Provides
Syntax

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to progressbar, stars

Tagged with poll

The skill plugin allows you to show a number of stars to represent the level of skill needed to understand and use the page content.

Example on: http://www.woow-fr.com/wikistuce/doku.php?id=javascript:polices_proportionelles

How to use it

Just write {{skill>5/7}}

The /7 is not mandatory.

Install

Create a folder named 'skill' in the plugins directory and put the code provided below in a syntax.php file.

Don't forget to put the picture in the same folder.

Code

<?php
 
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');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_skill extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'iDo',
            'email'  => 'iDo@woow-fr.com',
            'date'   => '13/10/2005',
            'name'   => 'Skill Plugin',
            'desc'   => 'Add the possibility to show skill level',
            'url'    => 'http://www.dokuwiki.org/plugin:skill',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 107;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern("{{skill>[0-9]*/?[0-9]*}}",$mode,'plugin_skill');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        $match = substr($match,8,-2); // Strip markup
		$match=split('/',$match); // Strip size
 
        if (!isset($match[1])) $match[1] = $match[0];
		if ($match[0]>$match[1]) $match[1]=$match[0];
        return $match;
    }  
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){       		
            $renderer->doc .= '<div>';
            $renderer->doc .= $this->_Skill($data);
            $renderer->doc .= '</div>';
            return true;
        }
        return false;
    }
 
	function _Skill($d) {
		$mRet='';
		for($i=1;$i<=$d[0];$i++) {
			$mRet.='<img src="lib/plugins/skill/star.png" alt="." style="" />';
		}
		for($i=1;$i<=($d[1]-$d[0]);$i++) {
			$mRet.='<img src="lib/plugins/skill/star.png" alt="." style="filter:alpha(opacity=40);-moz-opacity:0.4;opacity: 0.4;" />';
		}
 
		return $mRet;
	}
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>

Other resource:

You must put this image in the same directory as syntax.php: http://www.woow-fr.com/wikistuce/lib/plugins/skill/star.png

Comments

What about making this plugin “plugin manager” compatible to provide automatic install ?
Thank you for this plugin ;-) Leedoriden

This is a great plugin! I have one request: a max number of stars, to prevent users from entering (for example) 3,000 stars. Also, I made a couple of changes:

The first is to put the stars in a <span> instead of <div>, so I can put text and stars on the same line.
Since transparencies aren't supported in Opera, the second replaces the less visible star with a different image.

            $renderer->doc .= '<span>';
            $renderer->doc .= $this->_Skill($data);
            $renderer->doc .= '</span>';
            return true;

And then:

function _Skill($d) {
$mRet='';
for($i=1;$i<=$d[0];$i++) {
$mRet.='<img src="lib/plugins/skill/star.png" alt="." style="" />';
}
for($i=1;$i<=($d[1]-$d[0]);$i++) {
$mRet.='<img src="lib/plugins/skill/star2.png" alt="." style="" />';
}

I added some code to limit the number of stars to 10. Simply insert these two lines in function handle, before the line 'return $match'.

   if ($match[0]>10) $match[0]=10;
   if ($match[1]>10) $match[1]=10;
Please, provide an archive so that we can use the plug-in manager. I spend most of my time at some strange place called work where I have much spare time but no FTP access to my wiki, so that I cannot do anything except using the plug-in manager…
I have changed the above max star = 10 with calculations…
  if ($match[1]>10) {
    $match[0] = 10 * $match[0] / $match[1];
    $match[1] = 10;
  }
This keeps the ratio, rather than a roof cut-off. (kenc)
plugin/skill.txt · Last modified: 2018-02-01 13:30 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