Purging of scaled images when thumbnail is regenerated. Depends on visiting the page...
[mediawiki.git] / update.php
blobe4ae1874d074f0e1786da30c8878af41c2cb24cf
1 <?php
3 # Update already-installed software
6 include( "./install-utils.inc" );
7 install_version_checks();
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();
16 $IP = "./includes";
17 include_once( "./LocalSettings.php" );
18 include_once( "./AdminSettings.php" );
20 include( "$IP/Version.php" );
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();
29 # Copy files into installation directories
31 do_update_files();
33 $wgDBuser = $wgDBadminuser;
34 $wgDBpassword = $wgDBadminpassword;
36 include_once( "{$IP}/Setup.php" );
37 include_once( "./maintenance/InitialiseMessages.inc" );
39 $wgTitle = Title::newFromText( "Update script" );
42 # Check the database for things that need to be fixed...
44 print "Checking database for necessary updates...\n";
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();
53 do_revision_updates();
55 do_ipblocks_update();
56 do_interwiki_update();
57 do_index_update();
58 do_linkscc_update();
59 do_hitcounter_update();
60 do_recentchanges_update();
62 initialiseMessages();
64 $wgDatabase->close();
66 print "Done.\n";
67 exit();
73 function do_update_files() {
74 global $IP, $wgStyleSheetDirectory, $wgUploadDirectory, $wgLanguageCode, $wgDebugLogFile;
75 print "Copying files... ";
77 copyfile( ".", "wiki.phtml", $IP );
78 copyfile( ".", "redirect.phtml", $IP );
79 copyfile( ".", "texvc.phtml", $IP );
81 copydirectory( "./includes", $IP );
82 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
84 copyfile( "./images", "wiki.png", $wgUploadDirectory );
85 copyfile( "./images", "button_bold.gif", $wgUploadDirectory );
86 copyfile( "./images", "button_extlink.gif", $wgUploadDirectory );
87 copyfile( "./images", "button_headline.gif", $wgUploadDirectory );
88 copyfile( "./images", "button_hr.gif", $wgUploadDirectory );
89 copyfile( "./images", "button_image.gif", $wgUploadDirectory );
90 copyfile( "./images", "button_italic.gif", $wgUploadDirectory );
91 copyfile( "./images", "button_link.gif", $wgUploadDirectory );
92 copyfile( "./images", "button_math.gif", $wgUploadDirectory );
93 copyfile( "./images", "button_media.gif", $wgUploadDirectory );
94 copyfile( "./images", "button_sig.gif", $wgUploadDirectory );
95 copyfile( "./images", "button_template.gif", $wgUploadDirectory );
97 copyfile( "./languages", "Language.php", $IP );
98 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
100 if( !empty( $wgDebugLogFile ) ) {
101 $fp = fopen( $wgDebugLogFile, "w" );
102 if ( false === $fp ) {
103 print "Could not create log file \"{$wgDebugLogFile}\".\n";
104 exit();
106 $d = date( "Y-m-d H:i:s" );
107 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
108 fclose( $fp );
111 if ( $wgUseTeX ) {
112 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
113 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
114 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
117 copyfile( ".", "Version.php", $IP );
119 print "ok\n";
122 function do_revision_updates() {
123 global $wgSoftwareRevision;
124 if ( $wgSoftwareRevision < 1001 ) {
125 update_passwords();
129 function update_passwords() {
130 global $wgDatabase;
131 $fname = "Update script: update_passwords()";
132 print "\nIt appears that you need to update the user passwords in your\n" .
133 "database. If you have already done this (if you've run this update\n" .
134 "script once before, for example), doing so again will make all your\n" .
135 "user accounts inaccessible, so be sure you only do this once.\n" .
136 "Update user passwords? (yes/no)";
138 $resp = readconsole();
139 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
141 $sql = "SELECT user_id,user_password FROM user";
142 $source = $wgDatabase->query( $sql, $fname );
144 while ( $row = $wgDatabase->fetchObject( $source ) ) {
145 $id = $row->user_id;
146 $oldpass = $row->user_password;
147 $newpass = md5( "{$id}-{$oldpass}" );
149 $sql = "UPDATE user SET user_password='{$newpass}' " .
150 "WHERE user_id={$id}";
151 $wgDatabase->query( $sql, $fname );
155 function do_ipblocks_update() {
156 global $wgDatabase;
158 $do1 = $do2 = false;
160 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) {
161 $do1 = true;
163 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_expiry" ) ) {
164 $do2 = true;
167 if ( $do1 || $do2 ) {
168 echo "Updating ipblocks table... ";
169 if ( $do1 ) {
170 dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase );
172 if ( $do2 ) {
173 dbsource( "maintenance/archives/patch-ipb_expiry.sql", $wgDatabase );
175 echo "ok\n";
176 } else {
177 echo "...ipblocks is up to date.\n";
183 function do_interwiki_update() {
184 # Check that interwiki table exists; if it doesn't source it
185 global $wgDatabase;
186 if( $wgDatabase->tableExists( "interwiki" ) ) {
187 echo "...already have interwiki table\n";
188 return true;
190 echo "Creating interwiki table: ";
191 dbsource( "maintenance/archives/patch-interwiki.sql" );
192 echo "ok\n";
193 echo "Adding default interwiki definitions: ";
194 dbsource( "maintenance/interwiki.sql" );
195 echo "ok\n";
198 function do_index_update() {
199 # Check that proper indexes are in place
200 global $wgDatabase;
201 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
202 if( $meta->multiple_key == 0 ) {
203 echo "Updating indexes to 20031107: ";
204 dbsource( "maintenance/archives/patch-indexes.sql" );
205 echo "ok\n";
206 return true;
208 echo "...indexes seem up to 20031107 standards\n";
209 return false;
212 function do_linkscc_update() {
213 // Create linkscc if necessary
214 global $wgDatabase;
215 if( $wgDatabase->tableExists( "linkscc" ) ) {
216 echo "...have linkscc table.\n";
217 } else {
218 echo "Adding linkscc table... ";
219 dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase );
220 echo "ok\n";
224 function do_hitcounter_update() {
225 // Create hitcounter if necessary
226 global $wgDatabase;
227 if( $wgDatabase->tableExists( "hitcounter" ) ) {
228 echo "...have hitcounter table.\n";
229 } else {
230 echo "Adding hitcounter table... ";
231 dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase );
232 echo "ok\n";
236 function do_recentchanges_update() {
237 global $wgDatabase;
238 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) {
239 echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title...";
240 dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase );
241 echo "ok\n";