<?php
$wgExtensionFunctions[] = "wfDragonflyModule";
$wgHooks['GetLocalURL'][] = 'fnLinkHook' ;
$wgHooks['OutputPageBeforeHTML'][] = 'fnHeaderHook';
$wgHooks['ParserAfterTidy'][] = 'fnHeaderHook';
$wgHooks['AutoAuthenticate'][] = 'fnAuthServerMagic';
$wgHooks['SpecialPageExecuteBeforeHeader'][] = 'fnHeaderHook';
function wfDragonflyModule() {
global $wgSpecialPages;
//even if the login/logout buttons are displayed, they won't work from now on
unset($wgSpecialPages["Userlogin"]);
unset($wgSpecialPages["Userlogout"]);
}
/** this little function handles the rewriting of links inside the wiki. If you mess up the wiki settings concerning the lin
ks (prettying urls etc) in LocalSettings.php, these rules might not work, so beware! */
function fnLinkHook(&$title, &$url, $query) {
$url = str_replace("index.php?", "index.php?name=MediaWiki&", $url);
$url = str_replace("index.php/", "index.php?name=MediaWiki&title=", $url);
}
/** this function has two task: include in the head section of the page the necessery wiki css and js links, and second, out
put the Dragonfly header before the wiki module. The hardcoded header style and js links are ugly, should modify it somehow
in the future. */
function fnHeaderHook($parserOutput, $text) {
if (!defined('CPG_NUKE')) {
exit;
}
global $pagetitle, $modheader;
$pagetitle .= _MEDIAWIKI;
$modheader .= '<link rel="stylesheet" type="text/css" href="modules/MediaWiki/skins/dragonfly/main.css" />';
$modheader .= '<script type="text/javascript" src="modules/MediaWiki/skins/common/wikibits.js"></script>';
require_once("header.php");
}
/** As we disabled the login/logout when this extension is installed, we need to do these manually. The redirect link is never executes, just leaved it there for future modification. Some problems: passwords are not imported. So if converting the module back to standalone, you will have the users in the database, but noone can log in. More important issue: case sensitiv
ity and weird characters in username. These can cause serious headache, need further investigation. */
function fnAuthServerMagic(&$user) {
global $userinfo;
if (is_user()) {
$username = $userinfo['username'];
$realname = $userinfo['name'];
$useremail = $userinfo['user_email'];
} else return false;
session_start();
if ($username=="") {
header('Location: https://go.there.and/login.php?back='.$enc);
exit();
}
/* if a user is not present in wiki database, it will be created. If the user was present, then his settings WON'T b
e updated! The key for the identification is the username. If a user has mediawiki module admin rights, he will get admin ri
ghts in wiki. */
$user = User::newFromName($username);
if ($user->getID()==0) {
$user->addToDatabase();
$user->setEmail($useremail);
$user->setRealName($realname);
$user->setToken();
$user->saveSettings();
} else {
$user->loadFromDatabase();
}
if (can_admin('mediawiki')) {
$user->addGroup('sysop');
$user->addGroup('bureaucrat');
}
return true;
}
?> |