Difference between revisions of "Extensions/guildwars"
(add extension page) |
(No difference)
|
Latest revision as of 16:19, 13 September 2007
Guildwars extensions:
Implements tags: <character_statistics>, <guild_ladder>, <gwbbcode>
See talk on mainpage discussion about the usage of those tags
GWbbcode has been partially hacked into place by hardcoding the and replacing things in the returned html text (as seen from code)
A minor adjustment also needs to be made to gwbbcode/overlib.js. The variables
ol_offsetx=-160;
and
ol_offsety=-15;
must be set to those values to make the overlay appear in the right position.
The CSS (from overall.tpl) was put into Mediawiki:Common.css page and the Javascript from (from overall.tpl) was put into Mediawiki:Common.js page
Use this code at your own discretion, no warranty implied or given
<?php # To use, include this file from your LocalSettings.php # Guildwars specific extensions $wgExtensionFunctions[] = "wfGuildwars"; function wfGuildwars() { global $wgParser; $wgParser->setHook( "guildwars_ladder", "renderLadder" ); $wgParser->setHook( "character_statistics", "CharStats" ); $wgParser->setHook( "gw_build", "gwbbcode" ); } function renderLadder ( $guildtag , $argv, $parser ) { $c = file_get_contents("http://www.glop.org/guildwars/ladder.php?format=txt&tag=$guildtag",FALSE,NULL,0,1024); $p=explode("\n",$c); $style=""; if(isset($argv["style"])) { $style="style=\"".$argv["style"]."\""; } if($p[0] == "Guild not found") { $htmltxt = "No information for Guild with tag '$guildtag' found.<br>"; } else { $htmltxt = "<table $style class=\"diff\">\n"; $htmltxt .= "<tr><td>Rank</td><td>".$p[0]."</td></tr>\n"; $htmltxt .= "<tr><td>Guild</td><td>".$p[1]."</td></tr>\n"; $htmltxt .= "<tr><td>Tag</td><td>".$p[2]."</td></tr>\n"; $htmltxt .= "<tr><td>Points</td><td>".$p[3]."</td></tr>\n"; $htmltxt .= "<tr><td>Wins</td><td>".$p[4]."</td></tr>\n"; $htmltxt .= "<tr><td>Loses</td><td>".$p[5]."</td></tr>\n"; $htmltxt .= "<tr><td>Territory</td><td>".$p[6]."</td></tr>\n"; $htmltxt .= "</table>\n"; } return $htmltxt; } function CharStats ( $calclist , $argv, $parser ) { $charlist=explode("\n",$calclist); $style=""; $vlevel_precision=0; if(isset($argv["style"])) { $style="style=\"".$argv["style"]."\""; } if(isset($argv["vlevelprec"])) { $vlevel_precision=intval($argv["vlevelprec"]); } $htmltxt = "<table $style class=\"diff\" cellpadding=\"1\" cellspacing=\"5\">\n"; $htmltxt .= "<tr><th>Character</th><th>Hours played</th><th>Deaths</th><th>Deaths/h</th><th>XP</th>"; $htmltxt .= "<th>XP/h</th><th>XP/deaths</th><th>Virtual level</th><th>% hours</th><th>% deaths</th><th>% xp</th></tr>\n"; $xp_sum=$deaths_sum=$hours_sum=$char_count=0; foreach ($charlist as $i => $v) { if(strlen($v)>0) { $char_count++; $p=explode(",",$v); if(is_numeric($p[1])) { $hours_sum += $p[1]; } if(is_numeric($p[2])) { $deaths_sum += $p[2]; } if(is_numeric($p[3])) { $xp_sum += $p[3]; } } } foreach ($charlist as $i => $v) { if(strlen($v)>0) { $p=explode(",",$v); $xp=0; $deaths=0; $hours=0; if(is_numeric($p[1])) { $hours=$p[1]; } if(is_numeric($p[2])) { $deaths=$p[2]; } if(is_numeric($p[3])) { $xp=$p[3]; } if($hours_sum>0 && $deaths_sum>0 && $xp_sum>0) { $htmltxt .="<tr><td>"; $htmltxt .= $p[0]; $htmltxt .= "</td>"; $htmltxt .= "<td align=right>".number_format($hours)."</td><td align=right>".number_format($deaths)."</td>"; $htmltxt .= sprintf("<td align=right>%.2f</td>",$deaths/$hours); $htmltxt .= "<td align=right>".number_format($xp)."</td>"; $htmltxt .= sprintf("<td align=right>%s</td>",number_format($xp/$hours)); if($deaths>0) { $htmltxt .= sprintf("<td align=right>%s</td>",number_format($xp/$deaths)); } else { $htmltxt .= "<td align=right>N/A</td>"; } $htmltxt .= sprintf("<td align=right>%.".$vlevel_precision."f</td>",($xp - 182600)/15000 + 23); $htmltxt .= sprintf("<td align=right>%.0f</td>",$hours/$hours_sum*100); $htmltxt .= sprintf("<td align=right>%.0f</td>",$deaths/$deaths_sum*100); $htmltxt .= sprintf("<td align=right>%.0f</td>",$xp/$xp_sum*100); } else { $htmltxt .= "<tr><td>No valid input data found: its '<text>,<hours played>,<deaths>,<xp>'</td>"; } $htmltxt .= "</tr>\n"; } } if($hours_sum>0 && $deaths_sum>0 && $xp_sum>0) { $htmltxt .= "<tr><td><b>Total</b></td><td align=right><b>".number_format($hours_sum)."</b></td><td align=right><b>".number_format($deaths_sum)."</b></td>"; $htmltxt .= sprintf("<td align=right><b>%.2f</b></td>",$deaths_sum/$hours_sum); $htmltxt .= "<td align=right><b>".number_format($xp_sum)."</b></td>"; $htmltxt .= sprintf("<td align=right><b>%s</b></td>",number_format($xp_sum/$hours_sum)); $htmltxt .= sprintf("<td align=right><b>%s</b></td>",number_format($xp_sum/$deaths_sum)); $htmltxt .= sprintf("<td align=right><b>%.".$vlevel_precision."f</b></td>",($xp_sum - 182600)/15000 + 23); $htmltxt .= "</tr>\n"; $htmltxt .= "</table>\n"; $htmltxt .= sprintf("<p>%s Avg. Hours/Character, %s Avg. XP/Character, %s Avg. Deaths/Character</p>" ,number_format($hours_sum/$char_count),number_format($xp_sum/$char_count),number_format($deaths_sum/$char_count)); $htmltxt .= "<small>'Virtual level' means the level your character would be if there was no level 20 cap</small>\n"; } else { $htmltxt .= "<p>No valid input data found: its '<text>,<hours played>,<deaths>,<xp>'</p>\n"; } return $htmltxt; } function gwbbcode ( $build_code , $argv, $parser ) { $htmltext=""; //$htmltext.=require(dirname(__FILE__) . '/../gwbbcode/header.php'); $htmltext.=require(dirname(__FILE__) . '/../gwbbcode/body.php'); require_once(dirname(__FILE__) . '/../gwbbcode/gwbbcode.php'); $htmltext .= parse_gwbbcode($build_code); $htmltext = str_replace('src="./gwbbcode/','src="http://dotb-wiki.vader.dk/gwbbcode/',$htmltext); return $htmltext; } ?>
Document it ? Why do you think they call it code ?