function wfSpecialAsksql() { global $wgUser, $wgOut, $action; if ( ! $wgUser->isSysop() ) { $wgOut->sysopRequired(); return; } $fields = array( "wpSqlQuery" ); wfCleanFormFields( $fields ); $f = new SqlQueryForm(); if ( "submit" == $action ) { $f->doSubmit(); } else { $f->showForm( "" ); } } class SqlQueryForm { function showForm( $err ) { global $wgOut, $wgUser, $wgLang; global $wpSqlQuery; global $wgLogQueries; $wgOut->setPagetitle( wfMsg( "asksql" ) ); $note = wfMsg( "asksqltext" ); if($wgLogQueries) $note .= " " . wfMsg( "sqlislogged" ); $wgOut->addWikiText( $note ); if ( "" != $err ) { $wgOut->addHTML( "
" . htmlspecialchars($err) . "\n" ); } if ( ! $wpSqlQuery ) { $wpSqlQuery = "SELECT ... FROM ... WHERE ..."; } $q = wfMsg( "sqlquery" ); $qb = wfMsg( "querybtn" ); $action = wfLocalUrlE( $wgLang->specialPage( "Asksql" ), "action=submit" ); $wgOut->addHTML( "
\n" ); } function doSubmit() { global $wgOut, $wgUser, $wgServer, $wgScript, $wgArticlePath, $wgLang; global $wpSqlQuery; global $wgDBsqluser, $wgDBsqlpassword; # Use a limit, folks! $wpSqlQuery = trim( $wpSqlQuery ); if( preg_match( "/^SELECT/i", $wpSqlQuery ) and !preg_match( "/LIMIT/i", $wpSqlQuery ) ) { $wpSqlQuery .= " LIMIT 100"; } if ( ! $wgUser->isDeveloper() ) { $connection = wfGetDB( $wgDBsqluser, $wgDBsqlpassword ); } $this->logQuery( $wpSqlQuery ); $res = wfQuery( $wpSqlQuery, DB_WRITE, "SpecialAsksql::doSubmit" ); $this->logFinishedQuery(); $n = 0; @$n = wfNumFields( $res ); $titleList = false; if ( $n ) { $k = array(); for ( $x = 0; $x < $n; ++$x ) { array_push( $k, wfFieldName( $res, $x ) ); } if ( $n == 2 && in_array( "cur_title", $k ) && in_array( "cur_namespace", $k ) ) { $titleList = true; } $a = array(); while ( $s = wfFetchObject( $res ) ) { array_push( $a, $s ); } wfFreeResult( $res ); if ( $titleList ) { $r = ""; foreach ( $a as $y ) { $o = "" . htmlspecialchars( $y->$x ) . "" ; $sTitle = htmlspecialchars( $y->cur_title ); if ( $y->cur_namespace ) { $sNamespace = $wgLang->getNsText( $y->cur_namespace ); $link = "$sNamespace:$sTitle"; } else { $link = "$sTitle"; } $skin = $wgUser->getSkin(); $link = $skin->makeLink( $link ); $r .= "* [[$link]]
" . htmlspecialchars( $x ) . " | "; $r .= "
---|
" . $o . " | \n"; } $r .= "