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