User:Austin J. Che/Extensions/UserDefaultPage

From OpenWetWare

Jump to: navigation, search

UserDefaultPage

This extension uses PreferencesExtension to add one option to the user preferences under the Misc tab. The "Default main page" allows the user to enter a page title to be used as the default page. Normally, when the wiki url is entered without any specific page entered, the url redirects automatically to Main_Page. By entering a value for this preference, the user will instead be redirected to the given page.

Source

<?php
 
/**
 * This extension allows a user to change the default page to go to
 * when accessing the wiki without a specified page (instead of the default "Main Page")
 *
 * Isn't very useful without the PreferencesExtension installed
 *
 * Author: Austin Che <http://openwetware.org/wiki/User:Austin>
 */
 
$wgExtensionFunctions[] = "wfExtensionUserDefaultPage";
$wgExtensionCredits['other'][] = array(
    'name' => 'UserDefaultPage',
    'version' => '2006/03/10',
    'author' => 'Austin Che',
    'url' => 'http://openwetware.org/wiki/User:Austin_J._Che/Extensions/UserDefaultPage',
    'description' => 'Change the default main page for a user',
);
 
function wfExtensionUserDefaultPage() 
{
    global $wgMessageCache, $wgUser, $wgRequest;
    $wgMessageCache->addMessages(array('defaultpage' => 'Default main page'));
 
    // use the preferences extension only if it has been loaded
    if (function_exists("wfAddPreferences"))
    {
        wfAddPreferences(array(array('name' => "defaultpage",
                                     'section' => "prefs-misc",
                                     'type' => PREF_TEXT_T,
                                     'size' => 25)));
    }
 
    // check if no title is provided and if the user has a default page specified
    if ($wgRequest->getVal('title') == '' && $wgUser->getOption("defaultpage") != '')
    {
        // if so, we set $_REQUEST['title'] only (don't set $_GET['title'])
        // when index.php calls $wgRequest->getVal('title') it'll return this page
        // however it then checks $_GET['title'] is empty so then redirects to this page
        // which is the behavior that we want
        $wgRequest->data['Title'] = $wgUser->getOption("defaultpage");
    }
}
 
?>
 

Send bugs and comments to Austin Che. Other extensions including sources can be found at User:Austin J. Che/Extensions.

Personal tools