Extension:Login At Edit/LoginAtEdit.php

<?php


 * 1) Login At Edit Extension for MediaWiki, version 0.1
 * 2) Copyright 2006 Evan Miller


 * 1) This extension integrates a login form into the Edit form,
 * 2) so you can provide your log in credentials at the same time
 * 3) you submit a page edit.


 * 1) THIS EXTENSION IS A TOTAL HACK. IT MAY BREAK SOMETHING UNEXPECTED.
 * 2) DO NOT USE UNLESS YOU ARE WILLING TO CONTRACT DIPHTHERIA.

$wgHooks['EditFilter'][] = 'loginAtEdit_CheckCredentials'; $wgHooks['EditPage::showEditForm:initial'][] = 'loginAtEdit_InsertLoginForm';


 * 1) This method was ripped off of processLogin of SpecialUserlogin.php,
 * 2) replacing notices straight to wgOut.

function loginAtEdit_CheckCredentials($form, $textbox, $section) { global $wgUser, $wgAuth, $wgReservedUsernames, $wgOut, $wgDisableCookieCheck; if ($wgUser->isLoggedIn) { return true; }   $name = $form->editintro; $pass = $form->textbox2; if ( '' == $name ) { $wgOut->setPageTitle( "Log in problem" ); $wgOut->addWikiText( wfMsg( 'noname' ) ); return false; }   $u = User::newFromName( $name ); if( is_null( $u ) || in_array( $u->getName, $wgReservedUsernames ) ) { $wgOut->setPageTitle( "Log in problem" ); $wgOut->addWikiText( wfMsg( 'noname' ) ); return false; }   if ( 0 == $u->getID ) { /**   * If the external authentication plugin allows it, * automatically create a new account for users that * are externally defined but have not yet logged in. */   if ( $wgAuth->autoCreate && $wgAuth->userExists( $u->getName ) ) { if ( $wgAuth->authenticate( $u->getName, $pass ) ) { $u =& $this->initUser( $u ); } else { $wgOut->setPageTitle( "Log in problem" ); $wgOut->addWikiText( wfMsg( 'wrongpassword' ) ); return false; }   } else { $wgOut->setPageTitle( "Log in problem" ); $wgOut->addWikiText( wfMsg( 'nosuchuser', $u->getName ) ); return false; }   } else { $u->loadFromDatabase; }

if (!$u->checkPassword( $pass )) { $wgOut->setPageTitle( "Log in problem" ); $wgOut->addWikiText( wfMsg( $pass == '' ? 'wrongpasswordempty' : 'wrongpassword' ) ); return false; }

# We've verified now, update the real record #   $r = 0; # Maybe we can pack in the "Remember me" too? /*   if ( $this->mRemember ) { $r = 1; } else { $r = 0; }   */    $u->setOption( 'rememberpassword', $r );

$wgAuth->updateUser( $u );

$wgUser = $u; $wgUser->setCookies;

$wgUser->saveSettings;

if( !$wgDisableCookieCheck && !isset( $_COOKIE[session_name] ) ) { $wgOut->setPageTitle( "Log in problem" ); $wgOut->addWikiText("Please make sure cookies are enabled in your browser"); return false; }    return true; }

function loginAtEdit_InsertLoginForm($form) { global $wgOut, $wgUser;

if ($wgUser->isLoggedIn) { return; }

$output = << END; $wgOut->addHTML($output); return true; }

?>