$IP = "/usr/local/apache/htdocs/wiki";
-# This workaround is for the maintenance scripts:
-#
if ( ! isset( $DP ) ) { $DP = $IP; }
include_once( "$DP/DefaultSettings.php" );
# MySQL settings
#
-$wgDBserver = "127.0.0.1";
+$wgDBserver = "localhost";
$wgDBname = "wikidb";
$wgDBpassword = "userpass";
-#wgDBsqlpassword = "sqlpass";
+$wgDBsqlpassword = "sqlpass";
$wgDBminWordLen = 3; # Match this to your MySQL fulltext
$wgDBtransactions = false; # Set to true if using InnoDB tables
--- /dev/null
+# This file is copied to the install directory so that
+# later update scripts will be able to use it to determine
+# what they need to update. The version number here must
+# be updated any time you make a change that requires
+# the update to do anything other than copy the new files
+# over, such as changing the database layout. If you
+# change this version number, you should also update the
+# update.php script.
+#
+
+$wgSoftwareRevision = 1001;
+
# MySQL settings
#
-$wgDBserver = "127.0.0.1";
+$wgDBserver = "localhost";
$wgDBname = "wikidb";
$wgDBintlname = "intl";
$wgDBconnection = "";
function databaseError( $fname )
{
- global $wgUser;
+ global $wgUser, $wgCommandLineMode;
$this->setPageTitle( wfMsg( "databaseerror" ) );
$this->setRobotpolicy( "noindex,nofollow" );
$this->setArticleFlag( false );
- $msg = str_replace( "$1", htmlspecialchars( wfLastDBquery() ), wfMsg( "dberrortext" ) );
+ if ( $wgCommandLineMode ) {
+ $msg = wfMsg( "dberrortextcl" );
+ } else {
+ $msg = wfMsg( "dberrortextcl" );
+ }
+ $msg = str_replace( "$1", htmlspecialchars( wfLastDBquery() ), $msg );
$msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
$msg = str_replace( "$3", wfLastErrno(), $msg );
$msg = str_replace( "$4", htmlspecialchars( wfLastError() ), $msg );
+ if ( $wgCommandLineMode ) {
+ print $msg;
+ exit();
+ }
$sk = $wgUser->getSkin();
$shlink = $sk->makeKnownLink( wfMsg( "searchhelppage" ),
wfMsg( "searchingwikipedia" ) );
}
$wpName = trim( $wpName );
if ( ( "" == $wpName ) ||
- preg_match( "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/", $wpName ) ) {
+ preg_match( "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/", $wpName ) )
+{
mainLoginForm( wfMsg( "noname" ) );
return;
}
}
$u->setId( $id );
$u->loadFromDatabase();
- $ep = User::encryptPassword( $wpPassword );
+ $ep = $u->encryptPassword( $wpPassword );
if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
mainLoginForm( wfMsg( "wrongpassword" ) );
return;
}
}
+
# We've verified now, update the real record
#
- if ( 1 == $wpRemember ) { $r = 1; }
- else { $r = 0; }
+ if ( 1 == $wpRemember ) {
+ $r = 1;
+ $u->setCookiePassword( $wpPassword );
+ } else {
+ $r = 0;
+ }
$u->setOption( "rememberpassword", $r );
$wgUser = $u;
}
$np = User::randomPassword();
$u->setNewpassword( $np );
+
setcookie( "wcUserPassword", "", time() - 3600 );
$u->saveSettings();
if ( "" == $err ) {
$wgOut->addHTML( "<h2>$li:</h2>\n" );
} else {
- $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1' color='red'>$err</font>\n" );
+ $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1'
+color='red'>$err</font>\n" );
}
if ( 1 == $wgUser->getOption( "rememberpassword" ) ) {
$checked = " checked";
$wpEmail = wfEscapeHTML( $wpEmail );
$wgOut->addHTML( "
-<form id=\"userlogin\" method=\"post\" action=\"{$action}\">
+<form name='userlogin' method=post action=\"{$action}\">
<table border=0><tr>
<td align=right>$yn:</td>
<td colspan=2 align=left>
-<input tabindex=1 type=text name=\"wpName\" value=\"{$name}\" size=20>
+<input tabindex=1 type=text name='wpName' value=\"{$name}\" size=20>
</td></tr><tr>
<td align=right>$yp:</td>
<td align=left>
-<input tabindex=2 type=password name=\"wpPassword\" value=\"{$pwd}\" size=20>
+<input tabindex=2 type=password name='wpPassword' value=\"{$pwd}\" size=20>
</td>
<td align=left>
-<input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
+<input tabindex=3 type=submit name='wpLoginattempt' value=\"{$li}\">
</td></tr>
<tr><td colspan=3> </td></tr><tr>
<td align=right>$ypa:</td>
<td align=left>
-<input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\" size=20>
+<input tabindex=4 type=password name='wpRetype' value=\"{$wpRetype}\"
+size=20>
</td><td>$nuo</td></tr>
<tr>
<td align=right>$ye:</td>
<td align=left>
-<input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
+<input tabindex=5 type=text name='wpEmail' value=\"{$wpEmail}\" size=20>
</td><td align=left>
-<input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
+<input tabindex=6 type=submit name='wpCreateaccount' value=\"{$ca}\">
</td></tr>
<tr>
<td colspan=3 align=left>
-<input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\"$checked>$rmp
+<input tabindex=7 type=checkbox name='wpRemember' value='1'$checked>$rmp
</td></tr>
<tr><td colspan=3> </td></tr><tr>
<td colspan=3 align=left>
<p>$efl<br>
-<input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">
+<input tabindex=8 type=submit name='wpMailmypassword' value=\"{$mmp}\">
</td></tr></table>
</form>\n" );
}
/* private */ var $mSkin;
/* private */ var $mBlockedby, $mBlockreason;
/* private */ var $mTouched;
+ /* private */ var $mCookiePassword;
function User()
{
return $s->user_id;
}
}
-
+
# does the string match an anonymous user IP address?
/* static */ function isIP( $name ) {
return preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$name);
-
+
}
-
-
+
+
/* static */ function randomPassword()
{
$this->mDataLoaded = false;
$this->mBlockedby = -1; # Unset
$this->mTouched = '0'; # Allow any pages to be cached
+ $this->cookiePassword = "";
}
/* private */ function getBlockedStatus()
$this->mId = 0;
return;
}
+
+ $passwordCorrect = FALSE;
+ $this->mId = $sId;
+ $this->loadFromDatabase();
+
if ( isset( $wsUserPassword ) ) {
- $sPass = $wsUserPassword;
+ $passwordCorrect = $wsUserPassword == $this->mPassword;
} else if ( isset( $HTTP_COOKIE_VARS["wcUserPassword"] ) ) {
- $sPass = $HTTP_COOKIE_VARS["wcUserPassword"];
- $wsUserPassword = $sPass;
+ $this->mCookiePassword = $HTTP_COOKIE_VARS["wcUserPassword"];
+ $wsUserPassword = $this->addSalt($this->mCookiePassword);
+ $passwordCorrect = $wsUserPassword == $this->mPassword;
} else {
$this->mId = 0;
return;
}
- $this->mId = $sId;
- $this->loadFromDatabase();
- if ( ( $sName == $this->mName ) &&
- ( ( $sPass == $this->mPassword ) ||
- ( $sPass == $this->mNewpassword ) ) ) {
+ if ( ( $sName == $this->mName ) && $passwordCorrect ) {
return;
}
$this->loadDefaults(); # Can't log in from session
function loadFromDatabase()
{
- if ( $this->mDataLoaded ) { return; }
+ if ( $this->mDataLoaded ) { return; }
# check in separate table if there are changes to the talk page
$this->mNewtalk=0; # reset talk page status
- if($this->mId) {
- $sql = "SELECT 1 FROM user_newtalk WHERE user_id={$this->mId}";
+ if($this->mId) {
+ $sql = "SELECT 1 FROM user_newtalk WHERE user_id={$this->mId}";
$res = wfQuery ($sql, "User::loadFromDatabase" );
- if (wfNumRows($res)>0) {
+ if (wfNumRows($res)>0) {
$this->mNewtalk= 1;
}
wfFreeResult( $res );
} else {
- $sql = "SELECT 1 FROM user_newtalk WHERE user_ip='{$this->mName}'";
+ $sql = "SELECT 1 FROM user_newtalk WHERE user_ip='{$this->mName}'";
$res = wfQuery ($sql, "User::loadFromDatabase" );
-
- if (wfNumRows($res)>0) {
+
+ if (wfNumRows($res)>0) {
$this->mNewtalk= 1;
}
wfFreeResult( $res );
$this->mDataLoaded = true;
return;
} # the following stuff is for non-anonymous users only
-
+
$sql = "SELECT user_name,user_password,user_newpassword,user_email," .
"user_options,user_rights,user_touched FROM user WHERE user_id=" .
"{$this->mId}";
$this->decodeOptions( $s->user_options );
$this->mRights = explode( ",", strtolower( $s->user_rights ) );
$this->mTouched = $s->user_touched;
- }
-
+ }
+
wfFreeResult( $res );
$this->mDataLoaded = true;
}
$this->mNewtalk = $val;
$this->invalidateCache();
}
-
+
function invalidateCache() {
$this->loadFromDatabase();
$this->mTouched = wfTimestampNow();
# Don't forget to save the options after this or
# it won't take effect!
}
-
+
function validateCache( $timestamp ) {
$this->loadFromDatabase();
return ($timestamp >= $this->mTouched);
}
-
+
function getPassword()
{
$this->loadFromDatabase();
return $this->mNewpassword;
}
- /* static */ function encryptPassword( $p )
+ function addSalt( $p )
{
- $np = md5( $p );
- return $np;
+ return md5( "wikipedia{$this->mId}-{$p}" );
+ }
+
+ function encryptPassword( $p )
+ {
+ return $this->addSalt( md5( $p ) );
}
function setPassword( $str )
{
$this->loadFromDatabase();
- $this->mPassword = User::encryptPassword( $str );
+ $this->setCookiePassword( $str );
+ $this->mPassword = $this->encryptPassword( $str );
$this->mNewpassword = "";
}
+ function setCookiePassword( $str )
+ {
+ $this->loadFromDatabase();
+ $this->mCookiePassword = md5( $str );
+ }
+
function setNewpassword( $str )
{
$this->loadFromDatabase();
- $this->mNewpassword = User::encryptPassword( $str );
+ $this->mNewpassword = $this->encryptPassword( $str );
}
function getEmail()
return in_array( "developer", $this->mRights );
}
-
+
function isBot()
{
$this->loadFromDatabase();
if ( 0 == $this->mId ) { return false; }
-
+
return in_array( "bot", $this->mRights );
}
-
+
function &getSkin()
{
if ( ! isset( $this->mSkin ) ) {
$wsUserPassword = $this->mPassword;
if ( 1 == $this->getOption( "rememberpassword" ) ) {
- setcookie( "wcUserPassword", $this->mPassword, $exp, "/" );
+ setcookie( "wcUserPassword", $this->mCookiePassword, $exp, "/" );
} else {
setcookie( "wcUserPassword", "", time() - 3600 );
}
function saveSettings()
{
global $wgUser;
-
+
if(!$this->mNewtalk) {
-
+
if($this->mId) {
$sql="DELETE FROM user_newtalk WHERE user_id={$this->mId}";
wfQuery ($sql,"User::saveSettings");
} else {
-
-
+
+
$sql="DELETE FROM user_newtalk WHERE user_ip='{$this->mName}'";
wfQuery ($sql,"User::saveSettings");
-
+
}
}
- if ( 0 == $this->mId ) { return; }
+ if ( 0 == $this->mId ) { return; }
$sql = "UPDATE user SET " .
"user_name= '" . wfStrencode( $this->mName ) . "', " .
"user_newpassword= '" . wfStrencode( $this->mNewpassword ) . "', " .
"user_email= '" . wfStrencode( $this->mEmail ) . "', " .
"user_options= '" . $this->encodeOptions() . "', " .
- "user_rights= '" . wfStrencode( implode( ",", $this->mRights ) ) . "', " .
+ "user_rights= '" . wfStrencode( implode( ",", $this->mRights ) ) . "', "
+.
"user_touched= '" . wfStrencode( $this->mTouched ) .
"' WHERE user_id={$this->mId}";
wfQuery( $sql, "User::saveSettings" );
$this->mId = $this->idForName();
}
}
+
?>
"source directory before running this install script.\n";
exit();
}
+if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
+ print "To use math functions, you must first compile texvc by\n" .
+ "running \"make\" in the math directory.\n";
+ exit();
+}
$DP = "./includes";
include_once( "./LocalSettings.php" );
include_once( "./AdminSettings.php" );
-if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
- print "To use math functions, you must first compile texvc by\n" .
- "running \"make\" in the math directory.\n";
- exit();
+if ( is_file( "{$IP}/Version.php" ) ) {
+ print "There appears to be an installation of the software\n" .
+ "already present on \"{$IP}\". You may want to run the update\n" .
+ "script instead. If you continue with this installation script,\n" .
+ "that software and all of its data will be overwritten.\n" .
+ "Are you sure you want to do this? (yes/no) ";
+
+ $response = readconsole();
+ if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
}
+$wgCommandLineMode = true;
umask( 000 );
set_time_limit( 0 );
print "Copying files...\n";
copyfile( ".", "LocalSettings.php", $IP );
+copyfile( ".", "Version.php", $IP );
copyfile( ".", "wiki.phtml", $IP );
copyfile( ".", "redirect.phtml", $IP );
copyfile( ".", "texvc.phtml", $IP );
-$handle = opendir( "./includes" );
-while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- copyfile( "./includes", $f, $IP );
-}
-
-$handle = opendir( "./stylesheets" );
-while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- copyfile( "./stylesheets", $f, $wgStyleSheetDirectory );
-}
+copydirectory( "./includes", $IP );
+copydirectory( "./stylesheets", $wgStyleSheetsDirectory );
copyfile( "./images", "wiki.png", $wgUploadDirectory );
copyfile( "./languages", "Language.php", $IP );
print "Adding indexes...\n";
dbsource( $rconn, "./maintenance/indexes.sql" );
+copyfile( ".", "Version.php", $IP );
+
print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test,\n" .
"or \"run WikiSuite -b -o\" in test suite.\n";
exit();
# Functions used above:
#
function makedirectory( $d ) {
- global $installOwner, $installGroup;
+ global $wgInstallOwner, $wgInstallGroup;
if ( is_dir( $d ) ) {
print "Directory \"{$d}\" exists.\n";
} else {
if ( mkdir( $d, 0777 ) ) {
- if ( isset( $installOwner ) ) { chown( $d, $installOwner ); }
- if ( isset( $installGroup ) ) { chgrp( $d, $installGroup ); }
+ if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
+ if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
print "Directory \"{$d}\" created.\n";
} else {
print "Could not create directory \"{$d}\".\n";
}
}
-function copyfile( $sdir, $name, $ddir, $perms = 0644 ) {
- global $installOwner, $installGroup;
+function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
+ global $wgInstallOwner, $wgInstallGroup;
$d = "{$ddir}/{$name}";
if ( copy( "{$sdir}/{$name}", $d ) ) {
- if ( isset( $installOwner ) ) { chown( $d, $installOwner ); }
- if ( isset( $installGroup ) ) { chgrp( $d, $installGroup ); }
+ if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
+ if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
chmod( $d, $perms );
# print "Copied \"{$name}\" to \"{$ddir}\".\n";
} else {
}
}
+function copydirectory( $source, $dest ) {
+ $handle = opendir( $source );
+ while ( false !== ( $f = readdir( $handle ) ) ) {
+ if ( "." == $f{0} ) continue;
+ if ( "CVS" == $f ) continue;
+ copyfile( $source, $f, $dest );
+ }
+}
+
function readconsole() {
$fp = fopen( "php://stdin", "r" );
$resp = trim( fgets( $fp ) );
"cur_restrictions) VALUES ({$wns},'{$dlp}','" .
wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop')";
wfQuery( $sql );
+
+ $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text) " .
+ "VALUES (0,'" . wfStrencode( wfMsg( "mainpage" ) ) . "','" .
+ wfStrencode( wfMsg( "mainpagetext" ) ) . "')";
+ wfQuery( $sql );
}
?>
#
"linktrail" => "/^([a-z]+)(.*)\$/sD",
"mainpage" => "Main Page",
+"mainpagetext" => "Wiki software successfully installed.",
"about" => "About",
"aboutwikipedia" => "About Wikipedia",
"aboutpage" => "Wikipedia:About",
<blockquote><tt>$1</tt></blockquote>
from within function \"<tt>$2</tt>\".
MySQL returned error \"<tt>$3: $4</tt>\".",
+"dberrortextcl" => "A database query syntax error has occurred.
+The last attempted database query was:
+\"$1\"
+from within function \"$2\".
+MySQL returned error \"$3: $4\".\n",
"noconnect" => "Could not connect to DB on $1",
"nodb" => "Could not select database $1",
"readonly" => "Database locked",
}
private int part1() throws Exception {
+ WebResponse wr = getResponse( viewUrl( "Special:Upload" ) );
+ String text = getArticle( wr );
+
+ String[] goodpats = { "<h1[^>]*>Not logged in</h1>" };
+ int c = 0;
+
+ if ( 0 != ( c = checkGoodPatterns( text, goodpats ) ) ) {
+ return 100 + c;
+ }
+ wr = loginAs( "Fred", "Fred" );
+ wr = viewPage( "Special:Upload" );
+ text = getArticle( wr );
+
+ String[] goodpats2 = {
+ "<h1[^>]*>Upload file</h1>", ">image use policy<", ">upload log<"
+ };
+ if ( 0 != ( c = checkGoodPatterns( text, goodpats2 ) ) ) {
+ return 110 + c;
+ }
+
+ WebForm wf = getFormByName( wr, "upload" );
+ WebRequest req = wf.getRequest( "wpUpload" );
+
+ req.selectFile( "wpUploadFile", new java.io.File( "./data/startrek.png" ) );
+ req.setParameter( "wpUploadDescription", "Upload test" );
+
+ wr = getResponse( req );
+ text = getArticle( wr );
+
+ String[] goodpats3 = {
+ "<h1[^>]*>Upload error</h1>", "You must affirm"
+ };
+ if ( 0 != ( c = checkGoodPatterns( text, goodpats2 ) ) ) {
+ return 120 + c;
+ }
+
+ wr = viewPage( "Special:Upload" );
+ text = getArticle( wr );
+
+ wf = getFormByName( wr, "upload" );
+ req = wf.getRequest( "wpUpload" );
+ req.selectFile( "wpUploadFile", new java.io.File( "./data/startrek.png" ) );
+ req.setParameter( "wpUploadDescription", "Upload test" );
+ req.setParameter( "wpUploadAffirm", "1" );
+
+ wr = getResponse( req );
+ text = getArticle( wr );
+
+ String[] goodpats4 = {
+ "uploaded successfully", "description page"
+ };
+ if ( 0 != ( c = checkGoodPatterns( text, goodpats4 ) ) ) {
+ return 130 + c;
+ }
+
return 0;
}
umask( 000 );
set_time_limit( 0 );
+include_once( "{$IP}/Version.php" );
+include_once( "{$IP}/Setup.php" );
+$wgTitle = Title::newFromText( "Update script" );
+$wgCommandLineMode = true;
+
+do_revision_updates();
+
#
# Copy files into installation directories
#
copyfile( ".", "redirect.phtml", $IP );
copyfile( ".", "texvc.phtml", $IP );
-$handle = opendir( "./includes" );
-while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- copyfile( "./includes", $f, $IP );
-}
-
-$handle = opendir( "./stylesheets" );
-while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- copyfile( "./stylesheets", $f, $wgStyleSheetDirectory );
-}
+copydirectory( "./includes", $IP );
+copydirectory( "./stylesheets", $wgStyleSheetDirectory );
copyfile( "./images", "wiki.png", $wgUploadDirectory );
copyfile( "./languages", "Language.php", $IP );
copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
}
-print "Done.\nIf any database changes are necessary, you may have to run\n" .
- "one or more \"patch\" files from the maintenance directory.\n";
+copyfile( ".", "Version.php", $IP );
+
+print "Done.\n";
exit();
-function copyfile( $sdir, $name, $ddir, $perms = 0644 ) {
- global $installOwner, $installGroup;
+#
+#
+#
+
+function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
+ global $wgInstallOwner, $wgInstallGroup;
$d = "{$ddir}/{$name}";
if ( copy( "{$sdir}/{$name}", $d ) ) {
- if ( isset( $installOwner ) ) { chown( $d, $installOwner ); }
- if ( isset( $installGroup ) ) { chgrp( $d, $installGroup ); }
+ if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
+ if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
chmod( $d, $perms );
# print "Copied \"{$name}\" to \"{$ddir}\".\n";
} else {
}
}
+function copydirectory( $source, $dest ) {
+ $handle = opendir( $source );
+ while ( false !== ( $f = readdir( $handle ) ) ) {
+ if ( "." == $f{0} ) continue;
+ if ( "CVS" == $f ) continue;
+ copyfile( $source, $f, $dest );
+ }
+}
+
+function do_revision_updates() {
+ global $wgSoftwareRevision;
+
+ if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
+}
+
+function update_passwords() {
+ $fname = "Update scripte: update_passwords()";
+ print "Updating passwords...\n";
+
+ $sql = "SELECT user_id,user_password FROM user";
+ $source = wfQuery( $sql, fname );
+
+ while ( $row = mysql_fetch_object( $source ) ) {
+ $id = $row->user_id;
+ $oldpass = $row->user_password;
+ $newpass = md5( $oldpass . $id );
+
+ $sql = "UPDATE user SET user_password='{$newpass}' " .
+ "WHERE user_id={$id}";
+ wfQuery( $sql, $fname );
+ }
+}
+
?>