-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.inc.php
100 lines (86 loc) · 3.2 KB
/
hooks.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @brief Implementation of the hook functions.
* @file BugzillaView/hooks.inc.php
*
* @author Dominique Barton (dbarton), confirm IT solutions GmbH
*/
/**
* @brief Callback function for LinkEnd hook.
*
* This function will reformat all links, matching the interwiki prefix defined
* as BugzillaView link.
*
* @param $skin skin
* @param $target target object
* @param $options options
* @param $html HTML
* @param $attribs attributes
* @param $ret return value
*/
function bugzillaViewLinkEnd($skin, $target, $options, &$html, &$attribs, &$ret)
{
// globalize some vars (ugly thing!)
global $wgBugzillaView, $wgParser, $wgScriptPath;
// abort here, if the link is not a bugzilla interwiki link
if(!$target->mInterwiki || $target->mInterwiki != $wgBugzillaView['interwiki'])
return TRUE;
// disable parser cache, to keep bugzilla interwiki links up-to-date
$wgParser->disableCache();
// initialize required variables
$id = intval($target->mTextform);
$text = ($html != $wgBugzillaView['interwiki'].':'.$id) ? $html : '';
$classes = 'bug';
try
{
// get infos from bugzilla DB
$statement = BugzillaViewDatabase::getInstance()->query('SELECT resolution, short_desc, bug_status
FROM '.$wgBugzillaView['dbTablePrefix'].'bugs
WHERE bug_id = "'.$id.'"
LIMIT 1');
// get data record from database
$bug = $statement->fetch(PDO::FETCH_OBJ);
// handle correct bug IDs
if(is_object($bug))
{
if(strlen(trim($text)) == 0)
{
$text = $id.' ';
if($wgBugzillaView['displayDescription'])
$text .= '<span class="bug-label-description">'.utf8_encode($bug->short_desc).'</span> ';
$text .= '<span class="bug-label-status">'.$bug->bug_status.'</span> ';
$text .= '<span class="bug-label-resolution">'.$bug->resolution.'</span>';
}
$classes .= ' bug-status-'.strtolower($bug->bug_status).' bug-resolution-'.($bug->resolution ? strtolower($bug->resolution) : 'unknown');
}
// handle incorrect bug IDs
else
{
$text = 'Invalid Bug #'.$id;
$classes = ' bug-status-notfound';
}
// build link (image sponsored by http://www.fatcow.com/free-icons)
$ret = Xml::openElement('a', $attribs).'<span class="bug '.$classes.'"><img src="'.$wgScriptPath.'/extensions/BugzillaView/bug.png"> '.$text.'</span>'.Xml::closeElement('a');
}
catch(Exception $e)
{
echo 'BugzillaView extension error: '.$e->getMessage();
}
// tell MW to skip any further hooks
return FALSE;
}
/**
* @brief Callback function for BeforePageDisplay hook.
*
* This function will simply add the cascading stylesheet file to the MediaWiki
* HTML header. The stylesheet will be used to format the bugs.
*
* @param $output output object
* @param $skin skin
*/
function bugzillaViewBeforePageDisplay(&$output, &$skin)
{
global $wgScriptPath;
$output->addStyle($wgScriptPath.'/extensions/BugzillaView/stylesheet.css');
return TRUE;
}