3 if (!extension_loaded('mysql')) {
5 print "Could not load MySQL driver! Please compile ".
6 "php --with-mysql or install the mysql.so module.\n";
10 # Install software and create new empty database.
13 if ( ! ( is_readable( "./LocalSettings.php" )
14 && is_readable( "./AdminSettings.php" ) ) ) {
15 print "You must first create the files LocalSettings.php\n" .
16 "and AdminSettings.php based on the samples in the top\n" .
17 "source directory before running this install script.\n";
22 include_once( "./LocalSettings.php" );
23 include_once( "./AdminSettings.php" );
25 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
26 print "To use math functions, you must first compile texvc by\n" .
27 "running \"make\" in the math directory.\n";
30 if ( is_file( "{$IP}/Version.php" ) ) {
31 print "There appears to be an installation of the software\n" .
32 "already present on \"{$IP}\". You may want to run the update\n" .
33 "script instead. If you continue with this installation script,\n" .
34 "that software and all of its data will be overwritten.\n" .
35 "Are you sure you want to do this? (yes/no) ";
37 $response = readconsole();
38 if ( ! ( "Y" == $response{0} ||
"y" == $response{0} ) ) { exit(); }
41 $wgCommandLineMode = true;
46 # Make the necessary directories
48 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
49 foreach ( $dirs as $d ) { makedirectory( $d ); }
52 # Copy files into installation directories
54 print "Copying files...\n";
56 copyfile( ".", "LocalSettings.php", $IP );
57 copyfile( ".", "Version.php", $IP );
58 copyfile( ".", "wiki.phtml", $IP );
59 copyfile( ".", "redirect.phtml", $IP );
60 copyfile( ".", "texvc.phtml", $IP );
62 copydirectory( "./includes", $IP );
63 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
65 copyfile( "./images", "wiki.png", $wgUploadDirectory );
66 copyfile( "./languages", "Language.php", $IP );
67 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
69 $fp = fopen( $wgDebugLogFile, "w" );
70 if ( false === $fp ) {
71 print "Could not create log file \"{$wgDebugLogFile}\".\n";
74 $d = date( "Y-m-d H:i:s" );
75 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
79 makedirectory( "{$IP}/math" );
80 makedirectory( $wgMathDirectory );
81 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
82 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
83 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
86 copyfile( ".", "Version.php", $IP );
89 # Make and initialize database
91 print "\n* * *\nWarning! This script will completely erase the\n" .
92 "existing database \"{$wgDBname}\" and all its contents.\n" .
93 "Are you sure you want to do this? (yes/no) ";
95 $response = readconsole();
96 if ( ! ( "Y" == $response{0} ||
"y" == $response{0} ) ) { exit(); }
98 print "\nYou should have already created a root password for the database.\n" .
99 "Enter the root password here: ";
101 $rootpw = readconsole();
103 $rconn = mysql_connect( $wgDBserver, "root", $rootpw );
104 if ( false === $rconn ) {
105 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
109 # Include rest of code to get things like internationalized messages.
111 include_once( "{$IP}/Setup.php" );
112 $wgTitle = Title
::newFromText( "Installation script" );
114 # Now do the actual database creation
116 print "Creating database...\n";
117 dbsource( $rconn, "./maintenance/database.sql" );
119 mysql_select_db( $wgDBname, $rconn );
120 dbsource( $rconn, "./maintenance/tables.sql" );
121 dbsource( $rconn, "./maintenance/users.sql" );
122 dbsource( $rconn, "./maintenance/initialdata.sql" );
124 populatedata(); # Needs internationalized messages
126 print "Adding indexes...\n";
127 dbsource( $rconn, "./maintenance/indexes.sql" );
129 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test,\n" .
130 "or \"run WikiSuite -b -o\" in test suite.\n";
134 # Functions used above:
136 function makedirectory( $d ) {
137 global $wgInstallOwner, $wgInstallGroup;
139 if ( is_dir( $d ) ) {
140 print "Directory \"{$d}\" exists.\n";
142 if ( mkdir( $d, 0777 ) ) {
143 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
144 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
145 print "Directory \"{$d}\" created.\n";
147 print "Could not create directory \"{$d}\".\n";
153 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
154 global $wgInstallOwner, $wgInstallGroup;
156 $d = "{$ddir}/{$name}";
157 if ( copy( "{$sdir}/{$name}", $d ) ) {
158 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
159 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
161 # print "Copied \"{$name}\" to \"{$ddir}\".\n";
163 print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
168 function copydirectory( $source, $dest ) {
169 $handle = opendir( $source );
170 while ( false !== ( $f = readdir( $handle ) ) ) {
171 if ( "." == $f{0} ) continue;
172 if ( "CVS" == $f ) continue;
173 copyfile( $source, $f, $dest );
177 function readconsole() {
178 $fp = fopen( "php://stdin", "r" );
179 $resp = trim( fgets( $fp, 1024 ) );
185 # Read and execute SQL commands from a file
187 function dbsource( $conn, $fname ) {
188 $fp = fopen( $fname, "r" );
189 if ( false === $fp ) {
190 print "Could not open \"{$fname}\".\n";
197 while ( ! feof( $fp ) ) {
198 $line = trim( fgets( $fp, 1024 ) );
199 $sl = strlen( $line ) - 1;
201 if ( $sl < 0 ) { continue; }
202 if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
204 if ( ";" == $line{$sl} ) {
206 $line = substr( $line, 0, $sl );
209 if ( "" != $cmd ) { $cmd .= " "; }
213 $cmd = replacevars( $cmd );
214 $res = mysql_query( $cmd, $conn );
216 if ( false === $res ) {
217 print "Query \"{$cmd}\" failed.\n";
228 function replacevars( $ins ) {
230 "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
231 "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
232 "wgDBadminuser", "wgDBadminpassword"
235 foreach ( $varnames as $var ) {
237 $ins = str_replace( '{$' . $var . '}', $
$var, $ins );
242 function populatedata() {
243 global $wgDBadminpassword;
244 $fname = "Installation script: populatedata()";
246 $sql = "DELETE FROM site_stats";
247 wfQuery( $sql, $fname );
249 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
250 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
251 wfQuery( $sql, $fname );
253 $sql = "DELETE FROM user";
254 wfQuery( $sql, $fname );
256 $u = User
::newFromName( "WikiSysop" );
257 if ( 0 == $u->idForName() ) {
259 $u->setPassword( $wgDBadminpassword );
260 $u->addRight( "sysop" );
263 $u = User
::newFromName( "WikiDeveloper" );
264 if ( 0 == $u->idForName() ) {
266 $u->setPassword( $wgDBadminpassword );
267 $u->addRight( "sysop" );
268 $u->addRight( "developer" );
272 $wns = Namespace::getWikipedia();
273 $ulp = addslashes( wfMsg( "uploadlogpage" ) );
274 $dlp = addslashes( wfMsg( "dellogpage" ) );
276 $sql = "DELETE FROM cur";
277 wfQuery( $sql, $fname );
279 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
280 "cur_restrictions) VALUES ({$wns},'{$ulp}','" .
281 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop')";
284 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
285 "cur_restrictions) VALUES ({$wns},'{$dlp}','" .
286 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop')";
289 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text) " .
290 "VALUES (0,'" . wfStrencode( wfMsg( "mainpage" ) ) . "','" .
291 wfStrencode( wfMsg( "mainpagetext" ) ) . "')";