links.php
7.74 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
/**
* @package Joomla.Platform
* @subpackage MediaWiki
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* MediaWiki API Links class for the Joomla Platform.
*
* @since 3.1.4
*/
class JMediawikiLinks extends JMediawikiObject
{
/**
* Method to return all links from the given page(s).
*
* @param array $titles Page titles to retrieve links.
* @param array $plnamespace Namespaces to get links.
* @param string $pllimit Number of links to return.
* @param string $plcontinue Continue when more results are available.
* @param array $pltitles List links to these titles.
* @param string $pldir Direction of listing.
*
* @return object
*
* @since 3.1.4
*/
public function getLinks(array $titles, array $plnamespace = null, $pllimit = null, $plcontinue = null, array $pltitles = null, $pldir = null)
{
// Build the request.
$path = '?action=query&prop=links';
// Append titles to the request.
$path .= '&titles=' . $this->buildParameter($titles);
if (isset($plnamespace))
{
$path .= '&plnamespace=' . $this->buildParameter($plnamespace);
}
if (isset($pllimit))
{
$path .= '&pllimit=' . $pllimit;
}
if (isset($plcontinue))
{
$path .= '&plcontinue=' . $plcontinue;
}
if (isset($pltitles))
{
$path .= '&pltitles=' . $this->buildParameter($pltitles);
}
if (isset($pldir))
{
$path .= '&pldir=' . $pldir;
}
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
return $this->validateResponse($response);
}
/**
* Method to return info about the link pages.
*
* @param array $titles Page titles to retrieve links.
*
* @return object
*
* @since 3.1.4
*/
public function getLinksUsed(array $titles)
{
// Build the request.
$path = '?action=query&generator=links&prop=info';
// Append titles to the request.
$path .= '&titles=' . $this->buildParameter($titles);
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
return $this->validateResponse($response);
}
/**
* Method to return all interwiki links from the given page(s).
*
* @param array $titles Page titles to retrieve links.
* @param boolean $iwurl Whether to get the full url.
* @param integer $iwlimit Number of interwiki links to return.
* @param boolean $iwcontinue When more results are available, use this to continue.
* @param string $iwprefix Prefix for the interwiki.
* @param string $iwtitle Interwiki link to search for.
* @param string $iwdir The direction in which to list.
*
* @return object
*
* @since 3.1.4
*/
public function getIWLinks(array $titles, $iwurl = false, $iwlimit = null, $iwcontinue = false, $iwprefix = null, $iwtitle = null, $iwdir = null)
{
// Build the request.
$path = '?action=query&prop=links';
// Append titles to the request.
$path .= '&titles=' . $this->buildParameter($titles);
if ($iwurl)
{
$path .= '&iwurl=';
}
if (isset($iwlimit))
{
$path .= '&iwlimit=' . $iwlimit;
}
if ($iwcontinue)
{
$path .= '&iwcontinue=';
}
if (isset($iwprefix))
{
$path .= '&iwprefix=' . $iwprefix;
}
if (isset($iwtitle))
{
$path .= '&iwtitle=' . $iwtitle;
}
if (isset($iwdir))
{
$path .= '&iwdir=' . $iwdir;
}
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
return $this->validateResponse($response);
}
/**
* Method to return all interlanguage links from the given page(s).
*
* @param array $titles Page titles to retrieve links.
* @param integer $lllimit Number of language links to return.
* @param boolean $llcontinue When more results are available, use this to continue.
* @param string $llurl Whether to get the full URL.
* @param string $lllang Language code.
* @param string $lltitle Link to search for.
* @param string $lldir The direction in which to list.
*
* @return object
*
* @since 3.1.4
*/
public function getLangLinks(array $titles, $lllimit = null, $llcontinue = false, $llurl = null, $lllang = null, $lltitle = null, $lldir = null)
{
// Build the request.
$path = '?action=query&prop=langlinks';
// Append titles to the request.
$path .= '&titles=' . $this->buildParameter($titles);
if (isset($lllimit))
{
$path .= '&lllimit=' . $lllimit;
}
if ($llcontinue)
{
$path .= '&llcontinue=';
}
if (isset($llurl))
{
$path .= '&llurl=' . $llurl;
}
if (isset($lllang))
{
$path .= '&lllang=' . $lllang;
}
if (isset($lltitle))
{
$path .= '&lltitle=' . $lltitle;
}
if (isset($lldir))
{
$path .= '&lldir=' . $lldir;
}
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
return $this->validateResponse($response);
}
/**
* Method to return all external urls from the given page(s).
*
* @param array $titles Page titles to retrieve links.
* @param integer $ellimit Number of links to return.
* @param string $eloffset When more results are available, use this to continue.
* @param string $elprotocol Protocol of the url.
* @param string $elquery Search string without protocol.
*
* @return object
*
* @since 3.1.4
*/
public function getExtLinks(array $titles, $ellimit = null, $eloffset = null, $elprotocol = null, $elquery = null)
{
// Build the request.
$path = '?action=query&prop=extlinks';
// Append titles to the request.
$path .= '&titles=' . $this->buildParameter($titles);
if (isset($ellimit))
{
$path .= '&ellimit=' . $ellimit;
}
if (isset($eloffset))
{
$path .= '&eloffset=' . $eloffset;
}
if (isset($elprotocol))
{
$path .= '&elprotocol=' . $elprotocol;
}
if (isset($elquery))
{
$path .= '&elquery=' . $elquery;
}
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
return $this->validateResponse($response);
}
/**
* Method to enumerate all links that point to a given namespace.
*
* @param boolean $alcontinue When more results are available, use this to continue.
* @param string $alfrom Start listing at this title. The title need not exist.
* @param string $alto The page title to stop enumerating at.
* @param string $alprefix Search for all page titles that begin with this value.
* @param string $alunique Only show unique links.
* @param array $alprop What pieces of information to include.
* @param string $alnamespace The namespace to enumerate.
* @param integer $allimit Number of links to return.
*
* @return object
*
* @since 3.1.4
*/
public function enumerateLinks($alcontinue = false, $alfrom = null, $alto = null, $alprefix = null, $alunique = null, array $alprop = null,
$alnamespace = null, $allimit = null)
{
// Build the request.
$path = '?action=query&meta=siteinfo';
if ($alcontinue)
{
$path .= '&alcontinue=';
}
if (isset($alfrom))
{
$path .= '&alfrom=' . $alfrom;
}
if (isset($alto))
{
$path .= '&alto=' . $alto;
}
if (isset($alprefix))
{
$path .= '&alprefix=' . $alprefix;
}
if (isset($alunique))
{
$path .= '&alunique=' . $alunique;
}
if (isset($alprop))
{
$path .= '&alprop=' . $this->buildParameter($alprop);
}
if (isset($alnamespace))
{
$path .= '&alnamespace=' . $alnamespace;
}
if (isset($allimit))
{
$path .= '&allimit=' . $allimit;
}
// Send the request.
$response = $this->client->get($this->fetchUrl($path));
return $this->validateResponse($response);
}
}