forked from gvoss/php-mediawiki-jiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jiki.php
163 lines (154 loc) · 4.55 KB
/
Jiki.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
if(!defined("MEDIAWIKI"))
{
echo("This file is an extension to the MediaWiki software and cannot be used standalone.\n");
die(1);
}
$wgExtensionCredits["parserhook"][] = array
(
"path" => __FILE__,
"name" => "JIKI",
"namemsg" => "JIKI",
"description" => "JIKI - JIRA in your WIKI",
"descriptionmsg" => "JIKI - JIRA in your WIKI",
"version" => "1.0",
"author" => "gvoss",
"url" => "https://github.com/gvoss/php-mediawiki-jiki",
"license-name" => "https://github.com/gvoss/php-mediawiki-jiki/blob/master/LICENSE",
);
#jikiSupportedParams - base parameters supported by Jiki
$jikiSupportedParams = array
(
"id",
"key",
"issuetype",
"project",
"fixversion",
"affectedversion",
"reporter",
"assignee",
"priority",
"type",
"status",
"sprint",
"resolution",
"labels",
"component",
"description",
"createddate",
"updateddate",
array("param"=>"epiclink","jql"=>"\"Epic Link\""),
);
if(isset($jikiExtraParams))
{
$jikiSupportedParams = array_merge($jikiSupportedParams,$jikiExtraParams);#Allows for extending the base params
}
#jikiDataContainer - common container for response from JIRA
$jikiDataContainer = array
(
"jql" => "",
"host" => "",
"endpoint" => "",
"success" => false,
"total" => 0,
"data" => array(),
);
$wgHooks["ParserFirstCallInit"][] = "jikiSetHook";
#Import API Handlers
$wgAutoloadClasses['Rest'] = __DIR__ . '/api/Rest.php';#Calls JIRA REST API
#Import View Handlers
$wgAutoloadClasses['Simple'] = __DIR__ . '/view/Simple.php';#Allows to display in plain text
$wgAutoloadClasses['Hypertext'] = __DIR__ . '/view/Hypertext.php';#Allows to display in HTML
$wgAutoloadClasses['HTMLComponent'] = __DIR__ . '/view/HTMLComponent.php';#Allows to display in HTML with issues grouped by component
#Import Utilities
$wgAutoloadClasses['JQL'] = __DIR__ . '/util/JQL.php';#JQL Helper functions
$wgAutoloadClasses['JIRA'] = __DIR__ . '/util/JIRA.php';#JIRA Helper functions
global $jikiFullDetailsField;
if (!isset($jikiFullDetailsField))
{
$jikiFullDetailsField = "description";
}
define("JIKI_FULL_DETAILS_FIELD", $jikiFullDetailsField);
function jikiSetHook($parser)
{
$parser->setHook("jira","jikiRender");
return true;
}
function jikiRender($input,$args,$parser)
{
global $jikiJiraHost,$jikiJiraUser,$jikiJiraPassword,$jikiSupportedParams;#Configuration from the LocalSettings
$jikiJQL = "";#jql to send to JIRA
$jikiOutput = "";#output to the wiki page
$jikiFormat = "html";#How to format JIKI output
$jikiFullDetails = false;#Whether or not to show full ticket details
$jikiLinkToJira = true;#Whether to include a link to JIRA
if(!isset($jikiJiraHost)||!isset($jikiJiraUser)||!isset($jikiJiraPassword))#No Configuration
{
$jikiOutput = "No JIRA Configuration...";
return $jikiOutput;
}
if(!filter_var($jikiJiraHost,FILTER_VALIDATE_URL))#Bad URL
{
$jikiOutput = "Bad JIRA Host URL...";
return $jikiOutput;
}
if(strtolower(parse_url($jikiJiraHost,PHP_URL_SCHEME))!=="https")
{
$jikiOutput = "Consider using JIRA on HTTPS...";
return $jikiOutput;
}
if(isset($args["jql"]))#allow override of JQL
{
$jikiDataContainer["jql"] = $args["jql"];
}
else
{
$jikiDataContainer["jql"] = JQL::getJQL($input,$args,$jikiSupportedParams);
}
if(isset($args["jikiformat"]))#user specified a format
{
$jikiFormat = $args["jikiformat"];
}
if(isset($args["jikifulldetails"])&&$args["jikifulldetails"]=="true")#user specified full ticket details
{
$jikiFullDetails = true;
}
if(isset($args["id"])||isset($args["key"]))#user specified a single issue
{
$jikiLinkToJira = false;
}
#set up the arguments for the render methods
$jikiRenderArgs = array
(
"renderLink" => $jikiLinkToJira,
"renderDetails" => $jikiFullDetails,
);
if(Rest::getJIRAData($jikiDataContainer,$jikiJiraHost,$jikiJiraUser,$jikiJiraPassword,$jikiJQL))#Some data is returned
{
switch(strtolower($jikiFormat))
{
case "html_component":
{
$htmlComponent = new HTMLComponent;
$jikiDataContainer = $htmlComponent->sort($jikiDataContainer);
$jikiOutput = $htmlComponent->getRenderedView($jikiDataContainer,$jikiRenderArgs);
break;
}
case "html":
{
$jikiOutput = Hypertext::getRenderedView($jikiDataContainer,$jikiRenderArgs);
break;
}
default:
{
$jikiOutput = Simple::getRenderedView($jikiDataContainer,$jikiRenderArgs);
break;
}
}
}
else#Failure to get data
{
$jikiOutput = "Error while calling JIRA...";
}
return $jikiOutput;
}