0a1a1e709f822218de22bba89e52faa02f1c52a3
[lhc/web/wiklou.git] / update.php
1 <?php
2
3 # Update already-installed software
4 #
5
6 include( "./install-utils.inc" );
7 install_version_checks();
8
9 if ( ! ( is_readable( "./LocalSettings.php" )
10 && is_readable( "./AdminSettings.php" ) ) ) {
11 print "A copy of your installation's LocalSettings.php\n" .
12 "and AdminSettings.php must exist in this source directory.\n";
13 exit();
14 }
15
16 $IP = "./includes";
17 include_once( "./LocalSettings.php" );
18 include_once( "./AdminSettings.php" );
19
20 include( "$IP/Version.php" );
21
22 if( $wgSitename == "MediaWiki" ) {
23 die( "You must set the site name in \$wgSitename before installation.\n\n" );
24 }
25
26 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
27 print "To use math functions, you must first compile texvc by\n" .
28 "running \"make\" in the math directory.\n";
29 exit();
30 }
31
32 #
33 # Copy files into installation directories
34 #
35 do_update_files();
36
37 $wgDBuser = $wgDBadminuser;
38 $wgDBpassword = $wgDBadminpassword;
39
40 include_once( "{$IP}/Setup.php" );
41 include_once( "./maintenance/InitialiseMessages.inc" );
42
43 $wgTitle = Title::newFromText( "Update script" );
44
45 #
46 # Check the database for things that need to be fixed...
47 #
48 print "Checking database for necessary updates...\n";
49
50 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname,
51 1, false, true, false);
52 if ( !$wgDatabase->isOpen() ) {
53 print "Unable to connect to database: " . $wgDatabase->lastError() . "\n";
54 exit();
55 }
56
57 do_revision_updates();
58
59 do_ipblocks_update();
60 do_interwiki_update();
61 do_index_update();
62 do_linkscc_update();
63 do_hitcounter_update();
64 do_recentchanges_update();
65
66 initialiseMessages();
67
68 $wgDatabase->close();
69
70 print "Done.\n";
71 exit();
72
73 #
74 #
75 #
76
77 function do_update_files() {
78 global $IP, $wgStyleSheetDirectory, $wgUploadDirectory, $wgLanguageCode, $wgDebugLogFile;
79 print "Copying files... ";
80
81 copyfile( ".", "index.php", $IP );
82 copyfile( ".", "redirect.php", $IP );
83 # compatibility with older versions, can be removed in a year or so
84 # (written in Feb 2004)
85 copyfile( ".", "wiki.phtml", $IP );
86 copyfile( ".", "redirect.phtml", $IP );
87
88 copydirectory( "./includes", $IP );
89 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
90
91 copyfile( "./images", "wiki.png", $wgUploadDirectory );
92 copyfile( "./images", "button_bold.png", $wgUploadDirectory );
93 copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
94 copyfile( "./images", "button_headline.png", $wgUploadDirectory );
95 copyfile( "./images", "button_hr.png", $wgUploadDirectory );
96 copyfile( "./images", "button_image.png", $wgUploadDirectory );
97 copyfile( "./images", "button_italic.png", $wgUploadDirectory );
98 copyfile( "./images", "button_link.png", $wgUploadDirectory );
99 copyfile( "./images", "button_math.png", $wgUploadDirectory );
100 copyfile( "./images", "button_media.png", $wgUploadDirectory );
101 copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
102 copyfile( "./images", "button_sig.png", $wgUploadDirectory );
103 copyfile( "./images", "button_template.png", $wgUploadDirectory );
104 copyfile( "./images", "magnify-clip.png", $wgUploadDirectory );
105
106 copyfile( "./languages", "Language.php", $IP );
107 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
108
109 if( !empty( $wgDebugLogFile ) ) {
110 $fp = fopen( $wgDebugLogFile, "w" );
111 if ( false === $fp ) {
112 print "Could not create log file \"{$wgDebugLogFile}\".\n";
113 exit();
114 }
115 $d = date( "Y-m-d H:i:s" );
116 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
117 fclose( $fp );
118 }
119
120 if ( $wgUseTeX ) {
121 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
122 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
123 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
124 }
125
126 copyfile( ".", "Version.php", $IP );
127
128 print "ok\n";
129 }
130
131 function do_revision_updates() {
132 global $wgSoftwareRevision;
133 if ( $wgSoftwareRevision < 1001 ) {
134 update_passwords();
135 }
136 }
137
138 function update_passwords() {
139 global $wgDatabase;
140 $fname = "Update script: update_passwords()";
141 print "\nIt appears that you need to update the user passwords in your\n" .
142 "database. If you have already done this (if you've run this update\n" .
143 "script once before, for example), doing so again will make all your\n" .
144 "user accounts inaccessible, so be sure you only do this once.\n" .
145 "Update user passwords? (yes/no)";
146
147 $resp = readconsole();
148 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
149
150 $sql = "SELECT user_id,user_password FROM user";
151 $source = $wgDatabase->query( $sql, $fname );
152
153 while ( $row = $wgDatabase->fetchObject( $source ) ) {
154 $id = $row->user_id;
155 $oldpass = $row->user_password;
156 $newpass = md5( "{$id}-{$oldpass}" );
157
158 $sql = "UPDATE user SET user_password='{$newpass}' " .
159 "WHERE user_id={$id}";
160 $wgDatabase->query( $sql, $fname );
161 }
162 }
163
164 function do_ipblocks_update() {
165 global $wgDatabase;
166
167 $do1 = $do2 = false;
168
169 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) {
170 $do1 = true;
171 }
172 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_expiry" ) ) {
173 $do2 = true;
174 }
175
176 if ( $do1 || $do2 ) {
177 echo "Updating ipblocks table... ";
178 if ( $do1 ) {
179 dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase );
180 }
181 if ( $do2 ) {
182 dbsource( "maintenance/archives/patch-ipb_expiry.sql", $wgDatabase );
183 }
184 echo "ok\n";
185 } else {
186 echo "...ipblocks is up to date.\n";
187 }
188
189 }
190
191
192 function do_interwiki_update() {
193 # Check that interwiki table exists; if it doesn't source it
194 global $wgDatabase;
195 if( $wgDatabase->tableExists( "interwiki" ) ) {
196 echo "...already have interwiki table\n";
197 return true;
198 }
199 echo "Creating interwiki table: ";
200 dbsource( "maintenance/archives/patch-interwiki.sql" );
201 echo "ok\n";
202 echo "Adding default interwiki definitions: ";
203 dbsource( "maintenance/interwiki.sql" );
204 echo "ok\n";
205 }
206
207 function do_index_update() {
208 # Check that proper indexes are in place
209 global $wgDatabase;
210 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
211 if( $meta->multiple_key == 0 ) {
212 echo "Updating indexes to 20031107: ";
213 dbsource( "maintenance/archives/patch-indexes.sql" );
214 echo "ok\n";
215 return true;
216 }
217 echo "...indexes seem up to 20031107 standards\n";
218 return false;
219 }
220
221 function do_linkscc_update() {
222 // Create linkscc if necessary
223 global $wgDatabase;
224 if( $wgDatabase->tableExists( "linkscc" ) ) {
225 echo "...have linkscc table.\n";
226 } else {
227 echo "Adding linkscc table... ";
228 dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase );
229 echo "ok\n";
230 }
231 }
232
233 function do_hitcounter_update() {
234 // Create hitcounter if necessary
235 global $wgDatabase;
236 if( $wgDatabase->tableExists( "hitcounter" ) ) {
237 echo "...have hitcounter table.\n";
238 } else {
239 echo "Adding hitcounter table... ";
240 dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase );
241 echo "ok\n";
242 }
243 }
244
245 function do_recentchanges_update() {
246 global $wgDatabase;
247 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) {
248 echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title...";
249 dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase );
250 echo "ok\n";
251 }
252 }
253
254 ?>