From ba780a4674c0d6f7d1bdcc6fbe7ff3dc91298248 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 24 Jun 2003 19:27:21 +0000 Subject: [PATCH] Add optional log for AskSql queries --- includes/DefaultSettings.php | 2 ++ includes/SpecialAsksql.php | 33 ++++++++++++++++++++++++++++++++- languages/Language.php | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index dccc36a351..926cf8498e 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -55,6 +55,8 @@ $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR"; $wgDebugLogFile = "{$wgUploadDirectory}/log_dlJbnMZb"; $wgDebugComments = false; $wgReadOnly = false; +$wgSqlLogFile = "{$wgUploadDirectory}/sqllog_mFhyRe6"; +$wgLogQueries = false; # Client-side caching: $wgCachePages = true; # Allow client-side caching of pages diff --git a/includes/SpecialAsksql.php b/includes/SpecialAsksql.php index 34403c389c..062e1c1a28 100644 --- a/includes/SpecialAsksql.php +++ b/includes/SpecialAsksql.php @@ -22,9 +22,13 @@ class SqlQueryForm { { global $wgOut, $wgUser, $wgLang; global $wpSqlQuery; + global $wgLogQueries; $wgOut->setPagetitle( wfMsg( "asksql" ) ); - $wgOut->addWikiText( wfMsg( "asksqltext" ) ); + $note = wfMsg( "asksqltext" ); + if($wgLogQueries) + $note .= " " . wfMsg( "sqlislogged" ); + $wgOut->addWikiText( $note ); if ( "" != $err ) { $wgOut->addHTML( "

" . htmlspecialchars($err) . "\n" ); @@ -67,7 +71,9 @@ class SqlQueryForm { if ( ! $wgUser->isDeveloper() ) { $connection = wfGetDB( $wgDBsqluser, $wgDBsqlpassword ); } + $this->logQuery( $wpSqlQuery ); $res = wfQuery( $wpSqlQuery, "SpecialAsksql::doSubmit" ); + $this->logFinishedQuery(); $n = 0; @$n = wfNumFields( $res ); @@ -112,6 +118,31 @@ class SqlQueryForm { $wgOut->addHTML( "


{$r}\n" ); } + function logQuery( $q ) { + global $wgSqlLogFile, $wgLogQueries, $wgUser; + if(!$wgLogQueries) return; + + $f = fopen( $wgSqlLogFile, "a" ); + fputs( $f, "\n\n" . wfTimestampNow() . + " query by " . $wgUser->getName() . + ":\n$q\n" ); + fclose( $f ); + $this->starttime = microtime(); + } + + function logFinishedQuery() { + global $wgSqlLogFile, $wgLogQueries; + if(!$wgLogQueries) return; + + list($sec, $usec) = explode( " ", microtime() ); + list($sec1, $usec1) = explode( " ", $this->starttime ); + $interval = ($sec + $usec) - ($sec1 + $usec1); + + $f = fopen( $wgSqlLogFile, "a" ); + fputs( $f, "finished at " . wfTimestampNow() . "; took $interval secs\n" ); + fclose( $f ); + } + } ?> diff --git a/languages/Language.php b/languages/Language.php index fa95c282f2..9c61084805 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1024,6 +1024,7 @@ Wikipedia database. Use single quotes ('like this') to delimit string literals. This can often add considerable load to the server, so please use this function sparingly.", +"sqlislogged" => "Please note that all queries are logged.", "sqlquery" => "Enter query", "querybtn" => "Submit query", "selectonly" => "Queries other than \"SELECT\" are restricted to -- 2.20.1