1 of 1 found this page helpful

Augment special page functionality with PHP

    Requirements

    MindTouch with PHP plugin support > Lyons

    Tutorial

    Get familiar with plugins

    Browse your local MindTouch filesystem and find the plugin directory:

    {dekiroot}/deki/plugins

    Special page plugins are located at:

    {dekiroot}/deki/plugins/special_page

    You can see how plugins are loaded and the available hooks in the deki_plugin.php file:

    {dekiroot}/deki/plugins/deki_plugin.php

    Name your plugin

    One of the requirements for PHP plugins is that the folder and PHP file have the same name. The UI naming conventions for files are:

    • lowercase
    • no spaces
    • no dashes
    • underscores are okay

    Let's name our plugin:

    special_userregistration_plus

    Create a folder under the special_page folder with the name above and place a PHP file within the folder called:

    special_userregistration_plus.php

    If you're still following, your tree should look like this:

    {dekiroot}/deki/plugins/special_page/special_userregistration_plus
    {dekiroot}/deki/plugins/special_page/special_userregistration_plus/special_userregistration_plus.php

    Make it work

    MindTouch ships with safe-mode/explicit plugin loading. This means you'll have to either turn this functionality off or tell MindTouch about your new plugin.

    Option 1

    Whitelist the new special plugin:

    $wgDekiSpecialPages[] = 'special_userregistration_plus'; // the name of the plugin, not the PHP file

    Note: if you are attempting to load a non-special page plugin, then use this to whitelist:

    $wgDekiPlugins[] = 'my_plugin_name';

    Option 2

    Turn off whitelisting (not recommended for live sites):

    $wgDekiPluginMode = 'directory';

    Now we have a blank PHP file that will get loaded when a Special: request is made. Interesting but not useful. Let's put your plugin to work.

    Make me a sandwich

    Without explaining everything in detail, simply paste this into your special_userregistraion_plug.php file:

    <?php
    if (defined('MINDTOUCH_DEKI')) :
    DekiPlugin::registerHook(Hooks::SPECIAL_USER_REGISTRATION, 'wfSpecialUserRegistrationPlus', 10);
    
    function wfSpecialUserRegistrationPlus($pageName, &$pageTitle, &$html, &$subhtml)
    {
    	$html = '<p>Content is BEFORE the default registration info</p>' . $html;
    	$html .= '<p>Content is AFTER the default registration info</p>';
    }
    
    endif;

    Now visit http://{YOURWIKI}/Special:UserRegistration and notice where text was injected on the registration page. (You'll need to allow anonymous registrations for this page to load.)

    If you want to include custom CSS, then use the following code and make sure you have a mycustom.css file located in the plugin directory along with the special_userregistration_plus.php file. You can name the custom css file whatever you like but make sure the code references the correct file.

    <?php
    if (defined('MINDTOUCH_DEKI')) :
    DekiPlugin::registerHook(Hooks::SPECIAL_USER_REGISTRATION, array('SpecialUserRegistrationPlus', 'hook'), 10);
    
    class SpecialUserRegistrationPlus extends SpecialPagePlugin
    {
    	public static function hook($pageName, &$pageTitle, &$html, &$subhtml)
    	{
    		$Special = new self($pageName, basename(__FILE__, '.php'));
    		$Special->includeSpecialCss('mycustom.css');
    
    		$html = '<p>Content is BEFORE the default registration info</p>' . $html;
    		$html .= '<p>Content is AFTER the default registration info</p>';
    	}
    }
    endif;

    Combining these two approaches can allow you to augment the functionality or even the look and feel of any special page.

    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by