DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:phpwikify

PHP Wikify

Compatible with DokuWiki

Lemming, Anteater, rincewind, angua

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

Last updated on
2005-07-22
Provides
Syntax

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

Security warning (please read plugin security guidelines): This extension 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!


Sorry to say so, but for me it does not work with Adora Belle.

  • I tried MP's example, but there are no <a> tags in the resulting page code.
  • my own code1) (below) results in garbled output with phpwikify, but works fine within php tags.
<phpwikify>
 
echo "\n< co de>";
 
$filetolookat = "ftp://linux.intranet.ufz.de/ubuntu/ufzmount.bash";
$modzeit = date("Y-m-d H:m", filemtime($filetolookat));
$inhalt = file_get_contents($filetolookat);
$inhalt = nl2br(htmlentities($inhalt, ENT_COMPAT, 'UTF-8'));
$inhalt = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $inhalt);
$inhalt = str_replace('  ', '&nbsp;&nbsp;'            , $inhalt);
 
echo "$inhalt</ co de>\n";
echo "\n---\n";
echo "Zuletzt geändert: $modzeit";
 
</phpwikify>

results in

linux.intranet.ufz.de/ubuntu/ufzmount.bash“; $inhalt = file_get_contents($filetolookat); $modzeit = date(„Y-m-d H:m“, filemtime($filetolookat)); $inhalt = nl2br(htmlentities($inhalt, ENT_COMPAT, 'UTF-8')); $inhalt = str_replace(„\t“, '&nbsp;&nbsp;&nbsp;&nbsp;', $inhalt); $inhalt = str_replace(' ', '&nbsp;&nbsp;' , $inhalt); echo$inhalt</ co de>\n“; echo „\n---\n“; echo „Zuletzt geändert: $modzeit“; </phpwikify> 

Werner FlammeWerner Flamme
werner.flamme

2012/12/03 15:54


This is working very well for me after changing the path for the plugins folder. I see this has not been update in a very long time. If you change inc/plugins to lib/plugins it will work as expected. The main site is not responding and not sure how to contact the owner but I would not mind to adopt this plugin for use in the extension manager if possible.

TehdangoTehdango

2017-02-23 17:47

1)
slightly modified to not garble this page: < co de> and </ co de> do not contain any spaces on my page, but they garble the output of this page :-(
plugin/phpwikify.txt · Last modified: 2017-02-23 17:50 by Tehdango