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