Add optional log for AskSql queries
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 24 Jun 2003 19:27:21 +0000 (19:27 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 24 Jun 2003 19:27:21 +0000 (19:27 +0000)
includes/DefaultSettings.php
includes/SpecialAsksql.php
languages/Language.php

index dccc36a..926cf84 100644 (file)
@@ -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
index 34403c3..062e1c1 100644 (file)
@@ -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( "<p><font color='red' size='+1'>" . htmlspecialchars($err) . "</font>\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( "<hr>{$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 );
+       }
+
 }
 
 ?>
index fa95c28..9c61084 100644 (file)
@@ -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