Pablo,
I'm doing this against our MySQL and MS SQL servers via custom php extensions. It works well & is easily incorporated within the MediaWiki interface so none of my users is the wiser.
Regarding your specific request - the comment at the top of the specialasksql.php code suggests that it would only work for queries against the cur table. " * If enabled through $wgAllowSysopQueries = true, this class * let users with sysop right the possibility to make sql queries * against the cur table. * Heavy queries could slow down the database specially for the * biggest wikis."
Al. -----Original Message----- From: Pablo Chamorro C. [mailto:pchamorro@ingeominas.gov.co] Sent: Wednesday, 18 May 2005 12:44 p.m. To: mediawiki-l@wikimedia.org Subject: [Mediawiki-l] direct SQL Queries example
Could somebody please give me some details of how to do a direct SQL query? I mean, can I use Media Wiki as a frontend for my MySQL databases? That would be great! My wiki is on my intranet and for me a read only access is ok. If not, how could it be managed?
thanks,
Pablo Chamorro C.
---
"Direct SQL Queries
To allow SQL queries through the wiki's Special:Asksql page, you can enable direct SQL queries via the web interface. ..."
-- Tel: +57 (2) 7314752/3222/2595 - Fax: +57 (2) 7310514 Carrera 31 #18-07 Parque Infantil - PO Box 1795 - Pasto _______________________________________________ MediaWiki-l mailing list MediaWiki-l@Wikimedia.org http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
I'm doing this against our MySQL and MS SQL servers via custom php extensions. It works well & is easily incorporated within the MediaWiki interface so none of my users is the wiser.
Oh.. thanks, I see... But could you please share some sample of the extensions you wrote or give some clue? My knowledge is very limited.
thanks,
Pablo
Regarding your specific request - the comment at the top of the specialasksql.php code suggests that it would only work for queries against the cur table.
Al.
At 08:38 AM 5/18/05, Pablo Chamorro C. wrote:
I'm doing this against our MySQL and MS SQL servers via custom php extensions. It works well & is easily incorporated within the MediaWiki interface so none of my users is the wiser.
Oh.. thanks, I see... But could you please share some sample of the extensions you wrote or give some clue? My knowledge is very limited.
Hope this will help. Here is a sample from mine. I've stripped out a lot that doesn't matter and reduced the example to just one of the extension functions. To add more extensions/functions, add more $wgParser->setHook( "***", "****" ); statements and the corresponding functions.
Note that I've replaced my $username = "*************"; $password = "************"; $database = "************"; with *************, you'll have to put your own settings in those spots.
To call the extension/function, I have this on my wiki page: <PrussianCommunitiesTable>Wongrowitz</PrussianCommunitiesTable>
To see it in action: http://www.birchy.com/GenWiki/index.php?title=Kreis_Wongrowitz
This file ("BirchyExtensions.php") is in my Extension folder:
<?php # Example WikiMedia extension # with WikiMedia's extension mechanism it is possible to define # new tags of the form # <TAGNAME> some text </TAGNAME> # the function registered by the extension gets the text between the # tags as input and can transform it into arbitrary HTML code. # Note: The output is not interpreted as WikiText but directly # included in the HTML output. So Wiki markup is not supported. # To activate the extension, include it from your LocalSettings.php # with: include("extensions/ExampleExt.php");
$wgExtensionFunctions[] = "wfRegisterExtensions";
function wfRegisterExtensions() { global $wgParser; // register the extension with the WikiText parser // the first parameter is the name of the new tag. In this case it defines the tag <example> ... </example> // the second parameter is the callback function for processing the text between the tags
$wgParser->setHook( "1905GazetteerCommunitySuburbsTable", "create1905GazetteerCommunitySuburbsTable" ); }
function create1905GazetteerCommunitySuburbsTable( $input ) { $host = "localhost"; $username = "*************"; $password = "************"; $database = "************";
$dbh=mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($database) or die ('Cannot select database');
list($theKreis, $theTown) = explode(",", $input); $theTown = utf8_decode($theTown) ; $theKreis = utf8_decode($theKreis) ;
$CellStart = '<TD ALIGN="LEFT" VALIGN="TOP" BGCOLOR="F4F4DB">'; $CellStartNum = '<TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="F4F4DB">'; $output = convertSpecialChars($theTown)." owned and/or administered the communities of..\r\n";
$query = "SELECT tbl_2.Name, tbl_2.NamePolish, tbl_2.TypeExact, tbl_2.PopTotal, tbl_2.Notes FROM Gazetteer1905 AS tbl_2 INNER JOIN Gazetteer1905 AS tbl_1 ON tbl_2.PartOf = tbl_1.LineNum WHERE tbl_2.Kreis LIKE '".$theKreis."' AND tbl_1.Kreis LIKE '".$theKreis."' AND tbl_1.Name LIKE '".convertSpecialCharsForSearchStr($theTown)."' ORDER BY tbl_2.Name ASC;"; $result = mysql_query ($query); $numResults = mysql_num_rows($result); if ($numResults > 0) { $output .= '<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1" >'; $output .= '<TR>'; $output .= $CellStart.'<B>Town'.'</TD>'; $output .= $CellStart.'<B>Polish Spelling'.'</TD>'; $output .= $CellStart.'<B>Type'.'</TD>'; $output .= $CellStartNum.'<B>1905 Pop'.'</TD>'; $output .= $CellStart.'<B>Notes'.'</TD>'; $output .= $CellStart.'<B>More'.'</TD>'; $output .= '</TR>';
for ($i=1; $i < ($numResults + 1); $i++) { $row = mysql_fetch_array($result); $theName = convertSpecialChars($row["Name"]) ; $theTypeExact = convertSpecialChars($row["TypeExact"]) ; $theNamePolish = convertSpecialChars($row["NamePolish"]) ; $theNotes = convertSpecialChars($row["Notes"]) ; $thePopTotal = $row["PopTotal"] ;
$output .= '<TR>'; $output .= $CellStart.$theName.'</TD>'; $output .= $CellStart.$theNamePolish.'</TD>'; $output .= $CellStart.$theTypeMajor.'</TD>'; $output .= $CellStartNum.$thePopTotal.'</TD>'; $output .= $CellStart.$theNotes.'</TD>'; $output .= $CellStart.'</TD>'; $output .= '</TR>'; } $output .= '</TABLE> <TABLE> <TR><TD COLSPAN=4>'; // <FONT SIZE="3">'; $output .= '</TD></TR> </TABLE><BR>'; } else { $output .= "(communities owned here)\r\n"; } return $output; } ?>
James Birkholz admin, Posen-L mailing list and website http://www.Posen-L.com
Correction: In the previous post of an example, I c/p'd the wrong extension tags. Should be:
To call the extension/function, I have this on my wiki page: <create1905GazetteerCommunitySuburbsTable>Wongrowitz</create1905GazetteerCommunitySuburbsTable>
James
Hope this will help. Here is a sample from mine. I've stripped out a lot that doesn't matter and reduced the example to just one of the extension functions. To add more extensions/functions, add more $wgParser->setHook( "***", "****" ); statements and the corresponding functions.
You are very kind, thanks!. I was offline for a while.
Pablo
Note that I've replaced my $username = "*************"; $password = "************"; $database = "************"; with *************, you'll have to put your own settings in those spots.
mediawiki-l@lists.wikimedia.org