Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
categories.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 Categories class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage MediaWiki
17  * @since 12.3
18  */
20 {
21  /**
22  * Method to list all categories the page(s) belong to.
23  *
24  * @param array $titles Page titles to retrieve categories.
25  * @param array $clprop List of additional properties to get.
26  * @param array $clshow Type of categories to show.
27  * @param integer $cllimit Number of categories to return.
28  * @param boolean $clcontinue Continue when more results are available.
29  * @param array $clcategories Only list these categories.
30  * @param string $cldir Direction of listing.
31  *
32  * @return object
33  *
34  * @since 12.1
35  */
36  public function getCategories(array $titles, array $clprop = null, array $clshow = null, $cllimit = null, $clcontinue = false,
37  array $clcategories = null, $cldir = null)
38  {
39  // Build the request.
40  $path = '?action=query&prop=categories';
41 
42  // Append titles to the request.
43  $path .= '&titles=' . $this->buildParameter($titles);
44 
45  if (isset($clprop))
46  {
47  $path .= '&clprop=' . $this->buildParameter($clprop);
48  }
49 
50  if (isset($clshow))
51  {
52  $path .= '&$clshow=' . $this->buildParameter($clshow);
53  }
54 
55  if (isset($cllimit))
56  {
57  $path .= '&cllimit=' . $cllimit;
58  }
59 
60  if ($clcontinue)
61  {
62  $path .= '&clcontinue=';
63  }
64 
65  if (isset($clcategories))
66  {
67  $path .= '&clcategories=' . $this->buildParameter($clcategories);
68  }
69 
70  if (isset($cldir))
71  {
72  $path .= '&cldir=' . $cldir;
73  }
74 
75  // Send the request.
76  $response = $this->client->get($this->fetchUrl($path));
77 
78  return $this->validateResponse($response);
79  }
80 
81  /**
82  * Method to get information about all categories used.
83  *
84  * @param array $titles Page titles to retrieve categories.
85  *
86  * @return object
87  *
88  * @since 12.3
89  */
90  public function getCategoriesUsed(array $titles)
91  {
92  // Build the request
93  $path = '?action=query&generator=categories&prop=info';
94 
95  // Append titles to the request
96  $path .= '&titles=' . $this->buildParameter($titles);
97 
98  // Send the request.
99  $response = $this->client->get($this->fetchUrl($path));
100 
101  return $this->validateResponse($response);
102  }
103 
104  /**
105  * Method to get information about the given categories.
106  *
107  * @param array $titles Page titles to retrieve categories.
108  * @param boolean $clcontinue Continue when more results are available.
109  *
110  * @return object
111  *
112  * @since 12.3
113  */
114  public function getCategoriesInfo(array $titles, $clcontinue = false)
115  {
116  // Build the request.
117  $path = '?action=query&prop=categoryinfo';
118 
119  // Append titles to the request
120  $path .= '&titles=' . $this->buildParameter($titles);
121 
122  if ($clcontinue)
123  {
124  $path .= '&clcontinue=';
125  }
126 
127  // Send the request.
128  $response = $this->client->get($this->fetchUrl($path));
129 
130  return $this->validateResponse($response);
131  }
132 
133  /**
134  * Method to enumerate all categories.
135  *
136  * @param string $acfrom The category to start enumerating from.
137  * @param string $acto The category to stop enumerating at.
138  * @param string $acprefix Search for all category titles that begin with this value.
139  * @param string $acdir Direction to sort in.
140  * @param integer $acmin Minimum number of category members.
141  * @param integer $acmax Maximum number of category members.
142  * @param integer $aclimit How many categories to return.
143  * @param array $acprop Which properties to get.
144  *
145  * @return object
146  *
147  * @since 12.3
148  */
149  public function enumerateCategories($acfrom = null, $acto = null, $acprefix = null, $acdir = null, $acmin = null,
150  $acmax = null, $aclimit = null, array $acprop = null)
151  {
152  // Build the request.
153  $path = '?action=query&list=allcategories';
154 
155  if (isset($acfrom))
156  {
157  $path .= '&acfrom=' . $acfrom;
158  }
159 
160  if (isset($acto))
161  {
162  $path .= '&acto=' . $acto;
163  }
164 
165  if (isset($acprefix))
166  {
167  $path .= '&acprefix=' . $acprefix;
168  }
169 
170  if (isset($acdir))
171  {
172  $path .= '&acdir=' . $acdir;
173  }
174 
175  if (isset($acfrom))
176  {
177  $path .= '&acfrom=' . $acfrom;
178  }
179 
180  if (isset($acmin))
181  {
182  $path .= '&acmin=' . $acmin;
183  }
184 
185  if (isset($acmax))
186  {
187  $path .= '&acmax=' . $acmax;
188  }
189 
190  if (isset($aclimit))
191  {
192  $path .= '&aclimit=' . $aclimit;
193  }
194 
195  if (isset($acprop))
196  {
197  $path .= '&acprop=' . $this->buildParameter($acprop);
198  }
199 
200  // Send the request.
201  $response = $this->client->get($this->fetchUrl($path));
202 
203  return $this->validateResponse($response);
204  }
205 
206  /**
207  * Method to list change tags.
208  *
209  * @param array $tgprop List of properties to get.
210  * @param string $tglimit The maximum number of tags to limit.
211  *
212  * @return object
213  *
214  * @since 12.3
215  */
216  public function getChangeTags(array $tgprop = null, $tglimit = null)
217  {
218  // Build the request.
219  $path = '?action=query&list=tags';
220 
221  if (isset($tgprop))
222  {
223  $path .= '&tgprop=' . $this->buildParameter($tgprop);
224  }
225 
226  if (isset($tglimit))
227  {
228  $path .= '&tglimit=' . $tglimit;
229  }
230 
231  // @TODO add support for $tgcontinue
232 
233  // Send the request.
234  $response = $this->client->get($this->fetchUrl($path));
235 
236  return $this->validateResponse($response);
237  }
238 }