Nov. branch merge. Various features backported from stable, various bug fixes.
[lhc/web/wiklou.git] / update.php
1 <?
2
3
4 /*
5
6 TODO: Links cache will be very unhappy without a table like this //e23
7
8 CREATE TABLE linkscc (lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY,
9 lcc_title VARCHAR(255) NOT NULL UNIQUE KEY,
10 lcc_cacheobj MEDIUMBLOB NOT NULL);
11
12 */
13
14
15
16 # Update already-installed software
17 #
18
19 if ( ! ( is_readable( "./LocalSettings.php" )
20 && is_readable( "./AdminSettings.php" ) ) ) {
21 print "A copy of your installation's LocalSettings.php\n" .
22 "and AdminSettings.php must exist in this source directory.\n";
23 exit();
24 }
25
26 $IP = "./includes";
27 include_once( "./LocalSettings.php" );
28 include_once( "./AdminSettings.php" );
29
30 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
31 print "To use math functions, you must first compile texvc by\n" .
32 "running \"make\" in the math directory.\n";
33 exit();
34 }
35
36 umask( 000 );
37 set_time_limit( 0 );
38
39 include_once( "Version.php" );
40 include_once( "{$IP}/Setup.php" );
41 include_once( "./maintenance/InitialiseMessages.php" );
42
43 $wgTitle = Title::newFromText( "Update script" );
44 $wgCommandLineMode = true;
45 $wgAlterSpecs = array();
46
47 do_revision_updates();
48 alter_ipblocks();
49 initialiseMessages();
50
51 #
52 # Run ALTER TABLE queries.
53 #
54 if ( count( $wgAlterSpecs ) ) {
55 $rconn = mysql_connect( $wgDBserver, $wgDBadminuser, $wgDBadminpassword );
56 mysql_select_db( $wgDBname );
57 print "\n";
58 foreach ( $wgAlterSpecs as $table => $specs ) {
59 $sql = "ALTER TABLE $table $specs";
60 print "$sql;\n";
61 $res = mysql_query( $sql, $rconn );
62 if ( $res === false ) {
63 print "MySQL error: " . mysql_error( $rconn ) . "\n";
64 }
65 }
66 mysql_close( $rconn );
67 }
68
69
70 #
71 # Copy files into installation directories
72 #
73 print "Copying files...\n";
74
75 copyfile( ".", "wiki.phtml", $IP );
76 copyfile( ".", "redirect.phtml", $IP );
77 copyfile( ".", "texvc.phtml", $IP );
78
79 copydirectory( "./includes", $IP );
80 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
81
82 copyfile( "./images", "wiki.png", $wgUploadDirectory );
83 copyfile( "./languages", "Language.php", $IP );
84 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
85
86 $fp = fopen( $wgDebugLogFile, "w" );
87 if ( false === $fp ) {
88 print "Could not create log file \"{$wgDebugLogFile}\".\n";
89 exit();
90 }
91 $d = date( "Y-m-d H:i:s" );
92 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
93 fclose( $fp );
94
95 if ( $wgUseTeX ) {
96 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
97 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
98 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
99 }
100
101 copyfile( ".", "Version.php", $IP );
102
103 print "Done.\n";
104 exit();
105
106 #
107 #
108 #
109
110 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
111 global $wgInstallOwner, $wgInstallGroup;
112
113 $d = "{$ddir}/{$name}";
114 if ( copy( "{$sdir}/{$name}", $d ) ) {
115 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
116 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
117 chmod( $d, $perms );
118 # print "Copied \"{$name}\" to \"{$ddir}\".\n";
119 } else {
120 print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
121 exit();
122 }
123 }
124
125 function copydirectory( $source, $dest ) {
126 $handle = opendir( $source );
127 while ( false !== ( $f = readdir( $handle ) ) ) {
128 if ( "." == $f{0} ) continue;
129 # Windows turned all my CVS->cvs :(
130 if ( !strcasecmp ( "CVS", $f ) ) continue;
131 copyfile( $source, $f, $dest );
132 }
133 }
134
135 function readconsole() {
136 $fp = fopen( "php://stdin", "r" );
137 $resp = trim( fgets( $fp ) );
138 fclose( $fp );
139 return $resp;
140 }
141
142 function do_revision_updates() {
143 global $wgSoftwareRevision;
144 if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
145 }
146
147 function update_passwords() {
148 $fname = "Update script: update_passwords()";
149 print "\nIt appears that you need to update the user passwords in your\n" .
150 "database. If you have already done this (if you've run this update\n" .
151 "script once before, for example), doing so again will make all your\n" .
152 "user accounts inaccessible, so be sure you only do this once.\n" .
153 "Update user passwords? (yes/no)";
154
155 $resp = readconsole();
156 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
157
158 $sql = "SELECT user_id,user_password FROM user";
159 $source = wfQuery( $sql, DB_READ, fname );
160
161 while ( $row = mysql_fetch_object( $source ) ) {
162 $id = $row->user_id;
163 $oldpass = $row->user_password;
164 $newpass = md5( "{$id}-{$oldpass}" );
165
166 $sql = "UPDATE user SET user_password='{$newpass}' " .
167 "WHERE user_id={$id}";
168 wfQuery( $sql, DB_WRITE, $fname );
169 }
170 }
171
172 function alter_ipblocks() {
173 global $wgAlterSpecs;
174
175 if ( wfFieldExists( "ipblocks", "ipb_id" ) ) {
176 return;
177 }
178
179 if ( array_key_exists( "ipblocks", $wgAlterSpecs ) ) {
180 $wgAlterSpecs["ipblocks"] .= ",";
181 }
182
183 $wgAlterSpecs["ipblocks"] .=
184 "ADD ipb_auto tinyint(1) NOT NULL default '0', ".
185 "ADD ipb_id int(8) NOT NULL auto_increment,".
186 "ADD PRIMARY KEY (ipb_id)";
187 }
188
189 ?>