New update script, Version.php, new salted passwords, minor fixes.
authorLee Daniel Crocker <lcrocker@users.mediawiki.org>
Wed, 16 Apr 2003 07:30:52 +0000 (07:30 +0000)
committerLee Daniel Crocker <lcrocker@users.mediawiki.org>
Wed, 16 Apr 2003 07:30:52 +0000 (07:30 +0000)
LocalSettings.sample
Version.php [new file with mode: 0644]
includes/DefaultSettings.php
includes/OutputPage.php
includes/SpecialUserlogin.php
includes/User.php
install.php
languages/Language.php
testsuite/src/com/piclab/wikitest/UploadTest.java
update.php

index f0ac8e4..e5a82e9 100644 (file)
@@ -15,8 +15,6 @@
 
 $IP = "/usr/local/apache/htdocs/wiki";
 
-# This workaround is for the maintenance scripts:
-#
 if ( ! isset( $DP ) ) { $DP = $IP; }
 include_once( "$DP/DefaultSettings.php" );
 
@@ -31,10 +29,10 @@ $wgEmergencyContact = "wikiadmin@myhost.com";
 
 # 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
 
diff --git a/Version.php b/Version.php
new file mode 100644 (file)
index 0000000..cdbf6e3
--- /dev/null
@@ -0,0 +1,12 @@
+# 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;
+
index 77be904..6b9746c 100644 (file)
@@ -19,7 +19,7 @@ $wgEmergencyContact = "wikiadmin@" . getenv( "SERVER_NAME" );
 
 # MySQL settings
 #
-$wgDBserver         = "127.0.0.1";
+$wgDBserver         = "localhost";
 $wgDBname           = "wikidb";
 $wgDBintlname       = "intl";
 $wgDBconnection     = "";
index b1c97a1..8869627 100644 (file)
@@ -531,17 +531,26 @@ class OutputPage {
 
        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" ) );
index ed16443..803cafd 100644 (file)
@@ -31,7 +31,8 @@ function wfSpecialUserlogin()
        }
        $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;
        }
@@ -75,17 +76,22 @@ function wfSpecialUserlogin()
        }
        $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;
@@ -118,6 +124,7 @@ function wfSpecialUserlogin()
        }
        $np = User::randomPassword();
        $u->setNewpassword( $np );
+
        setcookie( "wcUserPassword", "", time() - 3600 );
        $u->saveSettings();
 
@@ -191,7 +198,8 @@ function wfSpecialUserlogin()
        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";
@@ -208,39 +216,40 @@ function wfSpecialUserlogin()
        $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>&nbsp;</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>&nbsp;</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" );
 }
index 127fe34..45c60a2 100644 (file)
@@ -8,6 +8,7 @@ class User {
        /* private */ var $mSkin;
        /* private */ var $mBlockedby, $mBlockreason;
        /* private */ var $mTouched;
+       /* private */ var $mCookiePassword;
 
        function User()
        {
@@ -45,14 +46,14 @@ class 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()
        {
@@ -84,6 +85,7 @@ class User {
                $this->mDataLoaded = false;
                $this->mBlockedby = -1; # Unset
                $this->mTouched = '0'; # Allow any pages to be cached
+               $this->cookiePassword = "";
        }
 
        /* private */ function getBlockedStatus()
@@ -152,21 +154,23 @@ class User {
                        $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
@@ -174,22 +178,22 @@ class User {
 
        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 );
@@ -198,7 +202,7 @@ class User {
                        $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}";
@@ -213,8 +217,8 @@ class User {
                        $this->decodeOptions( $s->user_options );
                        $this->mRights = explode( ",", strtolower( $s->user_rights ) );
                        $this->mTouched = $s->user_touched;
-               }                               
-               
+               }
+
                wfFreeResult( $res );
                $this->mDataLoaded = true;
        }
@@ -248,19 +252,19 @@ class User {
                $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();
@@ -273,23 +277,34 @@ class User {
                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()
@@ -342,15 +357,15 @@ class User {
 
                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 ) ) {
@@ -443,7 +458,7 @@ class User {
 
                $wsUserPassword = $this->mPassword;
                if ( 1 == $this->getOption( "rememberpassword" ) ) {
-                       setcookie( "wcUserPassword", $this->mPassword, $exp, "/" );
+                       setcookie( "wcUserPassword", $this->mCookiePassword, $exp, "/" );
                } else {
                        setcookie( "wcUserPassword", "", time() - 3600 );
                }
@@ -463,22 +478,22 @@ class User {
        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 ) . "', " .
@@ -486,7 +501,8 @@ class User {
                  "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" );
@@ -527,4 +543,5 @@ class User {
                $this->mId = $this->idForName();
        }
 }
+
 ?>
index e4f5a60..37775ca 100644 (file)
@@ -10,17 +10,28 @@ if ( ! ( is_readable( "./LocalSettings.php" )
          "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 );
 
@@ -36,21 +47,13 @@ foreach ( $dirs as $d ) { makedirectory( $d ); }
 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 );
@@ -114,6 +117,8 @@ populatedata(); # Needs internationalized messages
 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();
@@ -122,14 +127,14 @@ 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";
@@ -138,13 +143,13 @@ function makedirectory( $d ) {
        }
 }
 
-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 {
@@ -153,6 +158,15 @@ function copyfile( $sdir, $name, $ddir, $perms = 0644 ) {
        }
 }
 
+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 ) );
@@ -254,6 +268,11 @@ function populatedata() {
          "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 );
 }
 
 ?>
index 92312c1..6a99ed7 100644 (file)
@@ -280,6 +280,7 @@ this</a> (alternative: like this<a href=\"\" class=\"internal\">?</a>).",
 #
 "linktrail"            => "/^([a-z]+)(.*)\$/sD",
 "mainpage"             => "Main Page",
+"mainpagetext" => "Wiki software successfully installed.",
 "about"                        => "About",
 "aboutwikipedia" => "About Wikipedia",
 "aboutpage"            => "Wikipedia:About",
@@ -368,6 +369,11 @@ The last attempted database query was:
 <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",
index bdf0dc5..9c7bb72 100644 (file)
@@ -24,6 +24,61 @@ protected int runTest() throws Exception {
 }
 
 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;
 }
 
index 3d81288..0f63e53 100644 (file)
@@ -23,6 +23,13 @@ if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
 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
 #
@@ -32,17 +39,8 @@ 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", $wgStyleSheetDirectory );
 
 copyfile( "./images", "wiki.png", $wgUploadDirectory );
 copyfile( "./languages", "Language.php", $IP );
@@ -63,17 +61,22 @@ if ( $wgUseTeX ) {
        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 {
@@ -82,4 +85,37 @@ function copyfile( $sdir, $name, $ddir, $perms = 0644 ) {
        }
 }
 
+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 );
+       }
+}
+
 ?>