3 function wfSpecialAsksql()
5 global $wgUser, $wgOut, $action;
7 if ( ! $wgUser->isSysop() ) {
8 $wgOut->sysopRequired();
11 $fields = array( "wpSqlQuery" );
12 wfCleanFormFields( $fields );
13 $f = new SqlQueryForm();
15 if ( "submit" == $action ) { $f->doSubmit(); }
16 else { $f->showForm( "" ); }
21 function showForm( $err )
23 global $wgOut, $wgUser, $wgLang;
26 $wgOut->setPagetitle( wfMsg( "asksql" ) );
27 $wgOut->addWikiText( wfMsg( "asksqltext" ) );
30 $wgOut->addHTML( "<p><font color='red' size='+1'>" . htmlspecialchars($err) . "</font>\n" );
32 if ( ! $wpSqlQuery ) { $wpSqlQuery = "SELECT ... FROM ... WHERE ..."; }
33 $q = wfMsg( "sqlquery" );
34 $qb = wfMsg( "querybtn" );
35 $action = wfLocalUrlE( $wgLang->specialPage( "Asksql" ),
39 <form id=\"asksql\" method=\"post\" action=\"{$action}\">
41 <td align=right>{$q}:</td>
43 <textarea name=\"wpSqlQuery\" cols=80 rows=4 wrap=\"virtual\">"
44 . htmlspecialchars($wpSqlQuery) ."
48 <td> </td><td align=\"left\">
49 <input type=submit name=\"wpQueryBtn\" value=\"{$qb}\">
57 global $wgOut, $wgUser, $wgServer, $wgScript, $wgArticlePath, $wgLang;
59 global $wgDBsqluser, $wgDBsqlpassword;
62 $wpSqlQuery = trim( $wpSqlQuery );
63 if( preg_match( "/^SELECT/i", $wpSqlQuery )
64 and !preg_match( "/LIMIT/i", $wpSqlQuery ) ) {
65 $wpSqlQuery .= " LIMIT 100";
67 if ( ! $wgUser->isDeveloper() ) {
68 $connection = wfGetDB( $wgDBsqluser, $wgDBsqlpassword );
70 $res = wfQuery( $wpSqlQuery, "SpecialAsksql::doSubmit" );
73 @$n = wfNumFields( $res );
76 for ( $x = 0; $x < $n; ++
$x ) {
77 array_push( $k, wfFieldName( $res, $x ) );
80 while ( $s = wfFetchObject( $res ) ) {
85 $r = "<table border=1 bordercolor=black cellspacing=0 " .
86 "cellpadding=2><tr>\n";
87 foreach ( $k as $x ) $r .= "<th>" . htmlspecialchars( $x ) . "</th>";
90 foreach ( $a as $y ) {
92 foreach ( $k as $x ) {
94 if ( $x == "cur_title" or $x == "old_title" or $x == "rc_title") {
96 if( $x == "cur_title" ) $namespace = $y->cur_namespace
;
97 if( $x == "old_title" ) $namespace = $y->old_namespace
;
98 if( $x == "rc_title" ) $namespace = $y->rc_namespace
;
99 if( $namespace ) $o = $wgLang->getNsText( $namespace ) . ":" . $o;
100 $o = "<a href=\"" . wfLocalUrlE($o) . "\" class='internal'>" .
101 htmlspecialchars( $y->$x ) . "</a>" ;
103 $o = htmlspecialchars( $o );
105 $r .= "<td>" . $o . "</td>\n";
111 $this->showForm( wfMsg( "querysuccessful" ) );
112 $wgOut->addHTML( "<hr>{$r}\n" );