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