f4f92fc0e3d7a9b7d75ba8b65bb37d9088f9892e
[lhc/web/wiklou.git] / includes / api / ApiQueryImageInfo.php
1 <?php
2
3 /*
4 * Created on July 6, 2007
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 *
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.
14 *
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.
19 *
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
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
29 }
30
31 /**
32 * A query action to get image information and upload history.
33 *
34 * @addtogroup API
35 */
36 class ApiQueryImageInfo extends ApiQueryBase {
37
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'ii');
40 }
41
42 public function execute() {
43 $params = $this->extractRequestParams();
44
45 $history = $params['history'];
46
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
54 $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
55 if (!empty($pageIds[NS_IMAGE])) {
56 foreach ($pageIds[NS_IMAGE] as $dbKey => $pageId) {
57
58 $title = Title :: makeTitle(NS_IMAGE, $dbKey);
59 $img = wfFindFile($title);
60
61 $data = array();
62 if ( !$img ) {
63 $data['missing'] = '';
64 } else {
65
66 $data['repository'] = $img->getRepoName();
67
68 $isCur = true;
69 while($line = $img->nextHistoryLine()) { // assignment
70 $vals = array();
71
72 if ($fld_timestamp)
73 $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $line->img_timestamp);
74 if ($fld_user) {
75 $vals['user'] = $line->img_user_text;
76 if(!$line->img_user)
77 $vals['anon'] = '';
78 }
79 if ($fld_size) {
80 $vals['size'] = $line->img_size;
81 $vals['width'] = $line->img_width;
82 $vals['height'] = $line->img_height;
83 }
84 if ($fld_url)
85 $vals['url'] = $isCur ? $img->getURL() : $img->getArchiveUrl($line->oi_archive_name);
86 if ($fld_comment)
87 $vals['comment'] = $line->img_description;
88
89 $data[] = $vals;
90
91 if (!$history) // Stop after the first line.
92 break;
93
94 $isCur = false;
95 }
96
97 $img->resetHistory();
98 }
99
100 $this->addPageSubItems($pageId, $data);
101 }
102 }
103 }
104
105 protected function getAllowedParams() {
106 return array (
107 'prop' => array (
108 ApiBase :: PARAM_ISMULTI => true,
109 ApiBase :: PARAM_DFLT => 'timestamp|user',
110 ApiBase :: PARAM_TYPE => array (
111 'timestamp',
112 'user',
113 'comment',
114 'url',
115 'size',
116 )
117 ),
118 'history' => false,
119 );
120 }
121
122 protected function getParamDescription() {
123 return array (
124 'prop' => 'What image information to get.',
125 'history' => 'Include upload history',
126 );
127 }
128
129 protected function getDescription() {
130 return array (
131 'Returns image information and upload history'
132 );
133 }
134
135 protected function getExamples() {
136 return array (
137 'api.php?action=query&titles=Image:Albert%20Einstein%20Head.jpg&prop=imageinfo',
138 'api.php?action=query&titles=Image:Test.jpg&prop=imageinfo&iihistory&iiprop=timestamp|user|url',
139 );
140 }
141
142 public function getVersion() {
143 return __CLASS__ . ': $Id$';
144 }
145 }