User:Gizmhail/NewUserDefaultPage

Purpose
This extension creates a user page for an user when he logs in if he had no user page before

Code
Note : some "." unneeded characters are only here to bypass limitations of code storage on this page  * @copyright Copyright (C) 2008 Sebastien Poivre * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */

if (!defined('MEDIAWIKI')) die('Not an entry point.');

$wgExtensionFunctions[] = 'wfNewUserDefaultPage_Setup';

$wgExtensionCredits['other'][] = array(       'name'           => 'NewUserDefaultPage',        'author' =>  'Orange Labs (Sebastien Poivre)',        'url' => 'http://www.mediawiki.org/wiki/User:Gizmhail/NewUserDefaultPage',        'description' => "Add a defaut page content to newly created user's talk pages. Inspired by NewUserMessage extension]. Needs ParserFunctions extension for default tempalte to function.",        'version' => 0.1 );

function wfNewUserDefaultPage_Setup { global $wgHooks, $wgMessageCache,$wgNewUserDefaultPageTemplate; $defaultPagetemplate = "NewUserDefaultPage"; $wgNewUserDefaultPageTemplate = "MediaWiki:$defaultPagetemplate"; $wgMessageCache->addMessage( 'newUserDefaultPage',"== {"."{#if:{"."{"."{realname|}"."}"."}|{"."{"."{realname}}}|{"."{#if:{"."{"."{name|}"."}"."}|{"."{"."{name}"."}"."}|User name}"."}"."}"."} ==\n"               ."* email: {"."{"."{email|Not known}"."}"."}\n"                ."* registration date: {{#time:j F Y - G:H|{"."{"."{registration}"."}"."}"."}"."}"); $wgHooks['UserLoginComplete'][] = 'wfNewUserPage_UserLoginComplete'; }

function wfNewUserPage_UserLoginComplete($user) { global $wgNewUserDefaultPageTemplate;

$name = $user->getName; $realname = $user->getRealName; $email = $user->getEmail; $registration = $user->getRegistration; $userPage = $user->getUserPage;

if (!$user->isAnon&&$userPage&&!$userPage->exists) { $article = new Article($userPage); $summary = "New user page automatic creation."; $text = '{'.'{'."$wgNewUserDefaultPageTemplate\n" ."|name=$name\n" ."|realname=$realname\n" ."|email=$email\n" ."|registration=$registration\n" ."}}";               //Section similar to $article->insertNewArticle function call, but without the redirection $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY; $article->doEdit( $text, $summary, $flags );

$dbw = wfGetDB( DB_MASTER ); if (!$article->mTitle->userIsWatching) { $dbw->begin; $article->doWatch; $dbw->commit; }       }        return true; }