-
Notifications
You must be signed in to change notification settings - Fork 0
/
IssueTracker.body.php
187 lines (165 loc) · 4.46 KB
/
IssueTracker.body.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/** @see IssueTrackerModelDefault **/
require_once dirname(__FILE__) . '/Models/IssueTrackerModelDefault.php';
/**
* Issue Tracking System
*
* This class will be loaded automatically when the special page or hook
* is requested.
*
* @category Extensions
* @package IssueTracker
* @author Federico Cargnelutti
* @copyright Copyright (c) 2008 Federico Cargnelutti
* @license GNU General Public Licence 2.0 or later
*/
class IssueTracker extends SpecialPage
{
/**
* Instance of the class.
* @var obj
*/
protected static $_instance = null;
/**
* Instance of IssueTrackerConfig
* @var IssueTrackerConfig
*/
protected $_config = null;
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
parent::__construct('IssueTracker');
wfLoadExtensionMessages('IssueTracker');
$this->_loadConfigFile();
}
/**
* Special Page
*
* This methods overrides SpecialPage::execute(), it passes a single
* parameter, usually referred to cryptically as $par.
*
* @return void
*/
public function execute($par)
{
global $wgOut;
// Set the page namespace
$title = Title::makeTitle(NS_SPECIAL, $this->getName());
$namespace['dbKey'] = $title->getPrefixedDbKey();
$namespace['text'] = $title->getPrefixedDbKey();
// Process request
$output = $this->_processActionRequest($namespace);
// Output
$this->setHeaders();
$wgOut->addHtml($output);
}
/**
* Parser Hook
*
* The following method is assigned to a hook, which will be run whenever
* the user adds a <bugs /> tag in the main MediaWiki code.
*
* @param string $text
* @param array $args
* @param obj $parser
* @return str
*/
public static function executeHook($text, $args = array(), $parser)
{
$parser->disableCache();
// Set the page namespace
$namespace['dbKey'] = $parser->getTitle()->getPrefixedDBkey();
$namespace['text'] = $parser->getTitle()->getPrefixedText();
$isParserHook = true;
// Process request
$instance = self::_getInstance();
$output = $instance->_processActionRequest($namespace, $isParserHook, $args);
return $output;
}
/**
* Returns a single instance of the class.
*
* @return obj
*/
protected static function _getInstance()
{
if (null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Loads the config file.
*
* @return void
* @throws Exception
*/
protected function _loadConfigFile()
{
$file = dirname(__FILE__) . '/' . __CLASS__ . '.config.php';
if (! file_exists($file)) {
throw new Exception('Unable to load the configuration file: ' . $file);
}
require_once $file;
$class = __CLASS__ . 'Config';
$this->setConfig(new $class());
}
/**
* Processes the action request.
*
* @return string
* @throws Exception
*/
protected function _processActionRequest(array $namespace, $isParserHook = false, $args = array())
{
global $wgRequest;
$action = $wgRequest->getText('bt_action', 'list');
$class = __CLASS__ . 'Action' . ucfirst(strtolower($action));
$method = $action . 'Action';
$file = dirname(__FILE__) . '/Actions/' . $class . '.php';
if (! file_exists($file)) {
throw new Exception('Invalid file: ' . $file);
}
if (array_key_exists($action, $this->_config->getPermissions())) {
require_once dirname(__FILE__) . '/Actions/' . $class . '.php';
$controller = new $class();
$controller->setConfig($this->getConfig());
if ($controller->hasPermission($action)) {
$controller->setAction($action);
$controller->setParserHook($isParserHook);
$controller->setNamespace($namespace);
$controller->setModel(new IssueTrackerModelDefault());
$controller->setArguments($args);
if (!method_exists($controller, 'init') || $controller->init() === true) {
$controller->$method();
return $controller->getOutput();
}
}
return wfMsg('not_authorized');
}
return wfMsg('invalid_action') . ': ' . $action;
}
/**
* Sets the Config object.
*
* @param IssueTrackerConfig
* @return void
*/
public function setConfig(IssueTrackerConfig $config)
{
$this->_config = $config;
}
/**
* Returns the config object.
*
* @return array self::$_config
*/
public function getConfig()
{
return $this->_config;
}
}