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