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 Images class for the Joomla Platform.
14 *
15 * @since 12.3
16 */
17 class JMediawikiImages extends JMediawikiObject
18 {
19 /**
20 * Method to get all images contained on the given page(s).
21 *
22 * @param array $titles Page titles to retrieve images.
23 * @param integer $imagelimit How many images to return.
24 * @param boolean $imagecontinue When more results are available, use this to continue.
25 * @param integer $imimages Only list these images.
26 * @param string $imdir The direction in which to list.
27 *
28 * @return object
29 *
30 * @since 12.3
31 */
32 public function getImages(array $titles, $imagelimit = null, $imagecontinue = null, $imimages = null, $imdir = null)
33 {
34 // Build the request.
35 $path = '?action=query&prop=images';
36
37 // Append titles to the request.
38 $path .= '&titles=' . $this->buildParameter($titles);
39
40 if (isset($imagelimit))
41 {
42 $path .= '&imagelimit=' . $imagelimit;
43 }
44
45 if ($imagecontinue)
46 {
47 $path .= '&imagecontinue=';
48 }
49
50 if (isset($imimages))
51 {
52 $path .= '&imimages=' . $imimages;
53 }
54
55 if (isset($imdir))
56 {
57 $path .= '&imdir=' . $imdir;
58 }
59
60 // Send the request.
61 $response = $this->client->get($this->fetchUrl($path));
62
63 return $this->validateResponse($response);
64 }
65
66 /**
67 * Method to get all images contained on the given page(s).
68 *
69 * @param array $titles Page titles to retrieve links.
70 *
71 * @return object
72 *
73 * @since 12.3
74 */
75 public function getImagesUsed(array $titles)
76 {
77 // Build the request.
78 $path = '?action=query&generator=images&prop=info';
79
80 // Append titles to the request.
81 $path .= '&titles=' . $this->buildParameter($titles);
82
83 // Send the request.
84 $response = $this->client->get($this->fetchUrl($path));
85
86 return $this->validateResponse($response);
87 }
88
89 /**
90 * Method to get all image information and upload history.
91 *
92 * @param array $liprop What image information to get.
93 * @param integer $lilimit How many image revisions to return.
94 * @param string $listart Timestamp to start listing from.
95 * @param string $liend Timestamp to stop listing at.
96 * @param integer $liurlwidth URL to an image scaled to this width will be returned..
97 * @param integer $liurlheight URL to an image scaled to this height will be returned.
98 * @param string $limetadataversion Version of metadata to use.
99 * @param string $liurlparam A handler specific parameter string.
100 * @param boolean $licontinue When more results are available, use this to continue.
101 *
102 * @return object
103 *
104 * @since 12.3
105 */
106 public function getImageInfo(array $liprop = null, $lilimit = null, $listart = null, $liend = null, $liurlwidth = null,
107 $liurlheight = null, $limetadataversion = null, $liurlparam = null, $licontinue = null)
108 {
109 // Build the request.
110 $path = '?action=query&prop=imageinfo';
111
112 if (isset($liprop))
113 {
114 $path .= '&liprop=' . $this->buildParameter($liprop);
115 }
116
117 if (isset($lilimit))
118 {
119 $path .= '&lilimit=' . $lilimit;
120 }
121
122 if (isset($listart))
123 {
124 $path .= '&listart=' . $listart;
125 }
126
127 if (isset($liend))
128 {
129 $path .= '&liend=' . $liend;
130 }
131
132 if (isset($liurlwidth))
133 {
134 $path .= '&liurlwidth=' . $liurlwidth;
135 }
136
137 if (isset($liurlheight))
138 {
139 $path .= '&liurlheight=' . $liurlheight;
140 }
141
142 if (isset($limetadataversion))
143 {
144 $path .= '&limetadataversion=' . $limetadataversion;
145 }
146
147 if (isset($liurlparam))
148 {
149 $path .= '&liurlparam=' . $liurlparam;
150 }
151
152 if ($licontinue)
153 {
154 $path .= '&alcontinue=';
155 }
156
157 // Send the request.
158 $response = $this->client->get($this->fetchUrl($path));
159
160 return $this->validateResponse($response);
161 }
162
163 /**
164 * Method to enumerate all images.
165 *
166 * @param string $aifrom The image title to start enumerating from.
167 * @param string $aito The image title to stop enumerating at.
168 * @param string $aiprefix Search for all image titles that begin with this value.
169 * @param integer $aiminsize Limit to images with at least this many bytes.
170 * @param integer $aimaxsize Limit to images with at most this many bytes.
171 * @param integer $ailimit How many images in total to return.
172 * @param string $aidir The direction in which to list.
173 * @param string $aisha1 SHA1 hash of image.
174 * @param string $aisha1base36 SHA1 hash of image in base 36.
175 * @param array $aiprop What image information to get.
176 * @param string $aimime What MIME type to search for.
177 *
178 * @return object
179 *
180 * @since 12.3
181 */
182 public function enumerateImages($aifrom = null, $aito = null, $aiprefix = null, $aiminsize = null, $aimaxsize = null, $ailimit = null,
183 $aidir = null, $aisha1 = null, $aisha1base36 = null, array $aiprop = null, $aimime = null)
184 {
185 // Build the request.
186 $path = '?action=query&list=allimages';
187
188 if (isset($aifrom))
189 {
190 $path .= '&aifrom=' . $aifrom;
191 }
192
193 if (isset($aito))
194 {
195 $path .= '&aito=' . $aito;
196 }
197
198 if (isset($aiprefix))
199 {
200 $path .= '&aiprefix=' . $aiprefix;
201 }
202
203 if (isset($aiminsize))
204 {
205 $path .= '&aiminsize=' . $aiminsize;
206 }
207
208 if (isset($aimaxsize))
209 {
210 $path .= '&aimaxsize=' . $aimaxsize;
211 }
212
213 if (isset($ailimit))
214 {
215 $path .= '&ailimit=' . $ailimit;
216 }
217
218 if (isset($aidir))
219 {
220 $path .= '&aidir=' . $aidir;
221 }
222
223 if (isset($aisha1))
224 {
225 $path .= '&aisha1=' . $aisha1;
226 }
227
228 if (isset($aisha1base36))
229 {
230 $path .= '&$aisha1base36=' . $aisha1base36;
231 }
232
233 if (isset($aiprop))
234 {
235 $path .= '&aiprop=' . $this->buildParameter($aiprop);
236 }
237
238 if (isset($aimime))
239 {
240 $path .= '&aimime=' . $aimime;
241 }
242
243 // Send the request.
244 $response = $this->client->get($this->fetchUrl($path));
245
246 return $this->validateResponse($response);
247 }
248 }
249