update now creates linkscc table (used by PersistentLC)
[lhc/web/wiklou.git] / update.php
1 <?
2
3 if( !function_exists( "version_compare" ) ) {
4 # version_compare was introduced in 4.1.0
5 die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
6 }
7 if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
8 echo "WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up may work but are not actively supported.\n\n";
9 }
10 if( !ini_get( "register_globals" ) ) {
11 echo "WARNING: register_globals is not on; MediaWiki currently relies on this option.\n\n";
12 }
13
14 # Update already-installed software
15 #
16
17 if ( ! ( is_readable( "./LocalSettings.php" )
18 && is_readable( "./AdminSettings.php" ) ) ) {
19 print "A copy of your installation's LocalSettings.php\n" .
20 "and AdminSettings.php must exist in this source directory.\n";
21 exit();
22 }
23
24 $IP = "./includes";
25 include_once( "./LocalSettings.php" );
26 include_once( "./AdminSettings.php" );
27
28 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
29 print "To use math functions, you must first compile texvc by\n" .
30 "running \"make\" in the math directory.\n";
31 exit();
32 }
33
34 umask( 000 );
35 set_time_limit( 0 );
36
37 include_once( "Version.php" );
38 include_once( "{$IP}/Setup.php" );
39 include_once( "./maintenance/InitialiseMessages.inc" );
40
41 $wgTitle = Title::newFromText( "Update script" );
42 $wgCommandLineMode = true;
43 $wgAlterSpecs = array();
44
45 do_revision_updates();
46 alter_ipblocks();
47 initialiseMessages();
48
49 #
50 # Run ALTER TABLE queries.
51 #
52 if ( count( $wgAlterSpecs ) ) {
53 $rconn = mysql_connect( $wgDBserver, $wgDBadminuser, $wgDBadminpassword );
54 mysql_select_db( $wgDBname );
55 print "\n";
56 foreach ( $wgAlterSpecs as $table => $specs ) {
57 $sql = "ALTER TABLE $table $specs";
58 print "$sql;\n";
59 $res = mysql_query( $sql, $rconn );
60 if ( $res === false ) {
61 print "MySQL error: " . mysql_error( $rconn ) . "\n";
62 }
63 }
64 mysql_close( $rconn );
65 }
66
67 { // Create linkscc if necessary
68 $sql = "CREATE TABLE IF NOT EXISTS linkscc (".
69 " lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY, ".
70 " lcc_title VARCHAR(255) NOT NULL UNIQUE KEY,".
71 " lcc_cacheobj MEDIUMBLOB NOT NULL)";
72 // Should it be created as InnoDB?
73 $rconn = mysql_connect( $wgDBserver, $wgDBadminuser, $wgDBadminpassword );
74 mysql_select_db( $wgDBname );
75 print "\n$sql;\n";
76 $res = mysql_query( $sql, $rconn );
77 if ( $res === false ) {
78 print "MySQL error: " . mysql_error( $rconn ) . "\n";
79 }
80 mysql_close( $rconn );
81 }
82
83
84
85
86
87 #
88 # Copy files into installation directories
89 #
90 print "Copying files...\n";
91
92 copyfile( ".", "wiki.phtml", $IP );
93 copyfile( ".", "redirect.phtml", $IP );
94 copyfile( ".", "texvc.phtml", $IP );
95
96 copydirectory( "./includes", $IP );
97 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
98
99 copyfile( "./images", "wiki.png", $wgUploadDirectory );
100 copyfile( "./languages", "Language.php", $IP );
101 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
102
103 $fp = fopen( $wgDebugLogFile, "w" );
104 if ( false === $fp ) {
105 print "Could not create log file \"{$wgDebugLogFile}\".\n";
106 exit();
107 }
108 $d = date( "Y-m-d H:i:s" );
109 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
110 fclose( $fp );
111
112 if ( $wgUseTeX ) {
113 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
114 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
115 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
116 }
117
118 copyfile( ".", "Version.php", $IP );
119
120 print "Done.\n";
121 exit();
122
123 #
124 #
125 #
126
127 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
128 global $wgInstallOwner, $wgInstallGroup;
129
130 $d = "{$ddir}/{$name}";
131 if ( copy( "{$sdir}/{$name}", $d ) ) {
132 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
133 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
134 chmod( $d, $perms );
135 # print "Copied \"{$name}\" to \"{$ddir}\".\n";
136 } else {
137 print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
138 exit();
139 }
140 }
141
142 function copydirectory( $source, $dest ) {
143 $handle = opendir( $source );
144 while ( false !== ( $f = readdir( $handle ) ) ) {
145 if ( "." == $f{0} ) continue;
146 # Windows turned all my CVS->cvs :(
147 if ( !strcasecmp ( "CVS", $f ) ) continue;
148 copyfile( $source, $f, $dest );
149 }
150 }
151
152 function readconsole() {
153 $fp = fopen( "php://stdin", "r" );
154 $resp = trim( fgets( $fp, 1024 ) );
155 fclose( $fp );
156 return $resp;
157 }
158
159 function do_revision_updates() {
160 global $wgSoftwareRevision;
161 if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
162 }
163
164 function update_passwords() {
165 $fname = "Update script: update_passwords()";
166 print "\nIt appears that you need to update the user passwords in your\n" .
167 "database. If you have already done this (if you've run this update\n" .
168 "script once before, for example), doing so again will make all your\n" .
169 "user accounts inaccessible, so be sure you only do this once.\n" .
170 "Update user passwords? (yes/no)";
171
172 $resp = readconsole();
173 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
174
175 $sql = "SELECT user_id,user_password FROM user";
176 $source = wfQuery( $sql, DB_READ, fname );
177
178 while ( $row = mysql_fetch_object( $source ) ) {
179 $id = $row->user_id;
180 $oldpass = $row->user_password;
181 $newpass = md5( "{$id}-{$oldpass}" );
182
183 $sql = "UPDATE user SET user_password='{$newpass}' " .
184 "WHERE user_id={$id}";
185 wfQuery( $sql, DB_WRITE, $fname );
186 }
187 }
188
189 function alter_ipblocks() {
190 global $wgAlterSpecs;
191
192 if ( wfFieldExists( "ipblocks", "ipb_id" ) ) {
193 return;
194 }
195
196 if ( array_key_exists( "ipblocks", $wgAlterSpecs ) ) {
197 $wgAlterSpecs["ipblocks"] .= ",";
198 }
199
200 $wgAlterSpecs["ipblocks"] .=
201 "ADD ipb_auto tinyint(1) NOT NULL default '0', ".
202 "ADD ipb_id int(8) NOT NULL auto_increment,".
203 "ADD PRIMARY KEY (ipb_id)";
204 }
205
206 ?>