Table of Contents
Censure Plugin
Compatible with DokuWiki
No compatibility info given!
Edits must first be approved by an member of the censorship group before being published. Deals with Quality management systems and ISO_9001.
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 publish
Note: The functionality of this plugin is also provided by the more up-to-date Publish plugin, which is under active development. This plugin, Censure, seems to have been discontinued.
Censure definition
Censure = Censorship (and not censure)1)
TODO Work in progress
TODO : i have to translate it to English. i have to put all the language related sentences to vars (and then Param). Then I have to explain how to install it.
I can not redo your bug (line 20).2) Try to redo the install by copying the whole code … If the bug persist I will try one other dev environment…
About the two main flags : VALIDE and NON VALIDE. It is french sentences that I have to translate. It means : “VALID. An act, deed, will, and the like, which has received all the formalities required by law, is said to be valid or good in law.” 3)
NON VALIDE = NO VALID.
Ok. Next, every time somebody (and admin too) edit a page, by default, I will put this tag “NOVALID” on the page.
With a link “click here to validate this page”.
Only members of a certain group of the wiki can do the trick, and change the méta of the document from NOVALID to VALID.
Moreover. All the document with méta NOVALID can not be viewed by non authorized members of the wiki. Only the contributor of the page or the admin or the members of “Quality group” can edit this page.
This is quite a mess for tonight so I will try to improve it tomorrow.
What is it ?
This tip is to integrate a new feature called 'censure'. Censure deals with Quality management systems and ISO_9001. This tip deals with the question:
“Is it possible to configure DokuWiki in such a way, that all edits must first be approved by an administrator before being published?”
Andi provides an answer to this in the FAQ:approval. And that's right :! DokuWiki don't have to deal with that sort of “control system”.
But my Quality manager asked me prior to an Audit to add some functionality to our local DokuWiki.
- Every new change may be monitored (that's done by DokuWiki base code)
- Every new change may block the access to the page changed (not supported by DokuWiki)
- And if the page is blocked by quality policies, user may have a link to the last approved revision of the page.
- Members of a special group, that we call “qualite” in French or “quality” in English, may have the right to approve change, and so put back the page in classic DokuWiki access.
This policy is for me completely stupid, but I have no choice…
So I do the worst code on a pseudo “plugins” to act like the quality policy say.
Installation
- Here the code, create a directory lib/plugins/ that you name “censure”
- Create into that directory a page that you name action.php
- Copy past the code…
- Create two smiley for the pseudo tags “VALIDE” and “NONVALIDE”.
- I FORGOT to mention that you have to create in “User Manager”, a “group” of user that may have the name “qualite”, every user with power needs to join this group for being able to “censure” this wiki….
Cry on your new censured DokuWiki
The Code
<?php //TODO virer les 3 lignes du pas valide, c'est un peu trop... if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'action.php'); class action_plugin_censure extends DokuWiki_Action_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Jean Marc Masou', 'email' => 'massou@gmail.com', 'date' => '2007-11-22', 'name' => 'censure', 'desc' => 'Checks Events', 'url' => 'http://www.massou.tk' ); } /* * Register its handlers with the DokuWiki's event controller */ function register(Doku_Event_Handler $controller) { /* $events = array ( 'ACTION_HEADERS_SEND', 'HTML_PAGE_FROMTEMPLATE', 'HTML_PROFILEFORM_INJECTION', 'HTML_REGISTERFORM_INJECTION', 'IO_NAMESPACE_CREATED', 'IO_NAMESPACE_DELETED', 'IO_WIKIPAGE_READ', 'IO_WIKIPAGE_WRITE', 'PARSER_CACHE_USE', 'PARSER_HANDLER_DONE','PARSER_WIKITEXT_PREPROCESS', 'RENDERER_CONTENT_POSTPROCESS', 'TPL_ACT_RENDER', 'TPL_CONTENT_DISPLAY', 'TPL_METAHEADER_OUTPUT' ); */ $events = array ( 'TPL_METAHEADER_OUTPUT', 'TPL_ACT_RENDER', 'IO_WIKIPAGE_WRITE' ); foreach($events as $evt) { $controller->register_hook($evt, 'BEFORE', $this, 'write_event_before'); $controller->register_hook($evt, 'AFTER', $this, 'write_event_after'); } } function write_event_before (&$event, $param) { $this->write_event ($event, $param,'BEFORE'); } function write_event_after (&$event, $param) { $this->write_event ($event, $param, 'AFTER'); } function write_event (&$event, $param=NULL, $advise) { global $ID; global $conf, $INFO; $page_editednotvalid = 'Cette page n\'a pas été validé<br>'; $follow_thislink = 'Vous pouvez suivre ce lien pour voir l\'ancienne version : <br>'; $wait_valid = 'Il faut attendre que la page soit validée pour pouvoir la voir<br>'; $no_right = 'Vous n\'avez pas assez de droit pour consulter cette page<br>'; $no_valid_butedit = ' Votre page n\'a pas encore été validé Mais vous pouvez la modifier en tant qu\'auteur ou contributeur <br>'; $validator = ' Vous pouvez la valider en suivant ce lien : <br> '; //we test if the user is a member of the censure group //print_r($INFO); $grps = $INFO['userinfo']['grps']; $qg = 0; if (count($grps)>0) { foreach($grps as $g ){ if($g == 'admin' | $g == 'qualite'){ $qg=1; break; } } } $test = $event->name; //echo $test; $date = time(); //use current time if none supplied if($test == 'IO_WIKIPAGE_WRITE' && $advise == 'BEFORE') { $test2 = $event->data; //We select just when write on the data and not in the Attic... $rev = $test2[3]; //echo "after..."; // we edit the summary and append "NON VALIDE" $sum = $event->summary; $event->summary = $sum . "NON VALIDE"; //echo $_REQUEST['summary'] ; $_REQUEST['summary'] = "NON VALIDE"; //echo $event->summary ; $brut = $event->data[0][1]; $brut = str_replace("\\\\ \\\\ [[:valide]]VALIDE ","", $brut ); $brut = str_replace("\\\\ \\\\ [[:non valide]]NONVALIDE","", $brut ); $event->data[0][1]=$brut."\n \n \n \n \n \n\\\\ \\\\ [[:non valide]]NONVALIDE"; if ($rev <> '') { /*$file = $conf[metadir]."\\".str_replace(":","\\", $INFO[id] ).".changes" ; $file2 = $conf[changelog]; //$pattern ="[".$date ."]"; $pattern ="[".$rev."]"; $test = io_deleteFromFile($file,$pattern,true); $test = io_deleteFromFile($file2,$pattern,true); */ addLogEntry($date, $ID, DOKU_CHANGE_TYPE_EDIT, "PAGE NON VALIDE"); //addLogEntry($rev, $ID, DOKU_CHANGE_TYPE_EDIT, $_REQUEST['summary']." PAGE NON VALIDE"); $meta = array(); $user = (!$flagExternalEdit)?$_SERVER['REMOTE_USER']:''; if ($user) $meta['QUALITE']['user'] = $INFO['userinfo']['name']; $meta['QUALITE']['modified'] = $date; $meta['QUALITE']['TYPE'] = "NON VALIDE"; p_set_metadata($ID, $meta); } } if ($test == 'TPL_ACT_RENDER' & $advise == 'BEFORE'){ // msg($this->getLang('missing_pagelistplugin'), -1); $metas=p_get_metadata($ID); if ($metas['QUALITE']['TYPE']== "NON VALIDE") { $user = $INFO['userinfo']['name']; $editor = 0 ; //echo $user; if (is_string ($user)){ //print_r($metas); //echo $INFO['userinfo']['name']; //echo $metas['creator']; $contrib = $metas['contributor']; //echo $user; if ($metas['creator'] == $user){ $editor = 1 ; }else{ if (count($contrib)>0) { foreach($contrib as $cont ){ if($cont == $user){ //echo "contributeur".$user; $editor = 1 ; break; } } } } } //echo "editor".$user.$editor.$metas['creator']."/n"; if ($_REQUEST['do'] == 'revisions' | $_REQUEST['rev']<>'') { //we hide the bad revisions.... $info = getRevisionInfo($ID, $_REQUEST['rev']); //print_r ($info); //echo $info[sum]."<br>"; if($info[sum]=="PAGE VALIDE"){ //we show the page }elseif($qg==0 & $editor == 0){ //we hide the page and the revisions echo $no_right; $event->preventDefault(); $event->stopPropagation(); } }elseif ($editor <> 1 & $qg==0 ) { $revisions = getRevisions($ID, 1,50 ); if (count($revisions)>0) { foreach($revisions as $rev ){ $info = getRevisionInfo($ID, $rev); //print_r ($info); //echo $info[sum]."<br>"; if(@file_exists(wikiFN($ID,$rev))&$info[sum]=="PAGE VALIDE"){ $goodlastrev = $rev; $pagevalide = 1; break; } } echo $page_editednotvalid; echo $follow_thislink; echo '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>'; echo $no_right; $event->preventDefault(); $event->stopPropagation(); } else { echo $wait_valid; } } if ($qg==0 & $editor == 1){ echo $no_valid_butedit; } elseif ($qg==1){ echo $page_editednotvalid; echo $validator; print '<a class="wikilink1" href="'.wl($ID,"doit=valide").'">'.$ID.'</a>'; } else{ } } } if ($test == 'TPL_METAHEADER_OUTPUT' & $advise == 'BEFORE') { if ($_REQUEST['doit'] == 'valide' && $qg == 1) { $revisions = getRevisions($ID, 0,50 ); //print_r($revisions); if (count($revisions)>0) { foreach($revisions as $rev ){ if(@file_exists(wikiFN($ID,$rev))){ $goodlastrev = $rev; break; } } $file = $conf[metadir]."\\".str_replace(":","\\", $INFO[id] ).".changes" ; $file2 = $conf[changelog]; $pattern ="[".$INFO[lastmod]."]"; //$pattern ="[".$rev."]"; $test = io_deleteFromFile($file,$pattern,true); $test = io_deleteFromFile($file2,$pattern,true); addLogEntry($goodlastrev, $ID, DOKU_CHANGE_TYPE_EDIT, "PAGE VALIDE"); } else { addLogEntry($date, $ID, DOKU_CHANGE_TYPE_EDIT, "PAGE VALIDE"); } echo "VALIDE".$goodlastrev ; //p_set_metadata($ID, $data, $render, $persistent) $file_name= $conf[datadir]."/".str_replace(":","/", $INFO[id] ).".txt" ;; echo $file_name; if(file_exists($file_name)) { /* Open file for both reading and writng. * Place pointer at the beginning of the file. */ $handle = fopen($file_name, 'r+'); if(!$handle) { die("couldn't open file <i>$file_name</i>"); } while(1) { //read line $line = fgets($handle); //if end of file reached then stop reading anymore if($line == null)break; //replace student gpa with new updated gpa if(preg_match("/\[\[\:non valide\]\]NONVALIDE/", $line)) { //$new_line = str_replace ("non valide", "valide", $line); //$new_line = str_replace ("NONVALIDE", "VALIDE", $new_line ); //$new_line = str_replace ("]]NONVALIDE", " ", $new_line ); $new_line = preg_replace("/\[\[\:non valide\]\]NONVALIDE/", "[[:valide]]VALIDE ", $line); } else { //set file content to a string $str.= $line; } } //append new updated gpa to file content $str.= $new_line; //set pointer back to beginning rewind($handle); //delete everything in the file. ftruncate($handle, filesize($file_name)); //write everything back to file with the updated gpa line fwrite($handle, $str); echo "Page Validée avec succés sauvée sur le disque :!"; } else { echo "file <i>$file_name</i> doesn't exists"; } fclose($handle); $meta = array(); $user = (!$flagExternalEdit)?$_SERVER['REMOTE_USER']:''; //if ($user) $meta['QUALITE'][$user] = $INFO['userinfo']['name']; if ($user) $meta['QUALITE']["user"] = $INFO['userinfo']['name']; $meta['QUALITE']['modified'] = $date; $meta['QUALITE']['TYPE'] = "VALIDE"; p_set_metadata($ID, $meta); }elseif ($_REQUEST['doit'] == 'nonvalide' && $qg == 1) { echo "NON VALIDE"; $file_name= $conf[datadir]."\\".str_replace(":","\\", $INFO[id] ).".txt" ;; echo $file_name; if(file_exists($file_name)) { /* Open file for both reading and writng. * Place pointer at the beginning of the file. */ $handle = fopen($file_name, 'r+'); if(!$handle) { die("couldn't open file <i>$file_name</i>"); } while(1) { //read line $line = fgets($handle); //if end of file reached then stop reading anymore if($line == null)break; //replace student gpa with new updated gpa if(preg_match("/\[\[\:valide\]\]VALIDE/", $line)) { //$new_line = str_replace ("non valide", "valide", $line); //$new_line = str_replace ("NONVALIDE", "VALIDE", $new_line ); //$new_line = str_replace ("]]NONVALIDE", " ", $new_line ); $new_line = preg_replace("/\[\[\:valide\]\]VALIDE/", "[[:non valide]]NONVALIDE ", $line); } else { //set file content to a string $str.= $line; } } //append new updated gpa to file content $str.= $new_line; //set pointer back to beginning rewind($handle); //delete everything in the file. ftruncate($handle, filesize($file_name)); //write everything back to file with the updated gpa line fwrite($handle, $str); echo "Page InValidée avec succés sauvée sur le disque :!"; } else { echo "file <i>$file_name</i> doesn't exists"; } fclose($handle); $date = time(); //use current time if none supplied addLogEntry($date, $ID, DOKU_CHANGE_TYPE_EDIT, "PAGE NON VALIDE"); $meta = array(); $user = (!$flagExternalEdit)?$_SERVER['REMOTE_USER']:''; if ($user) $meta['QUALITE']['user'] = $INFO['userinfo']['name']; $meta['QUALITE']['modified'] = $date; $meta['QUALITE']['TYPE'] = "NON VALIDE"; p_set_metadata($ID, $meta); /* // send notify mails notify($id,'admin',$old,$summary,$minor); notify($id,'subscribers',$old,$summary,$minor); */ } } if ($test == 'TPL_ACT_RENDER' & $advise == 'AFTER'){ // msg($this->getLang('missing_pagelistplugin'), -1); $metas=p_get_metadata($ID); echo '<script type="text/javascript">'; echo 'function removeElement()'; echo '{'; echo 'document.getElementById("qualite").style.display="block";'; echo '}'; echo '</script>'; echo '<input type="button" onclick="removeElement()" value="Cartouche Qualite" />'; echo '<style type="text/css" media="print">'; echo 'div#qualite {display: block;position: fixed; margin-left: auto; margin-right: auto; width: 100%;}'; echo '</style>'; echo ' <div class="qualite" id="qualite" style="display:none"><pre>'; echo '<img src="http://www.topagri.fr/includes/a901/logo.gif" alt="Top@gri Services">'; echo "<br><h3>STATUT DOCUMENT</h3>Titre du document : ".$metas['title']."<br>"; echo "Date de Création : ".date("d-m-Y h:m",$metas['date']['created'])."<br>"; echo "Date de dernière édition : ".date("d-m-Y h:m",$metas['date']['modified'])."<br>"; $contrib = $metas['contributor']; if (count($contrib)>0) { $i=0; foreach($contrib as $cont ){ if ($i == 0){ }elseif ($i ==1){ echo "Créateur : ".$cont."<br>"; }else{ echo "Contributeur ".($i-1)." : ".$cont."<br>"; } $i= $i+1 ; } } echo "Statut du document : ".$metas['QUALITE']['TYPE']."<br>"; echo "Validation par : ".$metas['QUALITE']['user']."<br>"; echo "le : ".date("d-m-Y h:m",$metas['QUALITE']['modified'])."<br>"; //print_r ($metas); echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "</pre></div>"; } /* $filename = DOKU_INC . 'eventcheck.txt'; if (!$handle = fopen($filename, 'a')) { return; } $somecontent = "\n --- $advise ---\n"; $somecontent .= "\$_REQUEST: " . print_r($_REQUEST, true) . "\n"; $somecontent .= print_r($event, true) . "\n"; fwrite($handle, $somecontent); fclose($handle);*/ } }
Todo
- clean that dusty code…
- Integrate this JavaScript method :
http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm