-function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
- global $wgInstallOwner, $wgInstallGroup;
-
- $d = "{$ddir}/{$name}";
- if ( copy( "{$sdir}/{$name}", $d ) ) {
- if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
- if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
- chmod( $d, $perms );
- # print "Copied \"{$name}\" to \"{$ddir}\".\n";
- } else {
- print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
- exit();
- }
-}
-
-function copydirectory( $source, $dest ) {
- $handle = opendir( $source );
- while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- if ( "CVS" == $f ) continue;
- copyfile( $source, $f, $dest );
- }
-}
-
-function readconsole() {
- $fp = fopen( "php://stdin", "r" );
- $resp = trim( fgets( $fp, 1024 ) );
- fclose( $fp );
- return $resp;
-}
-
-#
-# Read and execute SQL commands from a file
-#
-function dbsource( $conn, $fname ) {
- $fp = fopen( $fname, "r" );
- if ( false === $fp ) {
- print "Could not open \"{$fname}\".\n";
- exit();
- }
-
- $cmd = "";
- $done = false;
-
- while ( ! feof( $fp ) ) {
- $line = trim( fgets( $fp, 1024 ) );
- $sl = strlen( $line ) - 1;
-
- if ( $sl < 0 ) { continue; }
- if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
-
- if ( ";" == $line{$sl} ) {
- $done = true;
- $line = substr( $line, 0, $sl );
- }
-
- if ( "" != $cmd ) { $cmd .= " "; }
- $cmd .= $line;
-
- if ( $done ) {
- $cmd = replacevars( $cmd );
- $res = mysql_query( $cmd, $conn );
-
- if ( false === $res ) {
- print "Query \"{$cmd}\" failed.\n";
- exit();
- }
-
- $cmd = "";
- $done = false;
- }
- }
- fclose( $fp );
-}
-
-function replacevars( $ins ) {
- $varnames = array(
- "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
- "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
- "wgDBadminuser", "wgDBadminpassword"
- );
-
- foreach ( $varnames as $var ) {
- global $$var;
- $ins = str_replace( '{$' . $var . '}', $$var, $ins );
- }
- return $ins;
-}