Adds support for WP-style signatures by translating "~~~~" into signature/login name + date information.
Just create a folder in your lib/plugins dir, called “wikisign”. In it, create a file called action.php containing the following code:
<?php if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'action.php'); require_once(DOKU_INC.'inc/common.php'); class action_plugin_wikisign extends DokuWiki_Action_Plugin { function getInfo() { return array ( 'author' => 'FeepingCreature', 'email' => 'default_357-line@yahoo.de', 'date' => '2008-11-08', 'name' => 'WP-style signature', 'desc' => 'Translate ~~~~ into signature info', 'url' => '' ); } function register(&$controller) { $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'signtranslate'); } function signtranslate(&$event, $param) { $pi = pageinfo(); global $USERINFO; $userinfo = $USERINFO['name']; if (empty($userinfo)) $userinfo = $_SERVER[REMOTE_ADDR]; $date = gmdate('H:i, d F Y e'); // $event->data[0][1] = str_replace('~~~~', '---//'.$userinfo.' '.$date.'//', $event->data[0][1]); // thanks to mystore for the next line (ignore ~~~~ in unparsed blocks) $event->data[0][1] = preg_replace('#[^(<nowiki>|<code>|<file>| |%%)]~~~~#', '---//'.$userinfo.' '.$date.'//', $event->data[0][1]); } } ?>
Have fun!
Add compatibility with non-parsed block : Replace the last line by :
$event->data[0][1] = preg_replace('#[^(<nowiki>|<code>|<file>| |%%)]~~~~#', '---//'.$userinfo.' '.$date.'//', $event->data[0][1]);
myst6re 2008/10/05
At least give an example of its use. ~~~~ (DOES NOT WORK!)
Strange. That's how it's SUPPOSED to work, and _does_ work here. Are you sure you installed it correctly?
Agree with the person above me. Does not parse at all (even after adding the closing PHP tag at the end), and just shows ~~~~.
Mine gives me the username and date, but adds a weird character after the date. example: —Admin 15:21, 12 December 2008 e
Your PHP's gmdate does not parse the “e” code correctly.
> $date = gmdate('H:i, d F Y e');
Remove the “e” from that line.
I tried putting #~~~~#, it kind of works. but it leaves a trailing #
Ok, same poster as above line. I've modified the last line to…
$event->data[0][1] = preg_replace('/[ \t]+[^(<nowiki>|<code>|<file>|%%)]~~~~ *$/x', '---//'.$userinfo.' '.$date.'//', $event->data[0][1]);
Give it a shot –johncruise
How can I change the code to insert a link to the user-page? like … Admin instead of “Admin”