* Recent Changes improvements: object oriented back end, move page annotation and...
[lhc/web/wiklou.git] / update.php
1 <?
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( ".", "wiki.phtml", $IP );
78 copyfile( ".", "redirect.phtml", $IP );
79 copyfile( ".", "texvc.phtml", $IP );
80
81 copydirectory( "./includes", $IP );
82 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
83
84 copyfile( "./images", "wiki.png", $wgUploadDirectory );
85 copyfile( "./languages", "Language.php", $IP );
86 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
87
88 if( !empty( $wgDebugLogFile ) ) {
89 $fp = fopen( $wgDebugLogFile, "w" );
90 if ( false === $fp ) {
91 print "Could not create log file \"{$wgDebugLogFile}\".\n";
92 exit();
93 }
94 $d = date( "Y-m-d H:i:s" );
95 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
96 fclose( $fp );
97 }
98
99 if ( $wgUseTeX ) {
100 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
101 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
102 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
103 }
104
105 copyfile( ".", "Version.php", $IP );
106
107 print "ok\n";
108 }
109
110 function do_revision_updates() {
111 global $wgSoftwareRevision;
112 if ( $wgSoftwareRevision < 1001 ) {
113 update_passwords();
114 }
115 }
116
117 function update_passwords() {
118 global $wgDatabase;
119 $fname = "Update script: update_passwords()";
120 print "\nIt appears that you need to update the user passwords in your\n" .
121 "database. If you have already done this (if you've run this update\n" .
122 "script once before, for example), doing so again will make all your\n" .
123 "user accounts inaccessible, so be sure you only do this once.\n" .
124 "Update user passwords? (yes/no)";
125
126 $resp = readconsole();
127 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
128
129 $sql = "SELECT user_id,user_password FROM user";
130 $source = $wgDatabase->query( $sql, $fname );
131
132 while ( $row = $wgDatabase->fetchObject( $source ) ) {
133 $id = $row->user_id;
134 $oldpass = $row->user_password;
135 $newpass = md5( "{$id}-{$oldpass}" );
136
137 $sql = "UPDATE user SET user_password='{$newpass}' " .
138 "WHERE user_id={$id}";
139 $wgDatabase->query( $sql, $fname );
140 }
141 }
142
143 function do_ipblocks_update() {
144 global $wgDatabase;
145 if ( $wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) {
146 echo "...ipblocks table is up to date.\n";
147 } else {
148 echo "Updating ipblocks table... ";
149 dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase );
150 echo "ok\n";
151 }
152 }
153
154
155 function do_interwiki_update() {
156 # Check that interwiki table exists; if it doesn't source it
157 global $wgDatabase;
158 if( $wgDatabase->tableExists( "interwiki" ) ) {
159 echo "...already have interwiki table\n";
160 return true;
161 }
162 echo "Creating interwiki table: ";
163 dbsource( "maintenance/archives/patch-interwiki.sql" );
164 echo "ok\n";
165 echo "Adding default interwiki definitions: ";
166 dbsource( "maintenance/interwiki.sql" );
167 echo "ok\n";
168 }
169
170 function do_index_update() {
171 # Check that proper indexes are in place
172 global $wgDatabase;
173 $meta = $wgDatabase->field_info( "recentchanges", "rc_timestamp" );
174 if( $meta->multiple_key == 0 ) {
175 echo "Updating indexes to 20031107: ";
176 dbsource( "maintenance/archives/patch-indexes.sql" );
177 echo "ok\n";
178 return true;
179 }
180 echo "...indexes seem up to 20031107 standards\n";
181 return false;
182 }
183
184 function do_linkscc_update() {
185 // Create linkscc if necessary
186 global $wgDatabase;
187 if( table_exists( "linkscc" ) ) {
188 echo "...have linkscc table.\n";
189 } else {
190 echo "Adding linkscc table... ";
191 dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase );
192 echo "ok\n";
193 }
194 }
195
196 function do_hitcounter_update() {
197 // Create hitcounter if necessary
198 global $wgDatabase;
199 if( $wgDatabase->tableExists( "hitcounter" ) ) {
200 echo "...have hitcounter table.\n";
201 } else {
202 echo "Adding hitcounter table... ";
203 dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase );
204 echo "ok\n";
205 }
206 }
207
208 function do_recentchanges_update() {
209 global $wgDatabase;
210 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) {
211 echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title...";
212 dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase );
213 echo "ok\n";
214 }
215 }
216
217 ?>