PHP Wikify

Compatible with DokuWiki

  • 2012-01-25 "Angua" yes
  • 2011-05-25 "Rincewind" yes
  • 2010-11-07 "Anteater" yes

plugin Allows one the possibility of having output of PHP scripts parsed

Last updated on
2005-07-22
Provides
Syntax

Security warning (please read plugin security guidelines): This plugin will allow execution of scripts. It should only be used when you trust ALL editors, best suited in private personal wikis.

Tagged with php

This plugin enables you to use PHP scripts in the wiki pages in the same way as by using the <php> tag. The difference is that the PHP script output is feed through the DokuWiki parser/renderer and you could create for example bulleted lists using ” *…”.

Security wise it is the same as having the Configuration Setting: phpok enabled. Even if the script output is parsed, any other actions taken by the script is NOT checked.

Download and Installation

Syntax/Usage

The following example

<phpwikify>
$tt = 'help';
echo "  * first bullet\n";
echo "  * $tt me\n";
</phpwikify>

will display

  • first bullet
  • help me

Source Code

This is a copy of the plugin displayed at http://wiki.kaspersandberg.com/doku.php?id=projects:dokuwiki:phpwikify 2010-04-03, please check original site for latest version.

syntax.php
<?php
/**
 * PHP-Wikify plugin: lets the parser wikify output of php scripts
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Kasper Sandberg <redeeman@metanurb.dk>
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'inc/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
class syntax_plugin_phpwikify extends DokuWiki_Syntax_Plugin
{
	function syntax_plugin_phpwikify(){
		global $PARSER_MODES;
		$this->allowedModes = $PARSER_MODES['formatting'];
	}
 
	function getInfo(){
		return array(
			'author' => 'Kasper Sandberg',
			'email'  => 'redeeman@metanurb.dk',
			'date'   => '2005-07-22',
			'name'   => 'PHP-Wikify Plugin',
			'desc'   => 'Enables php to be processed by renderer',
			'url'    => 'http://wiki.kaspersandberg.com/doku.php?projects:dokuwiki:phpwikify',
		);
	}
 
	function getType(){
		return "protected";
	}
 
	function getPType(){
		return "normal";
	}
 
	function getSort(){
		return 0;
	}
 
	function connectTo( $mode ) {
		$this->Lexer->addEntryPattern("<phpwikify>",$mode,"plugin_phpwikify");
	}
 
	function postConnect() {
		$this->Lexer->addExitPattern( "</phpwikify>","plugin_phpwikify");
	}
 
	function handle( $match, $state, $pos, &$handler ){
		$match = ereg_replace( "<phpwikify>", "", $match );
		$match = ereg_replace( "</phpwikify>", "", $match );
		return $match;
	}
 
	function render( $mode, &$renderer, $data ) {
		if($mode == 'xhtml'){
			ob_start();
			eval( $data );
			$renderer->doc .= p_render( "xhtml", p_get_instructions( ob_get_contents() ), $info );
			ob_end_clean();
			return true;
		}
		return false;
	}
}
?>

Discussion

This plugin is exactly what I have been looking for! The ability to generate Wiki code using PHP and then getting it parsed is very flexible indeed. For example, if you want to display certain Wiki text when meeting certain conditions - say for example, at a certain time of day - then you can use PHP to check for those conditions and then generate the appropriate Wiki text. It opens the doors to a lot of functionality - but, obviously, the potential security aspect must be understood and accepted.


Impressive, sincerely is the first plugin that is really useful to me, I wrote a dynamic menu generator in PHP because phpwikify made it possible, nice job. I post here the “automenu” as an example of what phpwikify can do, if anyone interested in developing it tell me, thanks: algspd at gmail dot com (sorry for bad English) To make the automenu work in real time, set cache to only a few seconds an this will include new pages automatically.

<phpwikify>
 
echo "<html><div style='margin-left: 30px;'>";
 
$namespaces = array("howto", "robotics", "wiki");
foreach ($namespaces as $namespace){
 echo "<br><b><u>".strtoupper($namespace)."</u></b><br><ul>";
 $dir=opendir("/var/www/data/pages/$namespace/");
 while ($archivo = readdir($dir)){
   if ($archivo!="." & $archivo!=".."){
 
     $name = basename($archivo, '.'. pathinfo($archivo, PATHINFO_EXTENSION));
 
     $name_c = str_replace("_", " ", ucwords($name));
 
     echo "<li><a href='?id=howto:$name'>$name_c</a><br>";}}
 closedir($dir);
 echo "</ul>";
}
echo "</div></html>";
</phpwikify>

MP - 10/04/2008


This is exactly the kind of extension I´ve been looking for. Only problem is: I use MediaWiki, not DokuWiki. Not being more than a novice coder, I wonder if there is any equivalent extension for MediaWiki, or if this function can be made compatible? Thanks!


This is an excellent plugin, thank you very much for sharing this. Is there any reason the output generated by this wouldn't work with <file txt somefile.txt></file> tags? I'm not sure if I'm doing it wrong, or if the plugin is not compatible with these tags. Thanks!

plugin/phpwikify.txt · Last modified: 2012/03/29 12:47 by 83.145.100.34
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate