New update script, Version.php, new salted passwords, minor fixes.
[lhc/web/wiklou.git] / update.php
1 <?
2
3 # Update already-installed software
4 #
5
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();
11 }
12
13 $DP = "./includes";
14 include_once( "./LocalSettings.php" );
15 include_once( "./AdminSettings.php" );
16
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();
21 }
22
23 umask( 000 );
24 set_time_limit( 0 );
25
26 include_once( "{$IP}/Version.php" );
27 include_once( "{$IP}/Setup.php" );
28 $wgTitle = Title::newFromText( "Update script" );
29 $wgCommandLineMode = true;
30
31 do_revision_updates();
32
33 #
34 # Copy files into installation directories
35 #
36 print "Copying files...\n";
37
38 copyfile( ".", "wiki.phtml", $IP );
39 copyfile( ".", "redirect.phtml", $IP );
40 copyfile( ".", "texvc.phtml", $IP );
41
42 copydirectory( "./includes", $IP );
43 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
44
45 copyfile( "./images", "wiki.png", $wgUploadDirectory );
46 copyfile( "./languages", "Language.php", $IP );
47 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
48
49 $fp = fopen( $wgDebugLogFile, "w" );
50 if ( false === $fp ) {
51 print "Could not create log file \"{$wgDebugLogFile}\".\n";
52 exit();
53 }
54 $d = date( "Y-m-d H:i:s" );
55 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
56 fclose( $fp );
57
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 );
62 }
63
64 copyfile( ".", "Version.php", $IP );
65
66 print "Done.\n";
67 exit();
68
69 #
70 #
71 #
72
73 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
74 global $wgInstallOwner, $wgInstallGroup;
75
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();
85 }
86 }
87
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 );
94 }
95 }
96
97 function do_revision_updates() {
98 global $wgSoftwareRevision;
99
100 if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
101 }
102
103 function update_passwords() {
104 $fname = "Update scripte: update_passwords()";
105 print "Updating passwords...\n";
106
107 $sql = "SELECT user_id,user_password FROM user";
108 $source = wfQuery( $sql, fname );
109
110 while ( $row = mysql_fetch_object( $source ) ) {
111 $id = $row->user_id;
112 $oldpass = $row->user_password;
113 $newpass = md5( $oldpass . $id );
114
115 $sql = "UPDATE user SET user_password='{$newpass}' " .
116 "WHERE user_id={$id}";
117 wfQuery( $sql, $fname );
118 }
119 }
120
121 ?>