From 549d49951e615b45e143e71909c44a08ed170338 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 1 Apr 2004 13:03:05 +0000 Subject: [PATCH] Refactored (object-orientified) to make them play nice with $wgRequest --- includes/SpecialMakesysop.php | 96 ++-- includes/SpecialPreferences.php | 736 +++++++++++++++--------------- includes/SpecialRecentchanges.php | 32 +- includes/SpecialUndelete.php | 265 ++++++----- includes/SpecialUserlogin.php | 714 +++++++++++++++-------------- 5 files changed, 945 insertions(+), 898 deletions(-) diff --git a/includes/SpecialMakesysop.php b/includes/SpecialMakesysop.php index f1346e086f..d08a1bbf52 100644 --- a/includes/SpecialMakesysop.php +++ b/includes/SpecialMakesysop.php @@ -3,7 +3,7 @@ include_once( "LinksUpdate.php" ); function wfSpecialMakesysop() { - global $wgUser, $wgOut, $action, $target; + global $wgUser, $wgOut, $wgRequest; if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) { $wgOut->errorpage( "movenologin", "movenologintext" ); @@ -13,26 +13,36 @@ function wfSpecialMakesysop() $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" ); return; } - + if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } - $f = new MakesysopForm(); + $f = new MakesysopForm( $wgRequest ); - if ( $_POST['wpMakesysopSubmit'] ) { + if ( $f->mSubmit ) { $f->doSubmit(); } else { $f->showForm( "" ); } } -class MakesysopForm { +class MakesysopForm { + var $mTarget, $mAction, $mRights, $mUser, $mSubmit; + + function MakesysopForm( &$request ) + { + $this->mAction = $request->getText( 'action' ); + $this->mRights = $request->getVal( 'wpRights' ); + $this->mUser = $request->getText( 'wpMakesysopUser' ); + $this->mSubmit = $request->getBool( 'wpMakesysopSubmit' ) && $request->wasPosted(); + $this->mBuro = $request->getBool( 'wpSetBureaucrat' ); + } + function showForm( $err = "") { global $wgOut, $wgUser, $wgLang; - global $wpNewTitle, $wpOldTitle, $wpMovetalk, $target, $wpRights, $wpMakesysopUser; if ( $wgUser->isDeveloper() ) { $wgOut->setPageTitle( wfMsg( "set_user_rights" ) ); @@ -50,8 +60,8 @@ class MakesysopForm { $wgOut->addHTML( "

{$err}\n" ); } $namedesc = wfMsg( "makesysopname" ); - if ( isset( $wpMakesysopUser ) ) { - $encUser = htmlspecialchars( $wpMakesysopUser ); + if ( !is_null( $this->mUser ) ) { + $encUser = htmlspecialchars( $this->mUser ); } else { $encUser = ""; } @@ -78,8 +88,8 @@ class MakesysopForm { if ( $wgUser->isDeveloper() ) { $rights = wfMsg( "rights" ); - if ( isset( $wpRights ) ) { - $encRights = htmlspecialchars( $wpRights ); + if ( !is_null( $this->mRights ) ) { + $encRights = htmlspecialchars( $this->mRights ); } else { $encRights = "sysop"; } @@ -111,13 +121,12 @@ class MakesysopForm { function doSubmit() { + global $wgOut, $wgUser, $wgLang; + global $wgDBname, $wgMemc, $wgLocalDatabases; - global $wgOut, $wgUser, $wgLang, $wpMakesysopUser, $wpSetBureaucrat; - global $wgDBname, $wgMemc, $wpRights, $wgLocalDatabases; - - $parts = explode( "@", $wpMakesysopUser ); + $parts = explode( "@", $this->mUser ); if( count( $parts ) == 2 && $wgUser->isDeveloper() ){ - $username = $parts[0]; + $username = wfStrencode( $parts[0] ); if ( array_key_exists( $parts[1], $wgLocalDatabases ) ) { $dbName = $wgLocalDatabases[$parts[1]]; $usertable = $dbName . ".user"; @@ -126,7 +135,7 @@ class MakesysopForm { return; } } else { - $username = $wpMakesysopUser; + $username = wfStrencode( $this->mUser ); $usertable = "user"; $dbName = $wgDBname; } @@ -135,39 +144,8 @@ class MakesysopForm { $sql = "SELECT user_id,user_rights FROM $usertable WHERE user_id=$id"; } else { $encName = wfStrencode( $username ); - $sql = "SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$encName}'"; - } - - $prev = wfIgnoreSQLErrors( TRUE ); - $res = wfQuery( $sql, DB_WRITE); - wfIgnoreSQLErrors( $prev ); - - global $wgOut, $wgUser, $wgLang, $wpMakesysopUser, $wpSetBureaucrat; - global $wgDBname, $wgMemc, $wpRights, $wgLocalDatabases; - - $parts = explode( "@", $wpMakesysopUser ); - if( count( $parts ) == 2 && $wgUser->isDeveloper() ){ - $username = wfStrencode( $parts[0] ); - if ( array_key_exists( $parts[1], $wgLocalDatabases ) ) { - $dbName = $wgLocalDatabases[$parts[1]]; - $usertable = $dbName . ".user"; - } else { - $this->showFail(); - return; - } - } else { - $username = wfStrencode( $wpMakesysopUser ); - $usertable = "user"; - $dbName = $wgDBname; + $sql = "SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$username}'"; } - if ( $username{0} == "#" ) { - $id = intval( substr( $username, 1 ) ); - $sql = "SELECT user_id,user_rights FROM $usertable WHERE user_id=$id"; - } else { - $encName = wfStrencode( $username ); - $sql = "SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$username}'"; - } - $prev = wfIgnoreSQLErrors( TRUE ); $res = wfQuery("SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$username}'", DB_WRITE); @@ -183,8 +161,8 @@ class MakesysopForm { $rightsNotation = array(); if ( $wgUser->isDeveloper() ) { - $newrights = (string)$wpRights; - $rightsNotation[] = "=$wpRights"; + $newrights = (string)$this->mRights; + $rightsNotation[] = "=$this->mRights"; } else { if( $row->user_rights ){ $rights = explode(",", $row->user_rights ); @@ -192,7 +170,7 @@ class MakesysopForm { $rights[] = "sysop"; $rightsNotation[] = "+sysop "; } - if ( $wpSetBureaucrat && !in_array( "bureaucrat", $rights ) ) { + if ( $this->mBuro && !in_array( "bureaucrat", $rights ) ) { $rights[] = "bureaucrat"; $rightsNotation[] = "+bureaucrat "; } @@ -200,7 +178,7 @@ class MakesysopForm { } else { $newrights = "sysop"; $rightsNotation[] = "+sysop"; - if ( $wpSetBureaucrat ) { + if ( $this->mBuro ) { $rightsNotation[] = "+bureaucrat"; $newrights .= ",bureaucrat"; } @@ -215,7 +193,7 @@ class MakesysopForm { $wgMemc->delete( "$dbName:user:id:$id" ); $bureaucratLog = wfMsg( "bureaucratlog" ); - $action = wfMsg( "bureaucratlogentry", $wpMakesysopUser, implode( " ", $rightsNotation ) ); + $action = wfMsg( "bureaucratlogentry", $this->mUser, implode( " ", $rightsNotation ) ); $log = new LogPage( $bureaucratLog ); $log->addEntry( $action, "" ); @@ -226,14 +204,14 @@ class MakesysopForm { function showSuccess() { - global $wgOut, $wpMakesysopUser, $wgUser; + global $wgOut, $wgUser; $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) ); if ( $wgUser->isDeveloper() ) { - $text = wfMsg( "user_rights_set", $wpMakesysopUser ); + $text = wfMsg( "user_rights_set", $this->mUser ); } else { - $text = wfMsg( "makesysopok", $wpMakesysopUser ); + $text = wfMsg( "makesysopok", $this->mUser ); } $text .= "\n\n"; $wgOut->addWikiText( $text ); @@ -243,13 +221,13 @@ class MakesysopForm { function showFail() { - global $wgOut, $wpMakesysopUser, $wgUser; + global $wgOut, $wgUser; $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) ); if ( $wgUser->isDeveloper() ) { - $this->showForm( wfMsg( "set_rights_fail", $wpMakesysopUser ) ); + $this->showForm( wfMsg( "set_rights_fail", $this->mUser ) ); } else { - $this->showForm( wfMsg( "makesysopfail", $wpMakesysopUser ) ); + $this->showForm( wfMsg( "makesysopfail", $this->mUser ) ); } } } diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index 26d202a197..20053c290f 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -2,402 +2,426 @@ function wfSpecialPreferences() { - global $wgUser, $wgOut, $wgUseDynamicDates, $action; - global $wpSaveprefs, $wpReset, $wgRequest; - - # EWWWWWW temp hack - global $wpOldpass, $wpNewpass, $wpRetypePass, $wpNick, $wpUserEmail; - $wpOldpass = $wgRequest->getText( 'wpOldpass' ); - $wpNewpass = $wgRequest->getText( 'wpNewpass' ); - $wpRetypePass = $wgRequest->getText( 'wpRetypePass' ); - $wpNick = $wgRequest->getText( 'wpNick' ); - $wpUserEmail = $wgRequest->getVal( 'wpUserEmail' ); - - if ( 0 == $wgUser->getID() ) { - $wgOut->errorpage( "prefsnologin", "prefsnologintext" ); - return; - } - if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; - } - if ( isset( $wpReset ) ) { - resetPrefs(); - mainPrefsForm( WfMsg( "prefsreset" ) ); - } else if ( isset( $_POST['wpSaveprefs'] ) ) { - savePreferences(); - } else { - resetPrefs(); - mainPrefsForm( "" ); - } -} + global $wgRequest; -/* private */ function validateInt( &$val, $min=0, $max=0x7fffffff ) { - $val = intval($val); - $val = min($val, $max); - $val = max($val, $min); - return $val; + $form = new PreferencesForm( $wgRequest ); + $form->execute(); } -/* private */ function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) { - $val = trim($val); - if($val === "") { - return $val; - } else { - return validateInt( $val, $min, $max ); +class PreferencesForm { + var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs; + var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick; + var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction; + var $mReset, $mPosted, $mToggles, $mSearchNs; + + function PreferencesForm( &$request ) { + global $wgLang; + + $this->mQuickbar = $request->getVal( 'wpQuickbar' ); + $this->mOldpass = $request->getVal( 'wpOldpass' ); + $this->mNewpass = $request->getVal( 'wpNewpass' ); + $this->mRetypePass =$request->getVal( 'wpRetypePass' ); + $this->mStubs = $request->getVal( 'wpStubs' ); + $this->mRows = $request->getVal( 'wpRows' ); + $this->mCols = $request->getVal( 'wpCols' ); + $this->mSkin = $request->getVal( 'wpSkin' ); + $this->mMath = $request->getVal( 'wpMath' ); + $this->mDate = $request->getVal( 'wpDate' ); + $this->mUserEmail = $request->getVal( 'wpUserEmail' ); + $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 1 : 0; + $this->mNick = $request->getVal( 'wpNick' ); + $this->mSearch = $request->getVal( 'wpSearch' ); + $this->mRecent = $request->getVal( 'wpRecent' ); + $this->mHourDiff = $request->getVal( 'wpHourDiff' ); + $this->mSearchLines = $request->getVal( 'wpSearchLines' ); + $this->mSearchChars = $request->getVal( 'wpSearchChars' ); + $this->mAction = $request->getVal( 'action' ); + $this->mReset = $request->getCheck( 'wpReset' ); + $this->mPosted = $request->wasPosted(); + $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) && $this->mPosted; + + # User toggles (the big ugly unsorted list of checkboxes) + $this->mToggles = array(); + if ( $this->mPosted ) { + $togs = $wgLang->getUserToggles(); + foreach ( $togs as $tname => $ttext ) { + $this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0; + } + } + + # Search namespace options + # Note: namespaces don't necessarily have consecutive keys + $this->mSearchNs = array(); + if ( $this->mPosted ) { + $namespaces = $wgLang->getNamespaces(); + foreach ( $namespaces as $i => $namespace ) { + if ( $i >= 0 ) { + $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0; + } + } + } } -} - -/* private */ function validateCheckbox( $cb ) -{ - if ( $cb ) - { - return 1; + function execute() { + global $wgUser, $wgOut, $wgUseDynamicDates; + + if ( 0 == $wgUser->getID() ) { + $wgOut->errorpage( "prefsnologin", "prefsnologintext" ); + return; + } + if ( wfReadOnly() ) { + $wgOut->readOnlyPage(); + return; + } + if ( $this->mReset ) { + $this->resetPrefs(); + $this->mainPrefsForm( wfMsg( "prefsreset" ) ); + } else if ( $this->mSaveprefs ) { + $this->savePreferences(); + } else { + $this->resetPrefs(); + $this->mainPrefsForm( "" ); + } } - else - { - return 0; + + /* private */ function validateInt( &$val, $min=0, $max=0x7fffffff ) { + $val = intval($val); + $val = min($val, $max); + $val = max($val, $min); + return $val; } -} -/* private */ function validateTimeZone( $s ) -{ - - if ( $s !== "" ) { - if ( strpos( $s, ":" ) ) { - # HH:MM - $array = explode( ":" , $s ); - $hour = intval( $array[0] ); - $minute = intval( $array[1] ); + /* private */ function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) { + $val = trim($val); + if($val === "") { + return $val; } else { - $minute = intval( $s * 60 ); - $hour = intval( $minute / 60 ); - $minute = abs( $minute ) % 60; + return $this->validateInt( $val, $min, $max ); } - $hour = min( $hour, 15 ); - $hour = max( $hour, -15 ); - $minute = min( $minute, 59 ); - $minute = max( $minute, 0 ); - $s = sprintf( "%02d:%02d", $hour, $minute ); } - return $s; -} -/* private */ function savePreferences() -{ - global $wgUser, $wgLang, $wgDeferredUpdateList; - global $wpQuickbar, $wpOldpass, $wpNewpass, $wpRetypePass; - global $wpSkin, $wpMath, $wpDate, $wpUserEmail, $wpEmailFlag, $wpNick, $wpSearch, $wpRecent; - global $wpSearchLines, $wpSearchChars, $wpStubs; - global $wpRows, $wpCols, $wpHourDiff; - - if ( "" != $wpNewpass ) { - if ( $wpNewpass != $wpRetypePass ) { - mainPrefsForm( wfMsg( "badretype" ) ); - return; + /* private */ function validateTimeZone( $s ) + { + + if ( $s !== "" ) { + if ( strpos( $s, ":" ) ) { + # HH:MM + $array = explode( ":" , $s ); + $hour = intval( $array[0] ); + $minute = intval( $array[1] ); + } else { + $minute = intval( $s * 60 ); + $hour = intval( $minute / 60 ); + $minute = abs( $minute ) % 60; + } + $hour = min( $hour, 15 ); + $hour = max( $hour, -15 ); + $minute = min( $minute, 59 ); + $minute = max( $minute, 0 ); + $s = sprintf( "%02d:%02d", $hour, $minute ); } - $ep = $wgUser->encryptPassword( $wpOldpass ); - if ( $ep != $wgUser->getPassword() ) { - if ( $ep != $wgUser->getNewpassword() ) { - mainPrefsForm( wfMsg( "wrongpassword" ) ); + return $s; + } + + /* private */ function savePreferences() + { + global $wgUser, $wgLang, $wgDeferredUpdateList; + + if ( "" != $this->mNewpass ) { + if ( $this->mNewpass != $this->mRetypePass ) { + $this->mainPrefsForm( wfMsg( "badretype" ) ); return; } + $ep = $wgUser->encryptPassword( $this->mOldpass ); + if ( $ep != $wgUser->getPassword() ) { + if ( $ep != $wgUser->getNewpassword() ) { + $this->mainPrefsForm( wfMsg( "wrongpassword" ) ); + return; + } + } + $wgUser->setPassword( $this->mNewpass ); } - $wgUser->setPassword( $wpNewpass ); - } - $wgUser->setEmail( $wpUserEmail ); - $wgUser->setOption( "nickname", $wpNick ); - $wgUser->setOption( "quickbar", $wpQuickbar ); - $wgUser->setOption( "skin", $wpSkin ); - $wgUser->setOption( "math", $wpMath ); - $wgUser->setOption( "date", $wpDate ); - $wgUser->setOption( "searchlimit", validateIntOrNull( $wpSearch ) ); - $wgUser->setOption( "contextlines", validateIntOrNull( $wpSearchLines ) ); - $wgUser->setOption( "contextchars", validateIntOrNull( $wpSearchChars ) ); - $wgUser->setOption( "rclimit", validateIntOrNull( $wpRecent ) ); - $wgUser->setOption( "rows", validateInt( $wpRows, 4, 1000 ) ); - $wgUser->setOption( "cols", validateInt( $wpCols, 4, 1000 ) ); - $wgUser->setOption( "stubthreshold", validateIntOrNull( $wpStubs ) ); - $wgUser->setOption( "timecorrection", validateTimeZone( $wpHourDiff, -12, 14 ) ); - - $namespaces = $wgLang->getNamespaces(); - # Set search namespace options - # Note: namespaces don't necessarily have consecutive keys - foreach ( $namespaces as $i => $namespaces ) { - if ( $i >= 0 ) { - $nsvar = "wpNs$i"; - global $$nsvar; - $wgUser->setOption( "searchNs{$i}", validateCheckbox( $$nsvar ) ); + $wgUser->setEmail( $this->mUserEmail ); + $wgUser->setOption( "nickname", $this->mNick ); + $wgUser->setOption( "quickbar", $this->mQuickbar ); + $wgUser->setOption( "skin", $this->mSkin ); + $wgUser->setOption( "math", $this->mMath ); + $wgUser->setOption( "date", $this->mDate ); + $wgUser->setOption( "searchlimit", $this->validateIntOrNull( $this->mSearch ) ); + $wgUser->setOption( "contextlines", $this->validateIntOrNull( $this->mSearchLines ) ); + $wgUser->setOption( "contextchars", $this->validateIntOrNull( $this->mSearchChars ) ); + $wgUser->setOption( "rclimit", $this->validateIntOrNull( $this->mRecent ) ); + $wgUser->setOption( "rows", $this->validateInt( $this->mRows, 4, 1000 ) ); + $wgUser->setOption( "cols", $this->validateInt( $this->mCols, 4, 1000 ) ); + $wgUser->setOption( "stubthreshold", $this->validateIntOrNull( $this->mStubs ) ); + $wgUser->setOption( "timecorrection", $this->validateTimeZone( $this->mHourDiff, -12, 14 ) ); + + # Set search namespace options + foreach( $this->mSearchNs as $i => $value ) { + $wgUser->setOption( "searchNs{$i}", $value ); } - } - - $wgUser->setOption( "disablemail", validateCheckbox( $wpEmailFlag ) ); + + $wgUser->setOption( "disablemail", $this->mEmailFlag ); - $togs = $wgLang->getUserToggles(); - foreach ( $togs as $tname => $ttext ) { - if ( array_key_exists( "wpOp$tname", $_POST ) ) { - $wgUser->setOption( $tname, 1 ); - } else { - $wgUser->setOption( $tname, 0 ); + # Set user toggles + foreach ( $this->mToggles as $tname => $tvalue ) { + $wgUser->setOption( $tname, $tvalue ); } + $wgUser->setCookies(); + $up = new UserUpdate(); + array_push( $wgDeferredUpdateList, $up ); + $this->mainPrefsForm( wfMsg( "savedprefs" ) ); } - $wgUser->setCookies(); - $up = new UserUpdate(); - array_push( $wgDeferredUpdateList, $up ); - mainPrefsForm( wfMsg( "savedprefs" ) ); -} -/* private */ function resetPrefs() -{ - global $wgUser, $wgLang; - global $wpQuickbar, $wpOldpass, $wpNewpass, $wpRetypePass, $wpStubs; - global $wpRows, $wpCols, $wpSkin, $wpMath, $wpDate, $wpUserEmail, $wpEmailFlag, $wpNick; - global $wpSearch, $wpRecent; - global $wpHourDiff, $wpSearchLines, $wpSearchChars; - - $wpOldpass = $wpNewpass = $wpRetypePass = ""; - $wpUserEmail = $wgUser->getEmail(); - if ( 1 == $wgUser->getOption( "disablemail" ) ) { $wpEmailFlag = 1; } - else { $wpEmailFlag = 0; } - $wpNick = $wgUser->getOption( "nickname" ); - - $wpQuickbar = $wgUser->getOption( "quickbar" ); - $wpSkin = $wgUser->getOption( "skin" ); - $wpMath = $wgUser->getOption( "math" ); - $wpDate = $wgUser->getOption( "date" ); - $wpRows = $wgUser->getOption( "rows" ); - $wpCols = $wgUser->getOption( "cols" ); - $wpStubs = $wgUser->getOption( "stubthreshold" ); - $wpHourDiff = $wgUser->getOption( "timecorrection" ); - $wpSearch = $wgUser->getOption( "searchlimit" ); - $wpSearchLines = $wgUser->getOption( "contextlines" ); - $wpSearchChars = $wgUser->getOption( "contextchars" ); - $wpRecent = $wgUser->getOption( "rclimit" ); - - $togs = $wgLang->getUserToggles(); - foreach ( $togs as $tname => $ttext ) { - $_POST["wpOp$tname"] = $wgUser->getOption( $tname ); - } -} + /* private */ function resetPrefs() + { + global $wgUser, $wgLang; + + $this->mOldpass = $this->mNewpass = $this->mRetypePass = ""; + $this->mUserEmail = $wgUser->getEmail(); + if ( 1 == $wgUser->getOption( "disablemail" ) ) { $this->mEmailFlag = 1; } + else { $this->mEmailFlag = 0; } + $this->mNick = $wgUser->getOption( "nickname" ); + + $this->mQuickbar = $wgUser->getOption( "quickbar" ); + $this->mSkin = $wgUser->getOption( "skin" ); + $this->mMath = $wgUser->getOption( "math" ); + $this->mDate = $wgUser->getOption( "date" ); + $this->mRows = $wgUser->getOption( "rows" ); + $this->mCols = $wgUser->getOption( "cols" ); + $this->mStubs = $wgUser->getOption( "stubthreshold" ); + $this->mHourDiff = $wgUser->getOption( "timecorrection" ); + $this->mSearch = $wgUser->getOption( "searchlimit" ); + $this->mSearchLines = $wgUser->getOption( "contextlines" ); + $this->mSearchChars = $wgUser->getOption( "contextchars" ); + $this->mRecent = $wgUser->getOption( "rclimit" ); + + $togs = $wgLang->getUserToggles(); + foreach ( $togs as $tname => $ttext ) { + $this->mToggles[$tname] = $wgUser->getOption( $tname ); + } -/* private */ function namespacesCheckboxes() -{ - global $wgLang, $wgUser; - - # Determine namespace checkboxes - $namespaces = $wgLang->getNamespaces(); - $r1 = ""; - - foreach ( $namespaces as $i => $name ) { - # Skip special or anything similar - if ( $i >= 0 ) { - $checked = ""; - if ( $wgUser->getOption( "searchNs$i" ) ) { - $checked = " checked"; - } - $name = str_replace( "_", " ", $namespaces[$i] ); - if ( "" == $name ) { - $name = wfMsg( "blanknamespace" ); + $namespaces = $wgLang->getNamespaces(); + foreach ( $namespaces as $i => $namespace ) { + if ( $i >= 0 ) { + $this->mSearchNs[$i] = $wgUser->getOption( "searchNs$i" ); } + } + } - if ( 0 != $i ) { - $r1 .= " "; + /* private */ function namespacesCheckboxes() + { + global $wgLang, $wgUser; + + # Determine namespace checkboxes + $namespaces = $wgLang->getNamespaces(); + $r1 = ""; + + foreach ( $namespaces as $i => $name ) { + # Skip special or anything similar + if ( $i >= 0 ) { + $checked = ""; + if ( $this->mSearchNs[$i] ) { + $checked = " checked"; + } + $name = str_replace( "_", " ", $namespaces[$i] ); + if ( "" == $name ) { + $name = wfMsg( "blanknamespace" ); + } + + if ( 0 != $i ) { + $r1 .= " "; + } + $r1 .= "\n"; } - $r1 .= "\n"; } + + return $r1; } - - return $r1; -} -/* private */ function mainPrefsForm( $err ) -{ - global $wgUser, $wgOut, $wgLang, $wgUseDynamicDates; - global $wpQuickbar, $wpOldpass, $wpNewpass, $wpRetypePass; - global $wpSkin, $wpMath, $wpDate, $wpUserEmail, $wpEmailFlag, $wpNick, $wpSearch, $wpRecent; - global $wpRows, $wpCols, $wpSaveprefs, $wpReset, $wpHourDiff; - global $wpSearchLines, $wpSearchChars, $wpStubs, $wgValidSkinNames; - - $wgOut->setPageTitle( wfMsg( "preferences" ) ); - $wgOut->setArticleRelated( false ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - - if ( "" != $err ) { - $wgOut->addHTML( "$err\n

" ); - } - $uname = $wgUser->getName(); - $uid = $wgUser->getID(); - - $wgOut->addWikiText( wfMsg( "prefslogintext", $uname, $uid ) ); - - $qbs = $wgLang->getQuickbarSettings(); - $skinNames = $wgLang->getSkinNames(); - $mathopts = $wgLang->getMathNames(); - $dateopts = $wgLang->getDateFormats(); - $togs = $wgLang->getUserToggles(); - - $titleObj = Title::makeTitle( NS_SPECIAL, "Preferences" ); - $action = $titleObj->escapeLocalURL(); - - $qb = wfMsg( "qbsettings" ); - $cp = wfMsg( "changepassword" ); - $sk = wfMsg( "skin" ); - $math = wfMsg( "math" ); - $dateFormat = wfMsg("dateformat"); - $opw = wfMsg( "oldpassword" ); - $npw = wfMsg( "newpassword" ); - $rpw = wfMsg( "retypenew" ); - $svp = wfMsg( "saveprefs" ); - $rsp = wfMsg( "resetprefs" ); - $tbs = wfMsg( "textboxsize" ); - $tbr = wfMsg( "rows" ); - $tbc = wfMsg( "columns" ); - $ltz = wfMsg( "localtime" ); - $tzt = wfMsg( "timezonetext" ); - $tzo = wfMsg( "timezoneoffset" ); - $tzGuess = wfMsg( "guesstimezone" ); - $tzServerTime = wfMsg( "servertime" ); - $yem = wfMsg( "youremail" ); - $emf = wfMsg( "emailflag" ); - $ynn = wfMsg( "yournick" ); - $stt = wfMsg ( "stubthreshold" ) ; - $srh = wfMsg( "searchresultshead" ); - $rpp = wfMsg( "resultsperpage" ); - $scl = wfMsg( "contextlines" ); - $scc = wfMsg( "contextchars" ); - $rcc = wfMsg( "recentchangescount" ); - $dsn = wfMsg( "defaultns" ); - - $wgOut->addHTML( "

\n" ); - - # Skin setting - # - $wgOut->addHTML( "" ); - - # Email, etc. - # - $wpUserEmail = wfEscapeHTML( $wpUserEmail ); - $wpNick = wfEscapeHTML( $wpNick ); - if ( $wpEmailFlag ) { $emfc = "checked"; } - else { $emfc = ""; } - - $ps = namespacesCheckboxes(); - - $wgOut->addHTML( " - - - - - -
$qb:
\n" ); - - # Quickbar setting - # - for ( $i = 0; $i < count( $qbs ); ++$i ) { - if ( $i == $wpQuickbar ) { $checked = " checked"; } - else { $checked = ""; } - $wgOut->addHTML( "
\n" ); - } + /* private */ function mainPrefsForm( $err ) + { + global $wgUser, $wgOut, $wgLang, $wgUseDynamicDates, $wgValidSkinNames; + + $wgOut->setPageTitle( wfMsg( "preferences" ) ); + $wgOut->setArticleRelated( false ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); - # Fields for changing password - # - $wpOldpass = wfEscapeHTML( $wpOldpass ); - $wpNewpass = wfEscapeHTML( $wpNewpass ); - $wpRetypePass = wfEscapeHTML( $wpRetypePass ); - - $wgOut->addHTML( "
$cp:
-
-
-
-
$sk:
\n" ); - # Only show members of $wgValidSkinNames rather than - # $skinNames (skins is all skin names from Language.php) - foreach ($wgValidSkinNames as $skinkey => $skinname ) { - if ( $skinkey == $wpSkin ) { - $checked = ' checked'; - } else { - $checked = ""; + if ( "" != $err ) { + $wgOut->addHTML( "$err\n

" ); + } + $uname = $wgUser->getName(); + $uid = $wgUser->getID(); + + $wgOut->addWikiText( wfMsg( "prefslogintext", $uname, $uid ) ); + + $qbs = $wgLang->getQuickbarSettings(); + $skinNames = $wgLang->getSkinNames(); + $mathopts = $wgLang->getMathNames(); + $dateopts = $wgLang->getDateFormats(); + $togs = $wgLang->getUserToggles(); + + $titleObj = Title::makeTitle( NS_SPECIAL, "Preferences" ); + $action = $titleObj->escapeLocalURL(); + + $qb = wfMsg( "qbsettings" ); + $cp = wfMsg( "changepassword" ); + $sk = wfMsg( "skin" ); + $math = wfMsg( "math" ); + $dateFormat = wfMsg("dateformat"); + $opw = wfMsg( "oldpassword" ); + $npw = wfMsg( "newpassword" ); + $rpw = wfMsg( "retypenew" ); + $svp = wfMsg( "saveprefs" ); + $rsp = wfMsg( "resetprefs" ); + $tbs = wfMsg( "textboxsize" ); + $tbr = wfMsg( "rows" ); + $tbc = wfMsg( "columns" ); + $ltz = wfMsg( "localtime" ); + $tzt = wfMsg( "timezonetext" ); + $tzo = wfMsg( "timezoneoffset" ); + $tzGuess = wfMsg( "guesstimezone" ); + $tzServerTime = wfMsg( "servertime" ); + $yem = wfMsg( "youremail" ); + $emf = wfMsg( "emailflag" ); + $ynn = wfMsg( "yournick" ); + $stt = wfMsg ( "stubthreshold" ) ; + $srh = wfMsg( "searchresultshead" ); + $rpp = wfMsg( "resultsperpage" ); + $scl = wfMsg( "contextlines" ); + $scc = wfMsg( "contextchars" ); + $rcc = wfMsg( "recentchangescount" ); + $dsn = wfMsg( "defaultns" ); + + $wgOut->addHTML( "" ); - - # Math setting - # - $wgOut->addHTML( "" ); - - # Date format - # - if ( $wgUseDynamicDates ) { - $wgOut->addHTML( "" ); + + # Math setting + # + $wgOut->addHTML( "" ); + + # Date format + # + if ( $wgUseDynamicDates ) { + $wgOut->addHTML( ""); } - $wgOut->addHTML( ""); + # Textbox rows, cols + # + $nowlocal = $wgLang->time( $now = wfTimestampNow(), true ); + $nowserver = $wgLang->time( $now, false ); + $wgOut->addHTML( "" ); + + # Email, etc. + # + $this->mUserEmail = wfEscapeHTML( $this->mUserEmail ); + $this->mNick = wfEscapeHTML( $this->mNick ); + if ( $this->mEmailFlag ) { $emfc = "checked"; } + else { $emfc = ""; } + + $ps = $this->namespacesCheckboxes(); + + $wgOut->addHTML( " + + + + + +
$qb:
\n" ); + + # Quickbar setting + # + for ( $i = 0; $i < count( $qbs ); ++$i ) { + if ( $i == $this->mQuickbar ) { $checked = " checked"; } + else { $checked = ""; } + $wgOut->addHTML( "
\n" ); } - $wgOut->addHTML( "
\n" ); - } - # Various checkbox options - # - if ( $wgUseDynamicDates ) { - $wgOut->addHTML( "
\n" ); - } else { - $wgOut->addHTML( "\n" ); - } - $wgOut->addHTML(""); - foreach ( $togs as $tname => $ttext ) { - if ( 1 == $wgUser->getOption( $tname ) ) { - $checked = " checked"; + # Fields for changing password + # + $this->mOldpass = wfEscapeHTML( $this->mOldpass ); + $this->mNewpass = wfEscapeHTML( $this->mNewpass ); + $this->mRetypePass = wfEscapeHTML( $this->mRetypePass ); + + $wgOut->addHTML( "\n" ); + + # Skin setting + # + $wgOut->addHTML( "\n" ); - } - $wgOut->addHTML( "
$cp:
+
+
+
+
$sk:
\n" ); + # Only show members of $wgValidSkinNames rather than + # $skinNames (skins is all skin names from Language.php) + foreach ($wgValidSkinNames as $skinkey => $skinname ) { + if ( $skinkey == $this->mSkin ) { + $checked = ' checked'; + } else { + $checked = ""; + } + $wgOut->addHTML( "
\n" ); + } + + # Various checkbox options + # + if ( $wgUseDynamicDates ) { + $wgOut->addHTML( "
\n" ); } else { - $checked = ""; - } - $wgOut->addHTML( "
$math:
\n" ); - for ( $i = 0; $i < count( $mathopts ); ++$i ) { - if ( $i == $wpMath ) { $checked = " checked"; } - else { $checked = ""; } - $wgOut->addHTML( "
\n" ); - } - $wgOut->addHTML( "
$dateFormat:
" ); - for ( $i = 0; $i < count( $dateopts ); ++$i) { - if ( $i == $wpDate ) { + $wgOut->addHTML( "
\n" ); + } + $wgOut->addHTML(""); + foreach ( $togs as $tname => $ttext ) { + if ( 1 == $wgUser->getOption( $tname ) ) { $checked = " checked"; } else { $checked = ""; + } + $wgOut->addHTML( "\n" ); + } + $wgOut->addHTML( "
$math:
\n" ); + for ( $i = 0; $i < count( $mathopts ); ++$i ) { + if ( $i == $this->mMath ) { $checked = " checked"; } + else { $checked = ""; } + $wgOut->addHTML( "
\n" ); + } + $wgOut->addHTML( "
$dateFormat:
" ); + for ( $i = 0; $i < count( $dateopts ); ++$i) { + if ( $i == $this->mDate ) { + $checked = " checked"; + } else { + $checked = ""; + } + $wgOut->addHTML( "
\n" ); } - $wgOut->addHTML( "
\n" ); + $wgOut->addHTML( "
$tbs:
+
+

+ $tzServerTime: $nowserver
+ $ltz: $nowlocal
+
+ +
+
+
+
+
+
+ {$srh}:
+
+
+
+ $dsn
+ $ps +
* {$tzt} \n" ); } - # Textbox rows, cols - # - $nowlocal = $wgLang->time( $now = wfTimestampNow(), true ); - $nowserver = $wgLang->time( $now, false ); - $wgOut->addHTML( "

$tbs:
-
-

-$tzServerTime: $nowserver
-$ltz: $nowlocal
-
- -
-
-
-
-
-
-{$srh}:
-
-
-
-$dsn
-$ps -
* {$tzt} \n" ); } - ?> diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 0de5ef5192..9cf8adb4e5 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -6,12 +6,24 @@ function wfSpecialRecentchanges( $par ) { global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname; global $wgRequest, $wgSitename, $wgLanguageCode; - global $days, $hideminor, $from, $hidebots, $hideliu; # From query string $fname = "wfSpecialRecentchanges"; + # Get query parameters $feedFormat = $wgRequest->getVal( "feed" ); $feeding = ( $feedFormat == "rss" ); + + $defaultDays = $wgUser->getOption( 'rcdays' ); + if ( !$defaultDays ) { + $defaultDays = 3; + } + + $days = $wgRequest->getInt( 'days', $defaultDays ); + $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0; + $from = $wgRequest->getText( 'from' ); + $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0; + $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0; + # Get query parameters from path if( $par ) { $bits = preg_split( '/\s*,\s*/', trim( $par ) ); if( in_array( "hidebots", $bits ) ) $hidebots = 1; @@ -41,12 +53,7 @@ function wfSpecialRecentchanges( $par ) } $wgOut->addWikiText( $rctext ); - - if ( ! $days ) { - $days = $wgUser->getOption( "rcdays" ); - if ( ! $days ) { $days = 3; } - } - $days = (int)$days; + list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" ); $now = wfTimestampNow(); $cutoff_unixtime = time() - ( $days * 86400 ); @@ -61,27 +68,16 @@ function wfSpecialRecentchanges( $par ) $sk = $wgUser->getSkin(); $showhide = array( wfMsg( "show" ), wfMsg( "hide" )); - if ( ! isset( $hideminor ) ) { - $hideminor = $wgUser->getOption( "hideminor" ); - } - $hideminor = ($hideminor ? 1 : 0); if ( $hideminor ) { $hidem = "AND rc_minor=0"; } else { $hidem = ""; } - if ( !isset( $hidebots ) ) { - $hidebots = 1; - } if( $hidebots ) { $hidem .= " AND rc_bot=0"; } - $hidebots = ($hidebots ? 1 : 0); - if ( !isset( $hideliu ) ) { - $hideliu = 0; - } if ( $hideliu ) { $hidem .= " AND rc_user=0"; } diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index e06c06b9aa..9f2f8e2963 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -2,123 +2,156 @@ function wfSpecialUndelete( $par ) { - global $wgLang, $wgUser, $wgOut, $action, $target, $timestamp, $restore; - - if( $par != "" ) $target = $par; - if( isset($target ) ) { - $t = Title::newFromURL( $target ); - $title = $t->mDbkeyform; - $namespace = $t->mNamespace; - if( isset( $timestamp ) ) { - return doUndeleteShowRevision( $namespace, $title, $timestamp ); - } - if( isset( $action ) and isset( $restore) and $action == "submit" ) { - return doUndeleteArticle( $namespace, $title ); - } - return doUndeleteShowHistory( $namespace, $title ); - } - - # List undeletable articles - $sql = "SELECT ar_namespace,ar_title, COUNT(*) AS count FROM archive GROUP BY ar_namespace,ar_title ORDER BY ar_namespace,ar_title"; - $res = wfQuery( $sql, DB_READ ); - - $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); - $wgOut->addWikiText( wfMsg( "undeletepagetext" ) ); - - $special = $wgLang->getNsText( Namespace::getSpecial() ); - $sk = $wgUser->getSkin(); - $wgOut->addHTML( "\n" ); - - return $ret; -} + global $wgRequest; -/* private */ function doUndeleteShowRevision( $namespace, $title, $timestamp ) { - global $wgLang, $wgUser, $wgOut, $action, $target, $timestamp, $restore; - - if(!preg_match("/[0-9]{14}/",$timestamp)) return 0; - - $sql = "SELECT ar_text,ar_flags FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" AND ar_timestamp={$timestamp}"; - $ret = wfQuery( $sql, DB_READ ); - $row = wfFetchObject( $ret ); - - $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); - $wgOut->addWikiText( "(" . wfMsg( "undeleterevision", $wgLang->date($timestamp, true) ) - . ")\n
\n" . Article::getRevisionText( $row, "ar_" ) ); - - return 0; + $form = new UndeleteForm( $wgRequest, $par ); + $form->execute(); } -/* private */ function doUndeleteShowHistory( $namespace, $title ) { - global $wgLang, $wgUser, $wgOut, $action, $target, $timestamp, $restore; - - $sk = $wgUser->getSkin(); - $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); +class UndeleteForm { + var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj; + + function UndeleteForm( &$request, $par = "" ) { + $this->mAction = $request->getText( 'action' ); + $this->mTarget = $request->getText( 'target' ); + $this->mTimestamp = $request->getText( 'timestamp' ); + $this->mRestore = $request->getCheck( 'restore' ); + if( $par != "" ) { + $this->mTarget = $par; + } + if ( $this->mTarget !== "" ) { + $this->mTargetObj = Title::newFromURL( $this->mTarget ); + } else { + $this->mTargetObj = NULL; + } + } + + function execute() { + if( !is_null( $this->mTargetObj ) ) { + $title = $this->mTargetObj->mDbkeyform; + $namespace = $this->mTargetObj->mNamespace; + if( $this->mTimestamp !== "" ) { + return $this->showRevision( $namespace, $title, $this->mTimestamp ); + } + if( $this->mRestore and $this->mAction == "submit" ) { + return $this->undelete( $namespace, $title ); + } + return $this->showHistory( $namespace, $title ); + } else { + return $this->showList(); + } + } + + /* private */ function showList() { + global $wgLang, $wgUser, $wgOut; + $fname = "UndeleteForm::showList"; + + # List undeletable articles + $sql = "SELECT ar_namespace,ar_title, COUNT(*) AS count FROM archive " . + "GROUP BY ar_namespace,ar_title ORDER BY ar_namespace,ar_title"; + $res = wfQuery( $sql, DB_READ, $fname ); + + $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); + $wgOut->addWikiText( wfMsg( "undeletepagetext" ) ); + + $special = $wgLang->getNsText( Namespace::getSpecial() ); + $sk = $wgUser->getSkin(); + $wgOut->addHTML( "\n" ); + + return 0; + } - # Get text of first revision - $sql = "SELECT ar_text FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" - ORDER BY ar_timestamp DESC LIMIT 1"; - $ret = wfQuery( $sql, DB_READ ); + /* private */ function showRevision( $namespace, $title, $timestamp ) { + global $wgLang, $wgUser, $wgOut; + $fname = "UndeleteForm::showRevision"; + + if(!preg_match("/[0-9]{14}/",$timestamp)) return 0; + + $sql = "SELECT ar_text,ar_flags FROM archive ". + "WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" AND ar_timestamp={$timestamp}"; + $ret = wfQuery( $sql, DB_READ, $fname ); + $row = wfFetchObject( $ret ); + + $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); + $wgOut->addWikiText( "(" . wfMsg( "undeleterevision", $wgLang->date($timestamp, true) ) + . ")\n
\n" . Article::getRevisionText( $row, "ar_" ) ); - if( wfNumRows( $ret ) == 0 ) { - $wgOut->addWikiText( wfMsg( "nohistory" ) ); return 0; } - $row = wfFetchObject( $ret ); - $wgOut->addWikiText( wfMsg( "undeletehistory" ) . "\n
\n" . $row->ar_text ); - - # Get remaining revisions - $sql = "SELECT ar_minor_edit,ar_timestamp,ar_user,ar_user_text,ar_comment - FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" - ORDER BY ar_timestamp DESC"; - $ret = wfQuery( $sql, DB_READ ); - # Ditch first row - $row = wfFetchObject( $ret ); - - $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" ); - $action = $titleObj->escapeLocalURL( "action=submit" ); - $wgOut->addHTML("

-

- - -
"); - - $log = wfGetSQL("cur", "cur_text", "cur_namespace=4 AND cur_title=\"".wfMsg("dellogpage")."\"" ); - if(preg_match("/^(.*". - preg_quote( ($namespace ? ($wgLang->getNsText($namespace) . ":") : "") - . str_replace("_", " ", $title), "/" ).".*)$/m", $log, $m)) { - $wgOut->addWikiText( $m[1] ); - } - - $special = $wgLang->getNsText( Namespace::getSpecial() ); - $wgOut->addHTML(""); - - return 0; -} - -/* private */ function doUndeleteArticle( $namespace, $title ) + + /* private */ function showHistory( $namespace, $title ) { + global $wgLang, $wgUser, $wgOut; + + $sk = $wgUser->getSkin(); + $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); + + # Get text of first revision + $sql = "SELECT ar_text FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" + ORDER BY ar_timestamp DESC LIMIT 1"; + $ret = wfQuery( $sql, DB_READ ); + + if( wfNumRows( $ret ) == 0 ) { + $wgOut->addWikiText( wfMsg( "nohistory" ) ); + return 0; + } + $row = wfFetchObject( $ret ); + $wgOut->addWikiText( wfMsg( "undeletehistory" ) . "\n
\n" . $row->ar_text ); + + # Get remaining revisions + $sql = "SELECT ar_minor_edit,ar_timestamp,ar_user,ar_user_text,ar_comment + FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" + ORDER BY ar_timestamp DESC"; + $ret = wfQuery( $sql, DB_READ ); + # Ditch first row + $row = wfFetchObject( $ret ); + + $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" ); + $action = $titleObj->escapeLocalURL( "action=submit" ); + $encTarget = htmlspecialchars( $this->mTarget ); + + $wgOut->addHTML("

+

+ + +
"); + + $log = wfGetSQL("cur", "cur_text", "cur_namespace=4 AND cur_title=\"".wfMsg("dellogpage")."\"" ); + if(preg_match("/^(.*". + preg_quote( ($namespace ? ($wgLang->getNsText($namespace) . ":") : "") + . str_replace("_", " ", $title), "/" ).".*)$/m", $log, $m)) { + $wgOut->addWikiText( $m[1] ); + } + + $special = $wgLang->getNsText( Namespace::getSpecial() ); + $wgOut->addHTML(""); + + return 0; + } + + /* private */ function undelete( $namespace, $title ) { - global $wgUser, $wgOut, $wgLang, $target, $wgDeferredUpdateList; + global $wgUser, $wgOut, $wgLang, $wgDeferredUpdateList; global $wgUseSquid, $wgInternalServer; $fname = "doUndeleteArticle"; @@ -150,7 +183,7 @@ function wfSpecialUndelete( $par ) "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,{$redir},RAND(),'{$now}' FROM archive " . "WHERE ar_namespace={$namespace} AND ar_title='{$t}' AND ar_timestamp={$max}"; wfQuery( $sql, DB_WRITE, $fname ); - $newid = wfInsertId(); + $newid = wfInsertId(); $oldones = "AND ar_timestamp<{$max}"; } else { # If already exists, put history entirely into old table @@ -172,13 +205,12 @@ function wfSpecialUndelete( $par ) "FROM archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' {$oldones}"; wfQuery( $sql, DB_WRITE, $fname ); - # Finally, clean up the link tables + # Finally, clean up the link tables if( $newid ) { # Create a dummy OutputPage to update the outgoing links # This works at the moment due to good luck. It may stop working in the # future. Damn globals. $dummyOut = new OutputPage(); - $to = Title::newFromDBKey( $target ); $res = wfQuery( "SELECT cur_text FROM cur WHERE cur_id={$newid} " . "AND cur_namespace={$namespace}", DB_READ, $fname ); $row = wfFetchObject( $res ); @@ -186,10 +218,10 @@ function wfSpecialUndelete( $par ) $dummyOut->addWikiText( $text ); wfFreeResult( $res ); - $u = new LinksUpdate( $newid, $to->getPrefixedDBkey() ); + $u = new LinksUpdate( $newid, $this->mTargetObj->getPrefixedDBkey() ); array_push( $wgDeferredUpdateList, $u ); - Article::onArticleCreate( $to ); + Article::onArticleCreate( $this->mTargetObj ); #TODO: SearchUpdate, etc. } @@ -202,9 +234,10 @@ function wfSpecialUndelete( $par ) # Touch the log? $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) ); - $log->addEntry( wfMsg( "undeletedarticle", $target ), "" ); + $log->addEntry( wfMsg( "undeletedarticle", $this->mTarget ), "" ); - $wgOut->addWikiText( wfMsg( "undeletedtext", $target ) ); + $wgOut->addWikiText( wfMsg( "undeletedtext", $this->mTarget ) ); return 0; } +} ?> diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 71d72fde38..75f2db22ed 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -10,423 +10,439 @@ function wfSpecialUserlogin() User::SetupSession(); } - $fields = array( "wpName", "wpPassword", "wpName", - "wpPassword", "wpRetype" ); - # FIXME: UGLY HACK - foreach( $fields as $x ) { - $_REQUEST[$x] = $wgRequest->getText( $x ); - } + $form = new LoginForm( $wgRequest ); + $form->execute(); +} - # When switching accounts, it sucks to get automatically logged out - global $wgLang; - if( $wgRequest->getVal( 'returnto' ) == $wgLang->specialPage( "Userlogout" ) ) { - $_REQUEST['returnto'] = ""; - } +class LoginForm { + var $mName, $mPassword, $mRetype, $mReturnto, $mCookieCheck, $mPosted; + var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword; + var $mLoginattempt, $mRemember, $mEmail; - $wpCookieCheck = $wgRequest->getVal( "wpCookieCheck" ); - - if ( isset( $wpCookieCheck ) ) { - onCookieRedirectCheck( $wpCookieCheck ); - } else if( $wgRequest->wasPosted() ) { - if( $wgRequest->getCheck( 'wpCreateaccount' ) ) { - return addNewAccount(); - } else if ( $wgRequest->getCheck( 'wpCreateaccountMail' ) ) { - return addNewAccountMailPassword(); - } else if ( $wgRequest->getCheck( 'wpMailmypassword' ) ) { - return mailPassword(); - } else if ( "submit" == $wgRequest->getVal( 'action' ) || $wgRequest->getCheck( 'wpLoginattempt' ) ) { - return processLogin(); + function LoginForm( &$request ) { + global $wgLang; + + $this->mName = $request->getText( 'wpName' ); + $this->mPassword = $request->getText( 'wpPassword' ); + $this->mRetype = $request->getText( 'wpRetype' ); + $this->mReturnto = $request->getText( 'returnto' ); + $this->mCookieCheck = $request->getVal( "wpCookieCheck" ); + $this->mPosted = $request->wasPosted(); + $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' ); + $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' ); + $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' ); + $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' ); + $this->mAction = $request->getVal( 'action' ); + $this->mRemember = $request->getCheck( 'wpRemember' ); + $this->mEmail = $request->getText( 'wpEmail' ); + + # When switching accounts, it sucks to get automatically logged out + if( $this->mReturnto == $wgLang->specialPage( "Userlogout" ) ) { + $this->mReturnto = ""; } } - mainLoginForm( "" ); -} - -/* private */ function addNewAccountMailPassword() -{ - global $wgOut; - - if ("" == $_REQUEST['wpEmail']) { - mainLoginForm( wfMsg( "noemail", $_REQUEST['wpName'] ) ); - return; + function execute() { + if ( !is_null( $this->mCookieCheck ) ) { + $this->onCookieRedirectCheck( $this->mCookieCheck ); + } else if( $this->mPosted ) { + if( $this->mCreateaccount ) { + return $this->addNewAccount(); + } else if ( $this->mCreateaccountMail ) { + return $this->addNewAccountMailPassword(); + } else if ( $this->mMailmypassword ) { + return $this->mailPassword(); + } else if ( ( "submit" == $this->mAction ) || $this->mLoginattempt ) { + return $this->processLogin(); + } + } + $this->mainLoginForm( "" ); } - $u = addNewaccountInternal(); + /* private */ function addNewAccountMailPassword() + { + global $wgOut; + + if ("" == $this->mEmail) { + $this->mainLoginForm( wfMsg( "noemail", $this->mName ) ); + return; + } - if ($u == NULL) { - return; - } + $u = $this->addNewaccountInternal(); - $u->saveSettings(); - if (mailPasswordInternal($u) == NULL) { - return; - } + if ($u == NULL) { + return; + } - $wgOut->setPageTitle( wfMsg( "accmailtitle" ) ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->setArticleRelated( false ); + $u->saveSettings(); + $error = $this->mailPasswordInternal($u); - $wgOut->addWikiText( wfMsg( "accmailtext", $u->getName(), $u->getEmail() ) ); - $wgOut->returnToMain( false ); + $wgOut->setPageTitle( wfMsg( "accmailtitle" ) ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleRelated( false ); + + if ( $error === "" ) { + $wgOut->addWikiText( wfMsg( "accmailtext", $u->getName(), $u->getEmail() ) ); + $wgOut->returnToMain( false ); + } else { + $this->mainLoginForm( wfMsg( "mailerror", $error ) ); + } - $u = 0; -} + $u = 0; + } -/* private */ function addNewAccount() -{ - global $wgUser, $wgOut; - global $wgDeferredUpdateList; + /* private */ function addNewAccount() + { + global $wgUser, $wgOut; + global $wgDeferredUpdateList; - $u = addNewAccountInternal(); + $u = $this->addNewAccountInternal(); - if ($u == NULL) { - return; - } + if ($u == NULL) { + return; + } - $wgUser = $u; - $wgUser->setCookies(); + $wgUser = $u; + $wgUser->setCookies(); - $up = new UserUpdate(); - array_push( $wgDeferredUpdateList, $up ); + $up = new UserUpdate(); + array_push( $wgDeferredUpdateList, $up ); - if( hasSessionCookie() ) { - return successfulLogin( wfMsg( "welcomecreation", $wgUser->getName() ) ); - } else { - return cookieRedirectCheck( "new" ); + if( $this->hasSessionCookie() ) { + return $this->successfulLogin( wfMsg( "welcomecreation", $wgUser->getName() ) ); + } else { + return $this->cookieRedirectCheck( "new" ); + } } -} -/* private */ function addNewAccountInternal() -{ - global $wgUser, $wgOut; - global $wgMaxNameChars; - global $wgRequest; + /* private */ function addNewAccountInternal() + { + global $wgUser, $wgOut; + global $wgMaxNameChars; - if (!$wgUser->isAllowedToCreateAccount()) { - userNotPrivilegedMessage(); - return; - } + if (!$wgUser->isAllowedToCreateAccount()) { + $this->userNotPrivilegedMessage(); + return; + } - if ( 0 != strcmp( $_REQUEST['wpPassword'], $_REQUEST['wpRetype'] ) ) { - mainLoginForm( wfMsg( "badretype" ) ); - return; - } - - $name = trim( $_REQUEST['wpName'] ); - if ( ( "" == $name ) || - preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $name ) || - (strpos( $name, "/" ) !== false) || - (strlen( $name ) > $wgMaxNameChars) ) - { - mainLoginForm( wfMsg( "noname" ) ); - return; - } - if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; - } - $u = User::newFromName( $name ); - - if ( 0 != $u->idForName() ) { - mainLoginForm( wfMsg( "userexists" ) ); - return; + if ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) { + $this->mainLoginForm( wfMsg( "badretype" ) ); + return; + } + + $name = trim( $this->mName ); + if ( ( "" == $name ) || + preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $name ) || + (strpos( $name, "/" ) !== false) || + (strlen( $name ) > $wgMaxNameChars) ) + { + $this->mainLoginForm( wfMsg( "noname" ) ); + return; + } + if ( wfReadOnly() ) { + $wgOut->readOnlyPage(); + return; + } + $u = User::newFromName( $name ); + + if ( 0 != $u->idForName() ) { + $this->mainLoginForm( wfMsg( "userexists" ) ); + return; + } + $u->addToDatabase(); + $u->setPassword( $this->mPassword ); + $u->setEmail( $this->mEmail ); + if ( $this->mRemember ) { $r = 1; } + else { $r = 0; } + $u->setOption( "rememberpassword", $r ); + + return $u; } - $u->addToDatabase(); - $u->setPassword( $_REQUEST['wpPassword'] ); - $u->setEmail( $_REQUEST['wpEmail'] ); - if ( $wgRequest->getCheck( 'wpRemember' ) ) { $r = 1; } - else { $r = 0; } - $u->setOption( "rememberpassword", $r ); - - return $u; -} + /* private */ function processLogin() + { + global $wgUser; + global $wgDeferredUpdateList; -/* private */ function processLogin() -{ - global $wgUser; - global $wgDeferredUpdateList; - global $wgRequest; - - if ( "" == $_REQUEST['wpName'] ) { - mainLoginForm( wfMsg( "noname" ) ); - return; - } - $u = User::newFromName( $_REQUEST['wpName'] ); - $id = $u->idForName(); - if ( 0 == $id ) { - mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) ); - return; - } - $u->setId( $id ); - $u->loadFromDatabase(); - $ep = $u->encryptPassword( $_REQUEST['wpPassword'] ); - if ( 0 != strcmp( $ep, $u->getPassword() ) ) { - if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) { - mainLoginForm( wfMsg( "wrongpassword" ) ); + if ( "" == $this->mName ) { + $this->mainLoginForm( wfMsg( "noname" ) ); return; } - } + $u = User::newFromName( $this->mName ); + $id = $u->idForName(); + if ( 0 == $id ) { + $this->mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) ); + return; + } + $u->setId( $id ); + $u->loadFromDatabase(); + $ep = $u->encryptPassword( $this->mPassword ); + if ( 0 != strcmp( $ep, $u->getPassword() ) ) { + if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) { + $this->mainLoginForm( wfMsg( "wrongpassword" ) ); + return; + } + } - # We've verified now, update the real record - # - if ( $wgRequest->getCheck( 'wpRemember' ) ) { - $r = 1; - $u->setCookiePassword( $wgRequest->getText( 'wpPassword' ) ); - } else { - $r = 0; - } - $u->setOption( "rememberpassword", $r ); + # We've verified now, update the real record + # + if ( $this->mRemember ) { + $r = 1; + $u->setCookiePassword( $this->mPassword ); + } else { + $r = 0; + } + $u->setOption( "rememberpassword", $r ); - $wgUser = $u; - $wgUser->setCookies(); + $wgUser = $u; + $wgUser->setCookies(); - $up = new UserUpdate(); - array_push( $wgDeferredUpdateList, $up ); + $up = new UserUpdate(); + array_push( $wgDeferredUpdateList, $up ); - if( hasSessionCookie() ) { - return successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) ); - } else { - return cookieRedirectCheck( "login" ); + if( $this->hasSessionCookie() ) { + return $this->successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) ); + } else { + return $this->cookieRedirectCheck( "login" ); + } } -} -/* private */ function mailPassword() -{ - global $wgUser, $wgDeferredUpdateList, $wgOutputEncoding; - global $wgCookiePath, $wgCookieDomain, $wgDBname; + /* private */ function mailPassword() + { + global $wgUser, $wgDeferredUpdateList, $wgOutputEncoding; + global $wgCookiePath, $wgCookieDomain, $wgDBname; - if ( "" == $_REQUEST['wpName'] ) { - mainLoginForm( wfMsg( "noname" ) ); - return; - } - $u = User::newFromName( $_REQUEST['wpName'] ); - $id = $u->idForName(); - if ( 0 == $id ) { - mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) ); - return; - } - $u->setId( $id ); - $u->loadFromDatabase(); + if ( "" == $this->mName ) { + $this->mainLoginForm( wfMsg( "noname" ) ); + return; + } + $u = User::newFromName( $this->mName ); + $id = $u->idForName(); + if ( 0 == $id ) { + $this->mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) ); + return; + } + $u->setId( $id ); + $u->loadFromDatabase(); + + $error = $this->mailPasswordInternal( $u ); + if ($error === "") { + $this->mainLoginForm( wfMsg( "passwordsent", $u->getName() ) ); + } else { + $this->mainLoginForm( wfMsg( "mailerror", $error ) ); + } - if (mailPasswordInternal($u) == NULL) { - return; } - mainLoginForm( wfMsg( "passwordsent", $u->getName() ) ); -} + /* private */ function mailPasswordInternal( $u ) + { + global $wgDeferredUpdateList, $wgOutputEncoding; + global $wgPasswordSender, $wgDBname, $wgIP; + global $wgCookiePath, $wgCookieDomain; -/* private */ function mailPasswordInternal( $u ) -{ - global $wgDeferredUpdateList, $wgOutputEncoding; - global $wgPasswordSender, $wgDBname, $wgIP; + if ( "" == $u->getEmail() ) { + $this->mainLoginForm( wfMsg( "noemail", $u->getName() ) ); + return; + } + $np = User::randomPassword(); + $u->setNewpassword( $np ); - if ( "" == $u->getEmail() ) { - mainLoginForm( wfMsg( "noemail", $u->getName() ) ); - return; - } - $np = User::randomPassword(); - $u->setNewpassword( $np ); + setcookie( "{$wgDBname}Password", "", time() - 3600, $wgCookiePath, $wgCookieDomain ); + $u->saveSettings(); - setcookie( "{$wgDBname}Password", "", time() - 3600, $wgCookiePath, $wgCookieDomain ); - $u->saveSettings(); + $ip = $wgIP; + if ( "" == $ip ) { $ip = "(Unknown)"; } - $ip = $wgIP; - if ( "" == $ip ) { $ip = "(Unknown)"; } + $m = wfMsg( "passwordremindertext", $ip, $u->getName(), $np ); - $m = wfMsg( "passwordremindertext", $ip, $u->getName(), $np ); + $error = userMailer( $u->getEmail(), $wgPasswordSender, wfMsg( "passwordremindertitle" ), $m ); + + return $error; + } - userMailer( $u->getEmail(), $wgPasswordSender, wfMsg( "passwordremindertitle" ), $m ); - - return $u; -} + /* private */ function successfulLogin( $msg ) + { + global $wgUser; + global $wgDeferredUpdateList; + global $wgOut; + + $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleRelated( false ); + $wgOut->addHTML( $msg . "\n

" ); + $wgOut->returnToMain(); + } -/* private */ function successfulLogin( $msg ) -{ - global $wgUser; - global $wgDeferredUpdateList; - global $wgOut; - - $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->setArticleRelated( false ); - $wgOut->addHTML( $msg . "\n

" ); - $wgOut->returnToMain(); -} + function userNotPrivilegedMessage() + { + global $wgOut, $wgUser, $wgLang; + + $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleRelated( false ); + + $wgOut->addWikiText( wfMsg( "whitelistacctext" ) ); + + $wgOut->returnToMain( false ); + } -function userNotPrivilegedMessage() -{ - global $wgOut, $wgUser, $wgLang; - - $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->setArticleRelated( false ); + /* private */ function mainLoginForm( $err ) + { + global $wgUser, $wgOut, $wgLang; + global $wgDBname; + + $le = wfMsg( "loginerror" ); + $yn = wfMsg( "yourname" ); + $yp = wfMsg( "yourpassword" ); + $ypa = wfMsg( "yourpasswordagain" ); + $rmp = wfMsg( "remembermypassword" ); + $nuo = wfMsg( "newusersonly" ); + $li = wfMsg( "login" ); + $ca = wfMsg( "createaccount" ); + $cam = wfMsg( "createaccountmail" ); + $ye = wfMsg( "youremail" ); + $efl = wfMsg( "emailforlost" ); + $mmp = wfMsg( "mailmypassword" ); + $endText = wfMsg( "loginend" ); + + if ( $endText = "<loginend>" ) { + $endText = ""; + } - $wgOut->addWikiText( wfMsg( "whitelistacctext" ) ); - - $wgOut->returnToMain( false ); -} + if ( "" == $this->mName ) { + if ( 0 != $wgUser->getID() ) { + $this->mName = $wgUser->getName(); + } else { + $this->mName = @$_COOKIE["{$wgDBname}UserName"]; + } + } -/* private */ function mainLoginForm( $err ) -{ - global $wgUser, $wgOut, $wgLang; - global $wgRequest, $wgDBname; - - $le = wfMsg( "loginerror" ); - $yn = wfMsg( "yourname" ); - $yp = wfMsg( "yourpassword" ); - $ypa = wfMsg( "yourpasswordagain" ); - $rmp = wfMsg( "remembermypassword" ); - $nuo = wfMsg( "newusersonly" ); - $li = wfMsg( "login" ); - $ca = wfMsg( "createaccount" ); - $cam = wfMsg( "createaccountmail" ); - $ye = wfMsg( "youremail" ); - $efl = wfMsg( "emailforlost" ); - $mmp = wfMsg( "mailmypassword" ); - $endText = wfMsg( "loginend" ); - - if ( $endText = "<loginend>" ) { - $endText = ""; - } + $wgOut->setPageTitle( wfMsg( "userlogin" ) ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleRelated( false ); - $name = $wgRequest->getText( 'wpName' ); - if ( "" == $name ) { - if ( 0 != $wgUser->getID() ) { - $name = $wgUser->getName(); + if ( "" == $err ) { + $lp = wfMsg( "loginprompt" ); + $wgOut->addHTML( "

$li:

\n

$lp

" ); } else { - $name = @$_COOKIE["{$wgDBname}UserName"]; + $wgOut->addHTML( "

$le:

\n$err\n" ); } - } - $pwd = $wgRequest->getText( 'wpPassword' ); - - $wgOut->setPageTitle( wfMsg( "userlogin" ) ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->setArticleRelated( false ); - - if ( "" == $err ) { - $lp = wfMsg( "loginprompt" ); - $wgOut->addHTML( "

$li:

\n

$lp

" ); - } else { - $wgOut->addHTML( "

$le:

\n$err\n" ); - } - if ( 1 == $wgUser->getOption( "rememberpassword" ) ) { - $checked = " checked"; - } else { - $checked = ""; - } - - $q = "action=submit"; - $returnto = $wgRequest->getVal( "returnto" ); - if ( !empty( $returnto ) ) { - $q .= "&returnto=" . wfUrlencode( $returnto ); - } - - $titleObj = Title::makeTitle( NS_SPECIAL, "Userlogin" ); - $action = $titleObj->escapeLocalUrl( $q ); - - $encName = wfEscapeHTML( $name ); - $encPassword = wfEscapeHTML( $pwd ); - $encRetype = wfEscapeHTML( $wgRequest->getText( 'wpRetype' ) ); - $encEmail = wfEscapeHTML( $wgRequest->getVal( 'wpEmail' ) ); - - if ($wgUser->getID() != 0) { - $cambutton = ""; - } else { - $cambutton = ""; - } + if ( 1 == $wgUser->getOption( "rememberpassword" ) ) { + $checked = " checked"; + } else { + $checked = ""; + } + + $q = "action=submit"; + if ( !empty( $this->mReturnto ) ) { + $q .= "&returnto=" . wfUrlencode( $this->mReturnto ); + } + + $titleObj = Title::makeTitle( NS_SPECIAL, "Userlogin" ); + $action = $titleObj->escapeLocalUrl( $q ); - $wgOut->addHTML( " -
- - - - - - - - - -"); - - if ($wgUser->isAllowedToCreateAccount()) { - $encRetype = htmlspecialchars( $wgRequest->getText( 'wpRetype' ) ); - $encEmail = htmlspecialchars( $wgRequest->getText( 'wpEmail' ) ); -$wgOut->addHTML(" - - - - -"); - } + $encName = wfEscapeHTML( $this->mName ); + $encPassword = wfEscapeHTML( $this->mPassword ); + $encRetype = wfEscapeHTML( $this->mRetype ); + $encEmail = wfEscapeHTML( $this->mEmail ); - $wgOut->addHTML(" - -
$yn: - - - -
$yp: - - - -
 
$ypa: - -$nuo
$ye: - - - -$cambutton -
 
-

$efl
- -

-
\n" ); - $wgOut->addHTML( $endText ); -} + if ($wgUser->getID() != 0) { + $cambutton = ""; + } else { + $cambutton = ""; + } -/* private */ function hasSessionCookie() -{ - global $wgDisableCookieCheck; - return ( $wgDisableCookieCheck ) ? true : ( "" != $_COOKIE[session_name()] ); -} - -/* private */ function cookieRedirectCheck( $type ) -{ - global $wgOut, $wgLang; + $wgOut->addHTML( " +
+ + + + + + + + + + "); + + if ($wgUser->isAllowedToCreateAccount()) { + $encRetype = htmlspecialchars( $this->mRetype ); + $encEmail = htmlspecialchars( $this->mEmail ); + $wgOut->addHTML(" + + + + + "); + } + + $wgOut->addHTML(" + +
$yn: + + + +
$yp: + + + +
 
$ypa: + + $nuo
$ye: + + + + $cambutton +
 
+

$efl
+ +

+
\n" ); + $wgOut->addHTML( $endText ); + } - $titleObj = Title::makeTitle( NS_SPECIAL, "Userlogin" ); - $check = $titleObj->getFullURL( "wpCookieCheck=$type" ); + /* private */ function hasSessionCookie() + { + global $wgDisableCookieCheck; + return ( $wgDisableCookieCheck ) ? true : ( "" != $_COOKIE[session_name()] ); + } + + /* private */ function cookieRedirectCheck( $type ) + { + global $wgOut, $wgLang; - return $wgOut->redirect( $check ); -} + $titleObj = Title::makeTitle( NS_SPECIAL, "Userlogin" ); + $check = $titleObj->getFullURL( "wpCookieCheck=$type" ); -/* private */ function onCookieRedirectCheck( $type ) { - global $wgUser; + return $wgOut->redirect( $check ); + } - if ( !hasSessionCookie() ) { - if ( $type == "new" ) { - return mainLoginForm( wfMsg( "nocookiesnew" ) ); - } else if ( $type == "login" ) { - return mainLoginForm( wfMsg( "nocookieslogin" ) ); + /* private */ function onCookieRedirectCheck( $type ) { + global $wgUser; + + if ( !$this->hasSessionCookie() ) { + if ( $type == "new" ) { + return $this->mainLoginForm( wfMsg( "nocookiesnew" ) ); + } else if ( $type == "login" ) { + return $this->mainLoginForm( wfMsg( "nocookieslogin" ) ); + } else { + # shouldn't happen + return $this->mainLoginForm( wfMsg( "error" ) ); + } } else { - # shouldn't happen - return mainLoginForm( wfMsg( "error" ) ); + return $this->successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) ); } - } else { - return successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) ); } } - ?> -- 2.20.1