Update LocalSettings.php and LanguageUtf8.php on command-line update
[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( ".", "LocalSettings.php", $IP );
82 copyfile( ".", "index.php", $IP );
83 copyfile( ".", "redirect.php", $IP );
84 # compatibility with older versions, can be removed in a year or so
85 # (written in Feb 2004)
86 copyfile( ".", "wiki.phtml", $IP );
87 copyfile( ".", "redirect.phtml", $IP );
88
89 copydirectory( "./includes", $IP );
90 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
91
92 copyfile( "./images", "wiki.png", $wgUploadDirectory );
93 copyfile( "./images", "button_bold.png", $wgUploadDirectory );
94 copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
95 copyfile( "./images", "button_headline.png", $wgUploadDirectory );
96 copyfile( "./images", "button_hr.png", $wgUploadDirectory );
97 copyfile( "./images", "button_image.png", $wgUploadDirectory );
98 copyfile( "./images", "button_italic.png", $wgUploadDirectory );
99 copyfile( "./images", "button_link.png", $wgUploadDirectory );
100 copyfile( "./images", "button_math.png", $wgUploadDirectory );
101 copyfile( "./images", "button_media.png", $wgUploadDirectory );
102 copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
103 copyfile( "./images", "button_sig.png", $wgUploadDirectory );
104 copyfile( "./images", "button_template.png", $wgUploadDirectory );
105 copyfile( "./images", "magnify-clip.png", $wgUploadDirectory );
106
107 copyfile( "./languages", "Language.php", $IP );
108 copyfile( "./languages", "LanguageUtf8.php", $IP );
109 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
110
111 if( !empty( $wgDebugLogFile ) ) {
112 $fp = fopen( $wgDebugLogFile, "w" );
113 if ( false === $fp ) {
114 print "Could not create log file \"{$wgDebugLogFile}\".\n";
115 exit();
116 }
117 $d = date( "Y-m-d H:i:s" );
118 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
119 fclose( $fp );
120 }
121
122 if ( $wgUseTeX ) {
123 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
124 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
125 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
126 }
127
128 copyfile( ".", "Version.php", $IP );
129
130 print "ok\n";
131 }
132
133 function do_revision_updates() {
134 global $wgSoftwareRevision;
135 if ( $wgSoftwareRevision < 1001 ) {
136 update_passwords();
137 }
138 }
139
140 function update_passwords() {
141 global $wgDatabase;
142 $fname = "Update script: update_passwords()";
143 print "\nIt appears that you need to update the user passwords in your\n" .
144 "database. If you have already done this (if you've run this update\n" .
145 "script once before, for example), doing so again will make all your\n" .
146 "user accounts inaccessible, so be sure you only do this once.\n" .
147 "Update user passwords? (yes/no)";
148
149 $resp = readconsole();
150 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
151
152 $sql = "SELECT user_id,user_password FROM user";
153 $source = $wgDatabase->query( $sql, $fname );
154
155 while ( $row = $wgDatabase->fetchObject( $source ) ) {
156 $id = $row->user_id;
157 $oldpass = $row->user_password;
158 $newpass = md5( "{$id}-{$oldpass}" );
159
160 $sql = "UPDATE user SET user_password='{$newpass}' " .
161 "WHERE user_id={$id}";
162 $wgDatabase->query( $sql, $fname );
163 }
164 }
165
166 function do_ipblocks_update() {
167 global $wgDatabase;
168
169 $do1 = $do2 = false;
170
171 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) {
172 $do1 = true;
173 }
174 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_expiry" ) ) {
175 $do2 = true;
176 }
177
178 if ( $do1 || $do2 ) {
179 echo "Updating ipblocks table... ";
180 if ( $do1 ) {
181 dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase );
182 }
183 if ( $do2 ) {
184 dbsource( "maintenance/archives/patch-ipb_expiry.sql", $wgDatabase );
185 }
186 echo "ok\n";
187 } else {
188 echo "...ipblocks is up to date.\n";
189 }
190
191 }
192
193
194 function do_interwiki_update() {
195 # Check that interwiki table exists; if it doesn't source it
196 global $wgDatabase;
197 if( $wgDatabase->tableExists( "interwiki" ) ) {
198 echo "...already have interwiki table\n";
199 return true;
200 }
201 echo "Creating interwiki table: ";
202 dbsource( "maintenance/archives/patch-interwiki.sql" );
203 echo "ok\n";
204 echo "Adding default interwiki definitions: ";
205 dbsource( "maintenance/interwiki.sql" );
206 echo "ok\n";
207 }
208
209 function do_index_update() {
210 # Check that proper indexes are in place
211 global $wgDatabase;
212 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
213 if( $meta->multiple_key == 0 ) {
214 echo "Updating indexes to 20031107: ";
215 dbsource( "maintenance/archives/patch-indexes.sql" );
216 echo "ok\n";
217 return true;
218 }
219 echo "...indexes seem up to 20031107 standards\n";
220 return false;
221 }
222
223 function do_linkscc_update() {
224 // Create linkscc if necessary
225 global $wgDatabase;
226 if( $wgDatabase->tableExists( "linkscc" ) ) {
227 echo "...have linkscc table.\n";
228 } else {
229 echo "Adding linkscc table... ";
230 dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase );
231 echo "ok\n";
232 }
233 }
234
235 function do_hitcounter_update() {
236 // Create hitcounter if necessary
237 global $wgDatabase;
238 if( $wgDatabase->tableExists( "hitcounter" ) ) {
239 echo "...have hitcounter table.\n";
240 } else {
241 echo "Adding hitcounter table... ";
242 dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase );
243 echo "ok\n";
244 }
245 }
246
247 function do_recentchanges_update() {
248 global $wgDatabase;
249 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) {
250 echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title...";
251 dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase );
252 echo "ok\n";
253 }
254 }
255
256 ?>