1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage MediaWiki
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * MediaWiki API Sites class for the Joomla Platform.
14 *
15 * @since 12.3
16 */
17 class JMediawikiSites extends JMediawikiObject
18 {
19 /**
20 * Method to get site information.
21 *
22 * @param array $siprop The sysinfo properties to get.
23 * @param string $sifilteriw Only local or only non local entries to return.
24 * @param boolean $sishowalldb List all database servers.
25 * @param boolean $sinumberingroup List the number of users in usergroups.
26 * @param array $siinlanguagecode Language code for localized languages.
27 *
28 * @return object
29 *
30 * @since 12.3
31 */
32 public function getSiteInfo(array $siprop = null, $sifilteriw = null, $sishowalldb = false, $sinumberingroup = false, array $siinlanguagecode = null)
33 {
34 // Build the request.
35 $path = '?action=query&meta=siteinfo';
36
37 if (isset($siprop))
38 {
39 $path .= '&siprop=' . $this->buildParameter($siprop);
40 }
41
42 if (isset($sifilteriw))
43 {
44 $path .= '&sifilteriw=' . $sifilteriw;
45 }
46
47 if ($sishowalldb)
48 {
49 $path .= '&sishowalldb=';
50 }
51
52 if ($sinumberingroup)
53 {
54 $path .= '&sinumberingroup=';
55 }
56
57 if (isset($siinlanguagecode))
58 {
59 $path .= '&siinlanguagecode=' . $this->buildParameter($siinlanguagecode);
60 }
61
62 // Send the request.
63 $response = $this->client->get($this->fetchUrl($path));
64
65 return $this->validateResponse($response);
66 }
67
68 /**
69 * Method to get events from logs.
70 *
71 * @param array $leprop List of properties to get.
72 * @param string $letype Filter log actions to only this type.
73 * @param string $leaction Filter log actions to only this type.
74 * @param string $letitle Filter entries to those related to a page.
75 * @param string $leprefix Filter entries that start with this prefix.
76 * @param string $letag Filter entries with tag.
77 * @param string $leuser Filter entries made by the given user.
78 * @param string $lestart Starting timestamp.
79 * @param string $leend Ending timestamp.
80 * @param string $ledir Direction of enumeration.
81 * @param integer $lelimit Event limit to return.
82 *
83 * @return object
84 *
85 * @since 12.3
86 */
87 public function getEvents(array $leprop = null, $letype = null, $leaction = null, $letitle = null, $leprefix = null, $letag = null,
88 $leuser = null, $lestart = null, $leend = null, $ledir = null, $lelimit = null)
89 {
90 // Build the request
91 $path = '?action=query&list=logevents';
92
93 if (isset($leprop))
94 {
95 $path .= '&leprop=' . $this->buildParameter($leprop);
96 }
97
98 if (isset($letype))
99 {
100 $path .= '&letype=' . $letype;
101 }
102
103 if (isset($leaction))
104 {
105 $path .= '&leaction=' . $leaction;
106 }
107
108 if (isset($letitle))
109 {
110 $path .= '&letitle=' . $letitle;
111 }
112
113 if (isset($leprefix))
114 {
115 $path .= '&leprefix=' . $leprefix;
116 }
117
118 if (isset($letag))
119 {
120 $path .= '&letag=' . $letag;
121 }
122
123 if (isset($leuser))
124 {
125 $path .= '&leuser=' . $leuser;
126 }
127
128 if (isset($lestart))
129 {
130 $path .= '&lestart=' . $lestart;
131 }
132
133 if (isset($leend))
134 {
135 $path .= '&leend=' . $leend;
136 }
137
138 if (isset($ledir))
139 {
140 $path .= '&ledir=' . $ledir;
141 }
142
143 if (isset($lelimit))
144 {
145 $path .= '&lelimit=' . $lelimit;
146 }
147
148 // Send the request.
149 $response = $this->client->get($this->fetchUrl($path));
150
151 return $this->validateResponse($response);
152 }
153
154 /**
155 * Method to get recent changes on a site.
156 *
157 * @param string $rcstart Starting timestamp.
158 * @param string $rcend Ending timestamp.
159 * @param string $rcdir Direction of enumeration.
160 * @param array $rcnamespace Filter changes to only this namespace(s).
161 * @param string $rcuser Filter changes by this user.
162 * @param string $rcexcludeuser Filter changes to exclude changes by this user.
163 * @param string $rctag Filter changes by this tag.
164 * @param array $rcprop Filter log actions to only this type.
165 * @param array $rctoken Which token to obtain for each change.
166 * @param array $rcshow Filter changes by this criteria.
167 * @param string $rclimit Changes limit to return.
168 * @param string $rctype Filter event by type of changes.
169 * @param string $rctoponly Filter changes which are latest revision.
170 *
171 * @return object
172 *
173 * @since 12.3
174 */
175 public function getRecentChanges($rcstart = null, $rcend = null, $rcdir = null, array $rcnamespace = null, $rcuser = null, $rcexcludeuser = null,
176 $rctag = null, array $rcprop = null, array $rctoken = null, array $rcshow = null, $rclimit = null, $rctype = null, $rctoponly = null)
177 {
178 // Build the request.
179 $path = '?action=query&list=recentchanges';
180
181 if (isset($rcstart))
182 {
183 $path .= '&rcstart=' . $rcstart;
184 }
185
186 if (isset($rcend))
187 {
188 $path .= '&rcend=' . $rcend;
189 }
190
191 if (isset($rcdir))
192 {
193 $path .= '&rcdir=' . $rcdir;
194 }
195
196 if (isset($rcnamespace))
197 {
198 $path .= '&rcnamespaces=' . $this->buildParameter($rcnamespace);
199 }
200
201 if (isset($rcuser))
202 {
203 $path .= '&rcuser=' . $rcuser;
204 }
205
206 if (isset($rcexcludeuser))
207 {
208 $path .= '&rcexcludeuser=' . $rcexcludeuser;
209 }
210
211 if (isset($rctag))
212 {
213 $path .= '&rctag=' . $rctag;
214 }
215
216 if (isset($rcprop))
217 {
218 $path .= '&rcprop=' . $this->buildParameter($rcprop);
219 }
220
221 if (isset($rctoken))
222 {
223 $path .= '&rctoken=' . $this->buildParameter($rctoken);
224 }
225
226 if (isset($rcshow))
227 {
228 $path .= '&rcshow=' . $this->buildParameter($rcshow);
229 }
230
231 if (isset($rclimit))
232 {
233 $path .= '&rclimit=' . $rclimit;
234 }
235
236 if (isset($rctype))
237 {
238 $path .= '&rctype=' . $rctype;
239 }
240
241 if (isset($rctoponly))
242 {
243 $path .= '&rctoponly=' . $rctoponly;
244 }
245
246 // Send the request.
247 $response = $this->client->get($this->fetchUrl($path));
248
249 return $this->validateResponse($response);
250 }
251
252 /**
253 * Method to get protected titles on a site.
254 *
255 * @param array $ptnamespace Only list titles in this namespace.
256 * @param array $ptlevel Only list titles with these protection level.
257 * @param integer $ptlimit Limit of pages to return.
258 * @param string $ptdir Direction of enumeration.
259 * @param string $ptstart Starting timestamp.
260 * @param string $ptend Ending timestamp.
261 * @param array $ptprop List of properties to get.
262 *
263 * @return object
264 *
265 * @since 12.3
266 */
267 public function getProtectedTitles(array $ptnamespace = null, array $ptlevel = null, $ptlimit = null, $ptdir = null, $ptstart = null,
268 $ptend = null, array $ptprop = null)
269 {
270 // Build the request.
271 $path = '?action=query&list=protectedtitles';
272
273 if (isset($ptnamespace))
274 {
275 $path .= '&ptnamespace=' . $this->buildParameter($ptnamespace);
276 }
277
278 if (isset($ptlevel))
279 {
280 $path .= '&ptlevel=' . $this->buildParameter($ptlevel);
281 }
282
283 if (isset($ptlimit))
284 {
285 $path .= '&ptlimit=' . $ptlimit;
286 }
287
288 if (isset($ptdir))
289 {
290 $path .= '&ptdir=' . $ptdir;
291 }
292
293 if (isset($ptstart))
294 {
295 $path .= '&ptstart=' . $ptstart;
296 }
297
298 if (isset($ptend))
299 {
300 $path .= '&ptend=' . $ptend;
301 }
302
303 if (isset($ptprop))
304 {
305 $path .= '&ptprop=' . $this->buildParameter($ptprop);
306 }
307
308 // Send the request.
309 $response = $this->client->get($this->fetchUrl($path));
310
311 return $this->validateResponse($response);
312 }
313 }
314