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