4 * Created on July 6, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * A query action to get image information and upload history.
36 class ApiQueryImageInfo
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'ii');
42 public function execute() {
43 $params = $this->extractRequestParams();
45 $history = $params['history'];
47 $prop = array_flip($params['prop']);
48 $fld_timestamp = isset($prop['timestamp']);
49 $fld_user = isset($prop['user']);
50 $fld_comment = isset($prop['comment']);
51 $fld_url = isset($prop['url']);
52 $fld_size = isset($prop['size']);
53 $fld_sha1 = isset($prop['sha1']);
54 $fld_metadata = isset($prop['metadata']);
56 if($params['urlheight'] != -1 && $params['urlwidth'] == -1)
57 $this->dieUsage("iiurlheight cannot be used without iiurlwidth", 'iiurlwidth');
58 $scale = $params['urlwidth'] != -1;
60 $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
61 if (!empty($pageIds[NS_IMAGE
])) {
62 foreach ($pageIds[NS_IMAGE
] as $dbKey => $pageId) {
64 $title = Title
:: makeTitle(NS_IMAGE
, $dbKey);
65 $img = wfFindFile($title);
72 $repository = $img->getRepoName();
76 while($line = $img->nextHistoryLine()) { // assignment
77 # FIXME: Limiting to 500 because it's unlimited right now
78 # 500+ image histories are scarce, but this has DoS potential
79 # FileRepo.php should be fixed
82 $row = get_object_vars( $line );
84 $prefix = $isCur ?
'img' : 'oi';
87 $vals['timestamp'] = wfTimestamp(TS_ISO_8601
, $row["${prefix}_timestamp"]);
89 $vals['user'] = $row["${prefix}_user_text"];
90 if(!$row["${prefix}_user"])
94 $vals['size'] = intval($row["{$prefix}_size"]);
95 $vals['width'] = intval($row["{$prefix}_width"]);
96 $vals['height'] = intval($row["{$prefix}_height"]);
99 if($scale && $isCur) {
100 $vals['url'] = $img->createThumb($params['urlwidth'], $params['urlheight']);
102 $vals['url'] = $isCur ?
$img->getURL() : $img->getArchiveUrl($row["oi_archive_name"]);
106 $vals['comment'] = $row["{$prefix}_description"];
109 $vals['sha1'] = wfBaseConvert($row["{$prefix}_sha1"], 36, 16, 40);
112 $metadata = unserialize($row["{$prefix}_metadata"]);
113 $vals['metadata'] = $metadata ?
$metadata : null;
114 $this->getResult()->setIndexedTagName_recursive($vals['metadata'], 'meta');
119 if (!$history) // Stop after the first line.
125 $img->resetHistory();
128 $this->getResult()->addValue(array(
129 'query', 'pages', intval($pageId)),
130 'imagerepository', $repository
133 $this->addPageSubItems($pageId, $data);
138 protected function getAllowedParams() {
141 ApiBase
:: PARAM_ISMULTI
=> true,
142 ApiBase
:: PARAM_DFLT
=> 'timestamp|user',
143 ApiBase
:: PARAM_TYPE
=> array (
155 ApiBase
:: PARAM_TYPE
=> 'integer',
156 ApiBase
:: PARAM_DFLT
=> -1
158 'urlheight' => array(
159 ApiBase
:: PARAM_TYPE
=> 'integer',
160 ApiBase
:: PARAM_DFLT
=> -1
165 protected function getParamDescription() {
167 'prop' => 'What image information to get.',
168 'history' => 'Include upload history',
169 'urlwidth' => 'If iiprop=url is set, a URL to an image scaled to this width will be returned. Only the current version of the image can be scaled.',
170 'urlheight' => 'Similar to iiurlwidth. Cannot be used without iiurlwidth',
174 protected function getDescription() {
176 'Returns image information and upload history'
180 protected function getExamples() {
182 'api.php?action=query&titles=Image:Albert%20Einstein%20Head.jpg&prop=imageinfo',
183 'api.php?action=query&titles=Image:Test.jpg&prop=imageinfo&iihistory&iiprop=timestamp|user|url',
187 public function getVersion() {
188 return __CLASS__
. ': $Id$';