Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
pages.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 Pages class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage MediaWiki
17  * @since 12.3
18  */
20 {
21  /**
22  * Method to edit a page.
23  *
24  * @param string $title Page title.
25  * @param int $section Section number.
26  * @param string $sectiontitle The title for a new section.
27  * @param string $text Page content.
28  * @param string $summary Title of the page you want to delete.
29  *
30  * @return object
31  *
32  * @since 12.3
33  */
34  public function editPage($title, $section = null, $sectiontitle = null, $text = null, $summary = null)
35  {
36  // Get the token.
37  $token = $this->getToken($title, 'edit');
38 
39  // Build the request path.
40  $path = '?action=edit';
41 
42  // Build the request data.
43  $data = array(
44  'title' => $title,
45  'token' => $token,
46  'section' => $section,
47  'sectiontitle' => $section,
48  'text' => $text,
49  'summary' => $summary
50  );
51 
52  // Send the request.
53  $response = $this->client->post($this->fetchUrl($path), $data);
54 
55  return $this->validateResponse($response);
56  }
57 
58  /**
59  * Method to delete a page.
60  *
61  * @param string $title Title of the page you want to delete.
62  * @param string $reason Reason for the deletion.
63  * @param string $watchlist Unconditionally add or remove the page from your watchlis.
64  * @param string $oldimage The name of the old image to delete.
65  *
66  * @return object
67  *
68  * @since 12.3
69  */
70  public function deletePageByName($title, $reason = null, $watchlist = null, $oldimage = null)
71  {
72  // Get the token.
73  $token = $this->getToken($title, 'delete');
74 
75  // Build the request path.
76  $path = '?action=delete';
77 
78  // Build the request data.
79  $data = array(
80  'title' => $title,
81  'token' => $token,
82  'reason' => $reason,
83  'watchlist' => $watchlist,
84  'oldimage' => $oldimage
85  );
86 
87  // Send the request.
88  $response = $this->client->post($this->fetchUrl($path), $data);
89 
90  return $this->validateResponse($response);
91  }
92 
93  /**
94  * Method to delete a page.
95  *
96  * @param string $pageid Page ID of the page you want to delete.
97  * @param string $reason Reason for the deletion.
98  * @param string $watchlist Unconditionally add or remove the page from your watchlis.
99  * @param string $oldimage The name of the old image to delete.
100  *
101  * @return object
102  *
103  * @since 12.3
104  */
105  public function deletePageByID($pageid, $reason = null, $watchlist = null, $oldimage = null)
106  {
107  // Get the token.
108  $token = $this->getToken($pageid, 'delete');
109 
110  // Build the request path.
111  $path = '?action=delete';
112 
113  // Build the request data.
114  $data = array(
115  'pageid' => $pageid,
116  'token' => $token,
117  'reason' => $reason,
118  'watchlist' => $watchlist,
119  'oldimage' => $oldimage
120  );
121 
122  // Send the request.
123  $response = $this->client->post($this->fetchUrl($path), $data);
124 
125  return $this->validateResponse($response);
126  }
127 
128  /**
129  * Method to restore certain revisions of a deleted page.
130  *
131  * @param string $title Title of the page you want to restore.
132  * @param string $reason Reason for restoring (optional).
133  * @param string $timestamp Timestamps of the revisions to restore.
134  * @param string $watchlist Unconditionally add or remove the page from your watchlist.
135  *
136  * @return object
137  *
138  * @since 12.3
139  */
140  public function undeletePage($title, $reason = null, $timestamp = null, $watchlist = null)
141  {
142  // Get the token.
143  $token = $this->getToken($title, 'undelete');
144 
145  // Build the request path.
146  $path = '?action=undelete';
147 
148  // Build the request data.
149  $data = array(
150  'title' => $title,
151  'token' => $token,
152  'reason' => $reason,
153  'timestamp' => $timestamp,
154  'watchlist' => $watchlist,
155  );
156 
157  // Send the request.
158  $response = $this->client->post($this->fetchUrl($path), $data);
159 
160  return $this->validateResponse($response);
161  }
162 
163  /**
164  * Method to move a page.
165  *
166  * @param string $from Title of the page you want to move.
167  * @param string $to Title you want to rename the page to.
168  * @param string $reason Reason for the move (optional).
169  * @param string $movetalk Move the talk page, if it exists.
170  * @param string $movesubpages Move subpages, if applicable.
171  * @param boolean $noredirect Don't create a redirect.
172  * @param string $watchlist Unconditionally add or remove the page from your watchlist.
173  * @param boolean $ignorewarnings Ignore any warnings.
174  *
175  * @return object
176  *
177  * @since 12.3
178  */
179  public function movePageByName($from, $to, $reason = null, $movetalk = null, $movesubpages = null, $noredirect = null,
180  $watchlist =null, $ignorewarnings = null)
181  {
182  // Get the token.
183  $token = $this->getToken($from, 'move');
184 
185  // Build the request path.
186  $path = '?action=move';
187 
188  // Build the request data.
189  $data = array(
190  'from' => $from,
191  'to' => $reason,
192  'token' => $token,
193  'reason' => $reason,
194  'movetalk' => $movetalk,
195  'movesubpages' => $movesubpages,
196  'noredirect' => $noredirect,
197  'watchlist' => $watchlist,
198  'ignorewarnings' => $ignorewarnings
199  );
200 
201  // Send the request.
202  $response = $this->client->post($this->fetchUrl($path), $data);
203 
204  return $this->validateResponse($response);
205  }
206 
207  /**
208  * Method to move a page.
209  *
210  * @param int $fromid Page ID of the page you want to move.
211  * @param string $to Title you want to rename the page to.
212  * @param string $reason Reason for the move (optional).
213  * @param string $movetalk Move the talk page, if it exists.
214  * @param string $movesubpages Move subpages, if applicable.
215  * @param boolean $noredirect Don't create a redirect.
216  * @param string $watchlist Unconditionally add or remove the page from your watchlist.
217  * @param boolean $ignorewarnings Ignore any warnings.
218  *
219  * @return object
220  *
221  * @since 12.3
222  */
223  public function movePageByID($fromid, $to, $reason = null, $movetalk = null, $movesubpages = null, $noredirect = null,
224  $watchlist =null, $ignorewarnings = null)
225  {
226  // Get the token.
227  $token = $this->getToken($fromid, 'move');
228 
229  // Build the request path.
230  $path = '?action=move';
231 
232  // Build the request data.
233  $data = array(
234  'fromid' => $fromid,
235  'to' => $reason,
236  'token' => $token,
237  'reason' => $reason,
238  'movetalk' => $movetalk,
239  'movesubpages' => $movesubpages,
240  'noredirect' => $noredirect,
241  'watchlist' => $watchlist,
242  'ignorewarnings' => $ignorewarnings
243  );
244 
245  // Send the request.
246  $response = $this->client->post($this->fetchUrl($path), $data);
247 
248  return $this->validateResponse($response);
249  }
250 
251  /**
252  * Method to undo the last edit to the page.
253  *
254  * @param string $title Title of the page you want to rollback.
255  * @param string $user Name of the user whose edits are to be rolled back.
256  * @param string $summary Custom edit summary. If not set, default summary will be used.
257  * @param string $markbot Mark the reverted edits and the revert as bot edits.
258  * @param string $watchlist Unconditionally add or remove the page from your watchlist.
259  *
260  * @return object
261  *
262  * @since 12.3
263  */
264  public function rollback($title, $user, $summary = null, $markbot = null, $watchlist = null)
265  {
266  // Get the token.
267  $token = $this->getToken($title, 'rollback');
268 
269  // Build the request path.
270  $path = '?action=rollback';
271 
272  // Build the request data.
273  $data = array(
274  'title' => $title,
275  'token' => $token,
276  'user' => $user,
277  'expiry' => $summary,
278  'markbot' => $markbot,
279  'watchlist' => $watchlist
280  );
281 
282  // Send the request.
283  $response = $this->client->post($this->fetchUrl($path), $data);
284 
285  return $this->validateResponse($response);
286  }
287 
288  /**
289  * Method to change the protection level of a page.
290  *
291  * @param string $title Title of the page you want to (un)protect.
292  * @param string $protections Pipe-separated list of protection levels.
293  * @param string $expiry Expiry timestamps.
294  * @param string $reason Reason for (un)protecting (optional).
295  * @param string $cascade Enable cascading protection.
296  * @param string $watchlist Unconditionally add or remove the page from your watchlist.
297  *
298  * @return object
299  *
300  * @since 12.3
301  */
302  public function changeProtection($title, $protections, $expiry = null, $reason = null, $cascade = null, $watchlist = null)
303  {
304  // Get the token.
305  $token = $this->getToken($title, 'unblock');
306 
307  // Build the request path.
308  $path = '?action=protect';
309 
310  // Build the request data.
311  $data = array(
312  'title' => $title,
313  'token' => $token,
314  'protections' => $protections,
315  'expiry' => $expiry,
316  'reason' => $reason,
317  'cascade' => $cascade,
318  'watchlist' => $watchlist
319  );
320 
321  // Send the request.
322  $response = $this->client->post($this->fetchUrl($path), $data);
323 
324  return $this->validateResponse($response);
325  }
326 
327  /**
328  * Method to get basic page information.
329  *
330  * @param array $titles Page titles to retrieve info.
331  * @param array $inprop Which additional properties to get.
332  * @param array $intoken Request a token to perform a data-modifying action on a page
333  * @param boolean $incontinue When more results are available, use this to continue.
334  *
335  * @return object
336  *
337  * @since 12.3
338  */
339  public function getPageInfo(array $titles, array $inprop = null, array $intoken = null, $incontinue = null)
340  {
341  // Build the request
342  $path = '?action=query&prop=info';
343 
344  // Append titles to the request.
345  $path .= '&titles=' . $this->buildParameter($titles);
346 
347  if (isset($inprop))
348  {
349  $path .= '&inprop=' . $this->buildParameter($inprop);
350  }
351 
352  if (isset($intoken))
353  {
354  $path .= '&intoken=' . $this->buildParameter($intoken);
355  }
356 
357  if ($incontinue)
358  {
359  $path .= '&incontinue=';
360  }
361 
362  // Send the request.
363  $response = $this->client->get($this->fetchUrl($path));
364 
365  return $this->validateResponse($response);
366  }
367 
368  /**
369  * Method to get various properties defined in the page content.
370  *
371  * @param array $titles Page titles to retrieve properties.
372  * @param boolean $ppcontinue When more results are available, use this to continue.
373  * @param string $ppprop Page prop to look on the page for.
374  *
375  * @return object
376  *
377  * @since 12.3
378  */
379  public function getPageProperties(array $titles, $ppcontinue = null, $ppprop = null)
380  {
381  // Build the request
382  $path = '?action=query&prop=pageprops';
383 
384  // Append titles to the request.
385  $path .= '&titles=' . $this->buildParameter($titles);
386 
387  if ($ppcontinue)
388  {
389  $path .= '&ppcontinue=';
390  }
391 
392  if (isset($ppprop))
393  {
394  $path .= '&ppprop=' . $ppprop;
395  }
396 
397  // Send the request.
398  $response = $this->client->get($this->fetchUrl($path));
399 
400  return $this->validateResponse($response);
401  }
402 
403  /**
404  * Method to get a list of revisions.
405  *
406  * @param array $titles Page titles to retrieve revisions.
407  * @param array $rvprop Which properties to get for each revision.
408  * @param boolean $rvparse Parse revision content.
409  * @param int $rvlimit Limit how many revisions will be returned.
410  *
411  * @return object
412  *
413  * @since 12.3
414  */
415  public function getRevisions(array $titles, array $rvprop = null, $rvparse = null, $rvlimit = null)
416  {
417  // Build the request
418  $path = '?action=query&prop=revisions';
419 
420  // Append titles to the request.
421  $path .= '&titles=' . $this->buildParameter($titles);
422 
423  if (isset($rvprop))
424  {
425  $path .= '&rvprop=' . $this->buildParameter($rvprop);
426  }
427 
428  if ($rvparse)
429  {
430  $path .= '&rvparse=';
431  }
432 
433  if (isset($rvlimit))
434  {
435  $path .= '&rvlimit=' . $rvlimit;
436  }
437 
438  // Send the request.
439  $response = $this->client->get($this->fetchUrl($path));
440 
441  return $this->validateResponse($response);
442  }
443 
444  /**
445  * Method to get all page templates from the given page.
446  *
447  * @param array $titles Page titles to retrieve templates.
448  * @param array $tlnamespace Show templates in this namespace(s) only.
449  * @param integer $tllimit How many templates to return.
450  * @param boolean $tlcontinue When more results are available, use this to continue.
451  * @param string $tltemplates Only list these templates.
452  * @param string $tldir The direction in which to list.
453  *
454  * @return object
455  *
456  * @since 12.3
457  */
458  public function getPageTemplates(array $titles, array $tlnamespace = null, $tllimit = null, $tlcontinue = null, $tltemplates = null, $tldir = null)
459  {
460  // Build the request.
461  $path = '?action=query&prop=templates';
462 
463  // Append titles to the request.
464  $path .= '&titles=' . $this->buildParameter($titles);
465 
466  if (isset($tlnamespace))
467  {
468  $path .= '&tlnamespace=' . $this->buildParameter($tlnamespace);
469  }
470 
471  if (isset($tllimit))
472  {
473  $path .= '&tllimit=' . $tllimit;
474  }
475 
476  if ($tlcontinue)
477  {
478  $path .= '&tlcontinue=';
479  }
480 
481  if (isset($tltemplates))
482  {
483  $path .= '&tltemplates=' . $tltemplates;
484  }
485 
486  if (isset($tldir))
487  {
488  $path .= '&tldir=' . $tldir;
489  }
490 
491  // Send the request.
492  $response = $this->client->get($this->fetchUrl($path));
493 
494  return $this->validateResponse($response);
495  }
496 
497  /**
498  * Method to get all pages that link to the given page.
499  *
500  * @param string $bltitle Title to search.
501  * @param integer $blpageid Pageid to search.
502  * @param boolean $blcontinue When more results are available, use this to continue.
503  * @param array $blnamespace The namespace to enumerate.
504  * @param string $blfilterredirect How to filter for redirects..
505  * @param integer $bllimit How many total pages to return.
506  * @param boolean $blredirect If linking page is a redirect, find all pages that link to that redirect as well.
507  *
508  * @return object
509  *
510  * @since 12.3
511  */
512  public function getBackLinks($bltitle, $blpageid = null, $blcontinue = null, array $blnamespace = null, $blfilterredirect = null,
513  $bllimit = null, $blredirect = null)
514  {
515  // Build the request.
516  $path = '?action=query&list=backlinks';
517 
518  if (isset($bltitle))
519  {
520  $path .= '&bltitle=' . $bltitle;
521  }
522 
523  if (isset($blpageid))
524  {
525  $path .= '&blpageid=' . $blpageid;
526  }
527 
528  if ($blcontinue)
529  {
530  $path .= '&blcontinue=';
531  }
532 
533  if (isset($blnamespace))
534  {
535  $path .= '&blnamespace=' . $this->buildParameter($blnamespace);
536  }
537 
538  if (isset($blfilterredirect))
539  {
540  $path .= '&blfilterredirect=' . $blfilterredirect;
541  }
542 
543  if (isset($bllimit))
544  {
545  $path .= '&bllimit=' . $bllimit;
546  }
547 
548  if ($blredirect)
549  {
550  $path .= '&blredirect=';
551  }
552 
553  // Send the request.
554  $response = $this->client->get($this->fetchUrl($path));
555 
556  return $this->validateResponse($response);
557  }
558 
559  /**
560  * Method to get all pages that link to the given interwiki link.
561  *
562  * @param string $iwbltitle Interwiki link to search for. Must be used with iwblprefix.
563  * @param string $iwblprefix Prefix for the interwiki.
564  * @param boolean $iwblcontinue When more results are available, use this to continue.
565  * @param integer $iwbllimit How many total pages to return.
566  * @param array $iwblprop Which properties to get.
567  *
568  * @return object
569  *
570  * @since 12.3
571  */
572  public function getIWBackLinks($iwbltitle, $iwblprefix = null, $iwblcontinue = null, $iwbllimit = null, array $iwblprop = null)
573  {
574  // Build the request
575  $path = '?action=query&list=iwbacklinks';
576 
577  if (isset($iwbltitle))
578  {
579  $path .= '&iwbltitle=' . $iwbltitle;
580  }
581 
582  if (isset($iwblprefix))
583  {
584  $path .= '&iwblprefix=' . $iwblprefix;
585  }
586 
587  if ($iwblcontinue)
588  {
589  $path .= '&iwblcontinue=';
590  }
591 
592  if (isset($iwbllimit))
593  {
594  $path .= '&bllimit=' . $iwbllimit;
595  }
596 
597  if (isset($iwblprop))
598  {
599  $path .= '&iwblprop=' . $this->buildParameter($iwblprop);
600  }
601 
602  // Send the request.
603  $response = $this->client->get($this->fetchUrl($path));
604 
605  return $this->validateResponse($response);
606  }
607 
608  /**
609  * Method to get access token.
610  *
611  * @param string $user The User to get token.
612  * @param string $intoken The type of token.
613  *
614  * @return object
615  *
616  * @since 12.1
617  */
618  public function getToken($user, $intoken)
619  {
620  // Build the request path.
621  $path = '?action=query&prop=info&intoken=' . $intoken . '&titles=User:' . $user;
622 
623  // Send the request.
624  $response = $this->client->post($this->fetchUrl($path), null);
625 
626  return (string) $this->validateResponse($response)->query->pages->page[$intoken . 'token'];
627  }
628 }