Skip to content

Instantly share code, notes, and snippets.

@ThePengwin
Created March 13, 2013 07:34
Show Gist options
  • Save ThePengwin/5150012 to your computer and use it in GitHub Desktop.
Save ThePengwin/5150012 to your computer and use it in GitHub Desktop.
Updated Mantis Plugin for MediaWiki
<?php
/*
* Installation:
* require_once("extensions/MantisIntegration/MantisIntegration.php"); in LocalSettings.php
* update $mantisDBSERVER, $mantisDBUSER, $mantisDBUSERPW, $mantisDBNAME, $mantis_home
* Usage:
* <mantis>#bugid</mantis>
*
* @version 0.2 schke 2008-10-31
* -change data input from php implode of bugsite to direct database access
* -added state information to output
* -added meta information for Spezial:Version
*
* @version 0.3 schke 2008-11-06
* -bug with specialcharacters resolved
*/
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
die( -1 );
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits['parserhook']['MantisExtension'] = array(
'name' => 'MantisExtension',
'version' => '0.4',
'author' => 'Alexander Botero-Lowry, [http://www.mediawiki.org/wiki/User:Schke Kevin Schulze]',
'description' => 'Link to Mantis Bug Report in MediaWiki',
'url' => 'http://www.mediawiki.org/w/index.php?title=Extension:MantisIntegration'
);
$wgExtensionFunctions[] = "wfMantisExtension";
function wfMantisExtension() {
global $wgParser;
$wgParser->setHook( "mantis", "showMantis" );
}
function showMantis( $input, $argv, &$parser) {
$mantisDBPrefix="mantis_";
$mantis_home = "http://mantis.xxxxxx.de/mantis/view.php?id=";
# --------------------------------------------
$bug_page = $mantis_home . $input;
//TODO: add the correct database details here
$mantisDB = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
if ( $mysqli->connect_error ) { return "<hr><b>Error while connecting to database - \" $mysqli->connect_error \" !</b><hr>"; }
$sql = sprintf("SELECT id, convert(convert(summary using utf8), binary) as summary, status FROM ".$mantisDBPrefix."bug_table where id=%d",
$mantisDB->escape_string($input));
$result = $mantisDB->query($sql);
if (!$result) { return "<hr><b>Error while MySQL Query :". $mantisDB->error() ;}
if ( ($row = $result->fetch_array($qryres) ) !== NULL) {
switch ($row['summary']) {
case 10:
$state_msg="new";
break;
case 20:
$state_msg="feedback";
break;
case 30:
$state_msg="acknowledged";
break;
case 40:
$state_msg="confirmed";
break;
case 50:
$state_msg="assigned";
break;
case 60:
$state_msg="working on";
break;
case 80:
$state_msg="resolved";
break;
case 90:
$state_msg="closed";
break;
default:
$state_msg="unkown";
}
$res = "Bug ID:".$row['id']." (".$state_msg.") : ".$row['summary'];
}else{
$res = "No MANTIS Entry found!!!";
}
//free result
$result->free();
//end db connection
$mantisDB->close();
$output = $parser->parse("[$bug_page $res]", $parser->mTitle, $parser->mOptions, false, false);
return $output->getText();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment