Add xml header (redundant but nice) and correct xml:lang tag
[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 $rconn = mysql_connect( $wgDBserver, $wgDBadminuser, $wgDBadminpassword );
47 mysql_select_db( $wgDBname );
48
49 do_revision_updates();
50
51 do_ipblocks_update();
52 do_interwiki_update();
53 do_index_update();
54 do_linkscc_update();
55
56 initialiseMessages();
57
58 mysql_close( $rconn );
59
60 print "Done.\n";
61 exit();
62
63 #
64 #
65 #
66
67 function do_update_files() {
68 global $IP, $wgStyleSheetDirectory, $wgUploadDirectory, $wgLanguageCode, $wgDebugLogFile;
69 print "Copying files... ";
70
71 copyfile( ".", "wiki.phtml", $IP );
72 copyfile( ".", "redirect.phtml", $IP );
73 copyfile( ".", "texvc.phtml", $IP );
74
75 copydirectory( "./includes", $IP );
76 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
77
78 copyfile( "./images", "wiki.png", $wgUploadDirectory );
79 copyfile( "./languages", "Language.php", $IP );
80 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
81
82 $fp = fopen( $wgDebugLogFile, "w" );
83 if ( false === $fp ) {
84 print "Could not create log file \"{$wgDebugLogFile}\".\n";
85 exit();
86 }
87 $d = date( "Y-m-d H:i:s" );
88 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
89 fclose( $fp );
90
91 if ( $wgUseTeX ) {
92 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
93 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
94 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
95 }
96
97 copyfile( ".", "Version.php", $IP );
98
99 print "ok\n";
100 }
101
102 function do_revision_updates() {
103 global $wgSoftwareRevision;
104 if ( $wgSoftwareRevision < 1001 ) {
105 update_passwords();
106 }
107 }
108
109 function update_passwords() {
110 $fname = "Update script: update_passwords()";
111 print "\nIt appears that you need to update the user passwords in your\n" .
112 "database. If you have already done this (if you've run this update\n" .
113 "script once before, for example), doing so again will make all your\n" .
114 "user accounts inaccessible, so be sure you only do this once.\n" .
115 "Update user passwords? (yes/no)";
116
117 $resp = readconsole();
118 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
119
120 $sql = "SELECT user_id,user_password FROM user";
121 $source = wfQuery( $sql, DB_READ, fname );
122
123 while ( $row = mysql_fetch_object( $source ) ) {
124 $id = $row->user_id;
125 $oldpass = $row->user_password;
126 $newpass = md5( "{$id}-{$oldpass}" );
127
128 $sql = "UPDATE user SET user_password='{$newpass}' " .
129 "WHERE user_id={$id}";
130 wfQuery( $sql, DB_WRITE, $fname );
131 }
132 }
133
134 function do_ipblocks_update() {
135 if ( wfFieldExists( "ipblocks", "ipb_id" ) ) {
136 echo "...ipblocks table is up to date.\n";
137 } else {
138 echo "Updating ipblocks table... ";
139 dbsource( "maintenance/archives/patch-ipblocks.sql" );
140 echo "ok\n";
141 }
142 }
143
144
145 function do_interwiki_update() {
146 # Check that interwiki table exists; if it doesn't source it
147 if( table_exists( "interwiki" ) ) {
148 echo "...already have interwiki table\n";
149 return true;
150 }
151 echo "Creating interwiki table: ";
152 dbsource( "maintenance/archives/patch-interwiki.sql" );
153 echo "ok\n";
154 echo "Adding default interwiki definitions: ";
155 dbsource( "maintenance/interwiki.sql" );
156 echo "ok\n";
157 }
158
159 function do_index_update() {
160 # Check that proper indexes are in place
161 $meta = field_info( "recentchanges", "rc_timestamp" );
162 if( $meta->multiple_key == 0 ) {
163 echo "Updating indexes to 20031107: ";
164 dbsource( "maintenance/archives/patch-indexes.sql" );
165 echo "ok\n";
166 return true;
167 }
168 echo "...indexes seem up to 20031107 standards\n";
169 return false;
170 }
171
172 function do_linkscc_update() {
173 // Create linkscc if necessary
174 global $rconn;
175 if( table_exists( "linkscc" ) ) {
176 echo "...have linkscc table.\n";
177 } else {
178 echo "Adding linkscc table... ";
179 dbsource( "maintenance/archives/patch-linkscc.sql" );
180 echo "ok\n";
181 }
182 }
183
184
185 ?>