Consolidate a bit of the link update code from movepage into linksupdate
[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 $IP = "./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( "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 readconsole() {
98 $fp = fopen( "php://stdin", "r" );
99 $resp = trim( fgets( $fp ) );
100 fclose( $fp );
101 return $resp;
102 }
103
104 function do_revision_updates() {
105 global $wgSoftwareRevision;
106
107 if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
108 }
109
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) ";
117
118 $resp = readconsole();
119 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
120
121 $sql = "SELECT user_id,user_password FROM user";
122 $source = wfQuery( $sql, fname );
123
124 while ( $row = mysql_fetch_object( $source ) ) {
125 $id = $row->user_id;
126 $oldpass = $row->user_password;
127 $newpass = md5( "{$id}-{$oldpass}" );
128
129 $sql = "UPDATE user SET user_password='{$newpass}' " .
130 "WHERE user_id={$id}";
131 wfQuery( $sql, $fname );
132 }
133 }
134
135 ?>