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 Links class for the Joomla Platform.
14 *
15 * @since 12.3
16 */
17 class JMediawikiLinks extends JMediawikiObject
18 {
19 /**
20 * Method to return all links from the given page(s).
21 *
22 * @param array $titles Page titles to retrieve links.
23 * @param array $plnamespace Namespaces to get links.
24 * @param string $pllimit Number of links to return.
25 * @param string $plcontinue Continue when more results are available.
26 * @param array $pltitles List links to these titles.
27 * @param string $pldir Direction of listing.
28 *
29 * @return object
30 *
31 * @since 12.3
32 */
33 public function getLinks(array $titles, array $plnamespace = null, $pllimit = null, $plcontinue = null, array $pltitles = null, $pldir = null)
34 {
35 // Build the request.
36 $path = '?action=query&prop=links';
37
38 // Append titles to the request.
39 $path .= '&titles=' . $this->buildParameter($titles);
40
41 if (isset($plnamespace))
42 {
43 $path .= '&plnamespace=' . $this->buildParameter($plnamespace);
44 }
45
46 if (isset($pllimit))
47 {
48 $path .= '&pllimit=' . $pllimit;
49 }
50
51 if (isset($plcontinue))
52 {
53 $path .= '&plcontinue=' . $plcontinue;
54 }
55
56 if (isset($pltitles))
57 {
58 $path .= '&pltitles=' . $this->buildParameter($pltitles);
59 }
60
61 if (isset($pldir))
62 {
63 $path .= '&pldir=' . $pldir;
64 }
65
66 // Send the request.
67 $response = $this->client->get($this->fetchUrl($path));
68
69 return $this->validateResponse($response);
70 }
71
72 /**
73 * Method to return info about the link pages.
74 *
75 * @param array $titles Page titles to retrieve links.
76 *
77 * @return object
78 *
79 * @since 12.3
80 */
81 public function getLinksUsed(array $titles)
82 {
83 // Build the request.
84 $path = '?action=query&generator=links&prop=info';
85
86 // Append titles to the request.
87 $path .= '&titles=' . $this->buildParameter($titles);
88
89 // Send the request.
90 $response = $this->client->get($this->fetchUrl($path));
91
92 return $this->validateResponse($response);
93 }
94
95 /**
96 * Method to return all interwiki links from the given page(s).
97 *
98 * @param array $titles Page titles to retrieve links.
99 * @param boolean $iwurl Whether to get the full url.
100 * @param integer $iwlimit Number of interwiki links to return.
101 * @param boolean $iwcontinue When more results are available, use this to continue.
102 * @param string $iwprefix Prefix for the interwiki.
103 * @param string $iwtitle Interwiki link to search for.
104 * @param string $iwdir The direction in which to list.
105 *
106 * @return object
107 *
108 * @since 12.3
109 */
110 public function getIWLinks(array $titles, $iwurl = false, $iwlimit = null, $iwcontinue = false, $iwprefix = null, $iwtitle = null, $iwdir = null)
111 {
112 // Build the request.
113 $path = '?action=query&prop=links';
114
115 // Append titles to the request.
116 $path .= '&titles=' . $this->buildParameter($titles);
117
118 if ($iwurl)
119 {
120 $path .= '&iwurl=';
121 }
122
123 if (isset($iwlimit))
124 {
125 $path .= '&iwlimit=' . $iwlimit;
126 }
127
128 if ($iwcontinue)
129 {
130 $path .= '&iwcontinue=';
131 }
132
133 if (isset($iwprefix))
134 {
135 $path .= '&iwprefix=' . $iwprefix;
136 }
137
138 if (isset($iwtitle))
139 {
140 $path .= '&iwtitle=' . $iwtitle;
141 }
142
143 if (isset($iwdir))
144 {
145 $path .= '&iwdir=' . $iwdir;
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 return all interlanguage links from the given page(s).
156 *
157 * @param array $titles Page titles to retrieve links.
158 * @param integer $lllimit Number of langauge links to return.
159 * @param boolean $llcontinue When more results are available, use this to continue.
160 * @param string $llurl Whether to get the full URL.
161 * @param string $lllang Language code.
162 * @param string $lltitle Link to search for.
163 * @param string $lldir The direction in which to list.
164 *
165 * @return object
166 *
167 * @since 12.3
168 */
169 public function getLangLinks(array $titles, $lllimit = null, $llcontinue = false, $llurl = null, $lllang = null, $lltitle = null, $lldir = null)
170 {
171 // Build the request.
172 $path = '?action=query&prop=langlinks';
173
174 // Append titles to the request.
175 $path .= '&titles=' . $this->buildParameter($titles);
176
177 if (isset($lllimit))
178 {
179 $path .= '&lllimit=' . $lllimit;
180 }
181
182 if ($llcontinue)
183 {
184 $path .= '&llcontinue=';
185 }
186
187 if (isset($llurl))
188 {
189 $path .= '&llurl=' . $llurl;
190 }
191
192 if (isset($lllang))
193 {
194 $path .= '&lllang=' . $lllang;
195 }
196
197 if (isset($lltitle))
198 {
199 $path .= '&lltitle=' . $lltitle;
200 }
201
202 if (isset($lldir))
203 {
204 $path .= '&lldir=' . $lldir;
205 }
206
207 // Send the request.
208 $response = $this->client->get($this->fetchUrl($path));
209
210 return $this->validateResponse($response);
211 }
212
213 /**
214 * Method to return all external urls from the given page(s).
215 *
216 * @param array $titles Page titles to retrieve links.
217 * @param integer $ellimit Number of links to return.
218 * @param string $eloffset When more results are available, use this to continue.
219 * @param string $elprotocol Protocol of the url.
220 * @param string $elquery Search string without protocol.
221 *
222 * @return object
223 *
224 * @since 12.3
225 */
226 public function getExtLinks(array $titles, $ellimit = null, $eloffset = null, $elprotocol = null, $elquery = null)
227 {
228 // Build the request.
229 $path = '?action=query&prop=extlinks';
230
231 // Append titles to the request.
232 $path .= '&titles=' . $this->buildParameter($titles);
233
234 if (isset($ellimit))
235 {
236 $path .= '&ellimit=' . $ellimit;
237 }
238
239 if (isset($eloffset))
240 {
241 $path .= '&eloffset=' . $eloffset;
242 }
243
244 if (isset($elprotocol))
245 {
246 $path .= '&elprotocol=' . $elprotocol;
247 }
248
249 if (isset($elquery))
250 {
251 $path .= '&elquery=' . $elquery;
252 }
253
254 // Send the request.
255 $response = $this->client->get($this->fetchUrl($path));
256
257 return $this->validateResponse($response);
258 }
259
260 /**
261 * Method to enumerate all links that point to a given namespace.
262 *
263 * @param boolean $alcontinue When more results are available, use this to continue.
264 * @param string $alfrom Start listing at this title. The title need not exist.
265 * @param string $alto The page title to stop enumerating at.
266 * @param string $alprefix Search for all page titles that begin with this value.
267 * @param string $alunique Only show unique links.
268 * @param array $alprop What pieces of information to include.
269 * @param string $alnamespace The namespace to enumerate.
270 * @param integer $allimit Number of links to return.
271 *
272 * @return object
273 *
274 * @since 12.3
275 */
276 public function enumerateLinks($alcontinue = false, $alfrom = null, $alto = null, $alprefix = null, $alunique = null, array $alprop = null,
277 $alnamespace = null, $allimit = null)
278 {
279 // Build the request.
280 $path = '?action=query&meta=siteinfo';
281
282 if ($alcontinue)
283 {
284 $path .= '&alcontinue=';
285 }
286
287 if (isset($alfrom))
288 {
289 $path .= '&alfrom=' . $alfrom;
290 }
291
292 if (isset($alto))
293 {
294 $path .= '&alto=' . $alto;
295 }
296
297 if (isset($alprefix))
298 {
299 $path .= '&alprefix=' . $alprefix;
300 }
301
302 if (isset($alunique))
303 {
304 $path .= '&alunique=' . $alunique;
305 }
306
307 if (isset($alprop))
308 {
309 $path .= '&alprop=' . $this->buildParameter($alprop);
310 }
311
312 if (isset($alnamespace))
313 {
314 $path .= '&alnamespace=' . $alnamespace;
315 }
316
317 if (isset($allimit))
318 {
319 $path .= '&allimit=' . $allimit;
320 }
321
322 // Send the request.
323 $response = $this->client->get($this->fetchUrl($path));
324
325 return $this->validateResponse($response);
326 }
327 }
328