Mypage plugin

Compatible with DokuWiki

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

plugin Adds an action (do=mypage) which renders a user page from a page template

Last updated on
2009-09-27
Provides
Action

Similar to userhomepage

Tagged with users

Download and Installation

Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.

  • FIXME put URL here

For manual installation, see Source code below

Dependencies

No other plugins are required, but any plugins capable of displaying information related to a specific user are useful, such as

  • The editor plugin, to show a list of pages edited by the currently logged in user.

How to use it

Add an action link in you template

<a href="<?php wl($ID, 'do=mypage')?>" class="action mypage" rel="nofollow" accesskey="m">My page</a>

Create a page template for the page "My page"

Create a page with the name mypagetemplate or a file called _mypage.txt in the data/pages directory.

This example uses the editor plugin to display a list of pages edited by the current user.

_mypage.txt
====== My page ======
 
Hello @NAME@! Here is a list of your contributions.
 
{{editor>?@USER@&header&table&firsthl&desc&comments}}

Supported macros in the page template are @NS@, @NAME@, @USER@, @MAIL@ and @DATE@.

Note: This page is not used as a page, but only as a template for the plugin. You may want to make it invisible using the ACL. To display the personalized user page, use the action mypage, i.e. do=mypage, on any page URL. Example: http://wiki.example.com/doku.php?id=start&do=mypage.

Source code

For manual installation, save this file as lib/plugins/mypage/action.php.

action.php
<?php
/**
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Viktor Söderqvist <viktor@zuiderkwast.se>
 *
 * Mypage - a user page created from a template where users can their
 * recent contributions etc.
 *
 */
 
// must be run within DokuWiki
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_mypage extends DokuWiki_Action_Plugin {
 
    /**
     * return some info
     */
    function getInfo() {
        return array(
            'author' => 'Viktor Söderqvist',
            'email'  => 'viktor@zuiderkwast.se',
            'date'   => '2009-09-26',
            'name'   => 'Mypage Plugin',
            'desc'   => 'Provides an new action that shows a user page, generated '.
                        'from a template, where users can their recent contributions etc',
            'url'    => 'http://www.dokuwiki.org/plugin:mypage',
        );
    }
 
    /**
     * register the eventhandlers
     */
    function register(&$contr) {
        $contr->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'handleTplActUnknown');
        $contr->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActPreprocess');
    }
 
    /**
     * Hook for event ACTION_ACT_PREPROCESS, action 'mypage'. Just accepts the action.
     */
    function handleActPreprocess(&$event, $param) {
        $act = $event->data;
        if (is_array($act))
            list($act) = array_keys($act);
 
        if ($act != 'mypage')
            return; // Not handled here
 
        if (empty($_SERVER['REMOTE_USER'])) {
            $event->data = 'login';
            return; // Not logged in
        }
 
        // Accept the action
        $event->preventDefault();
        $event->stopPropagation();
    }
 
    /**
     * Hook for event TPL_ACT_UNKNOWN, action 'mypage'
     * Show the page "My page"
     */
    function handleTplActUnknown(&$event, $param) {
        if ($event->data == 'mypage') {
            $event->preventDefault();
            $event->stopPropagation();
            // get wikitext
            $wikitext = $this->_getMypageWikitext();
            // parse and render. TODO: cache
            $ret = p_render('xhtml',p_get_instructions($wikitext),$info);
            echo $ret;
        }
    }
 
    function _getMypageWikitext() {
        global $conf, $INFO;
        // Is there a localized mypage template?
        $namespaces = array($conf['lang'], '');
        $filenames = array('_mypage.txt', 'mypagetemplate.txt');
        $file = null;
        foreach ($namespaces as $ns) {
            $dir = dirname(wikiFN($ns.':'.'dummy'));
            foreach ($filenames as $filename) {
                if (@file_exists($dir.'/'.$filename)) {
                    $file = $dir.'/'.$filename; // OK!
                    break 2;
                }
            }
        }
        if ($file) {
            $tpl = io_readFile($file);
        }
        else {
            msg('My Page template not found (_mypage.txt or mypagetemplate.txt)');
            $tpl = "====== My page example ======\n".
                   "@NAME@ <@MAIL@> (@USER@) @DATE@";
        }
        $tpl = str_replace(
            array(
                '@NS@',
                '@USER@',
                '@NAME@',
                '@MAIL@',
                '@DATE@',
             ),
             array(
                 $ns,
                 //utf8_ucfirst($page),
                 //utf8_ucwords($page),
                 //utf8_strtoupper($page),
                 $_SERVER['REMOTE_USER'],
                 $INFO['userinfo']['name'],
                 $INFO['userinfo']['mail'],
                 $conf['dformat'],
             ),
             $tpl);
 
        // we need the callback to work around strftime's char limit
        $tpl = preg_replace('/%./e','strftime($0)',$tpl);
        return $tpl;
    }
}
// vim:ts=4:sw=4:et:enc=utf-8:

Bugs

Comments

plugin/mypage.txt · Last modified: 2011/04/23 01:49 by 213.112.161.53
 
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