Various additions and fixes
[mediawiki.git] / update.php
blob66ae6f06009c8e3c79d9a6e885e90466d6414150
1 <?
3 # Update already-installed software
6 if ( ! ( is_readable( "./LocalSettings.php" )
7 && is_readable( "./AdminSettings.php" ) ) ) {
8 print "A copy of your installation's LocalSettings.php\n" .
9 "and AdminSettings.php must exist in this source directory.\n";
10 exit();
13 $IP = "./includes";
14 include_once( "./LocalSettings.php" );
15 include_once( "./AdminSettings.php" );
17 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
18 print "To use math functions, you must first compile texvc by\n" .
19 "running \"make\" in the math directory.\n";
20 exit();
23 umask( 000 );
24 set_time_limit( 0 );
26 include_once( "Version.php" );
27 include_once( "{$IP}/Setup.php" );
28 $wgTitle = Title::newFromText( "Update script" );
29 $wgCommandLineMode = true;
31 do_revision_updates();
34 # Copy files into installation directories
36 print "Copying files...\n";
38 copyfile( ".", "wiki.phtml", $IP );
39 copyfile( ".", "redirect.phtml", $IP );
40 copyfile( ".", "texvc.phtml", $IP );
42 copydirectory( "./includes", $IP );
43 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
45 copyfile( "./images", "wiki.png", $wgUploadDirectory );
46 copyfile( "./languages", "Language.php", $IP );
47 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
49 $fp = fopen( $wgDebugLogFile, "w" );
50 if ( false === $fp ) {
51 print "Could not create log file \"{$wgDebugLogFile}\".\n";
52 exit();
54 $d = date( "Y-m-d H:i:s" );
55 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
56 fclose( $fp );
58 if ( $wgUseTeX ) {
59 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
60 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
61 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
64 copyfile( ".", "Version.php", $IP );
66 print "Done.\n";
67 exit();
73 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
74 global $wgInstallOwner, $wgInstallGroup;
76 $d = "{$ddir}/{$name}";
77 if ( copy( "{$sdir}/{$name}", $d ) ) {
78 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
79 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
80 chmod( $d, $perms );
81 # print "Copied \"{$name}\" to \"{$ddir}\".\n";
82 } else {
83 print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
84 exit();
88 function copydirectory( $source, $dest ) {
89 $handle = opendir( $source );
90 while ( false !== ( $f = readdir( $handle ) ) ) {
91 if ( "." == $f{0} ) continue;
92 if ( "CVS" == $f ) continue;
93 copyfile( $source, $f, $dest );
97 function readconsole() {
98 $fp = fopen( "php://stdin", "r" );
99 $resp = trim( fgets( $fp ) );
100 fclose( $fp );
101 return $resp;
104 function do_revision_updates() {
105 global $wgSoftwareRevision;
107 if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
110 function update_passwords() {
111 $fname = "Update scripte: update_passwords()";
112 print "\nIt appears that you need to update the user passwords in your\n" .
113 "database. If you have already done this (if you've run this update\n" .
114 "script once before, for example), doing so again will make all your\n" .
115 "user accounts inaccessible, so be sure you only do this once.\n" .
116 "Update user passwords? (yes/no) ";
118 $resp = readconsole();
119 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
121 $sql = "SELECT user_id,user_password FROM user";
122 $source = wfQuery( $sql, fname );
124 while ( $row = mysql_fetch_object( $source ) ) {
125 $id = $row->user_id;
126 $oldpass = $row->user_password;
127 $newpass = md5( "{$id}-{$oldpass}" );
129 $sql = "UPDATE user SET user_password='{$newpass}' " .
130 "WHERE user_id={$id}";
131 wfQuery( $sql, $fname );