Index: trunk/phase3/includes/api/ApiQueryImageInfo.php |
— | — | @@ -43,24 +43,22 @@ |
44 | 44 | $params = $this->extractRequestParams(); |
45 | 45 | |
46 | 46 | $prop = array_flip($params['prop']); |
47 | | - $this->fld_timestamp = isset($prop['timestamp']); |
48 | | - $this->fld_user = isset($prop['user']); |
49 | | - $this->fld_comment = isset($prop['comment']); |
50 | | - $this->fld_url = isset($prop['url']); |
51 | | - $this->fld_size = isset($prop['size']); |
52 | | - $this->fld_sha1 = isset($prop['sha1']); |
53 | | - $this->fld_mime = isset($prop['mime']); |
54 | | - $this->fld_metadata = isset($prop['metadata']); |
55 | | - $this->fld_archivename = isset($prop['archivename']); |
56 | 47 | |
57 | 48 | if($params['urlheight'] != -1 && $params['urlwidth'] == -1) |
58 | 49 | $this->dieUsage("iiurlheight cannot be used without iiurlwidth", 'iiurlwidth'); |
59 | | - $this->scale = ($params['urlwidth'] != -1); |
60 | | - $this->urlwidth = $params['urlwidth']; |
61 | | - $this->urlheight = $params['urlheight']; |
| 50 | + |
| 51 | + if ( $params['urlwidth'] != -1 ) { |
| 52 | + $scale = array(); |
| 53 | + $scale['width'] = $params['urlwidth']; |
| 54 | + $scale['height'] = $params['urlheight']; |
| 55 | + } else { |
| 56 | + $scale = null; |
| 57 | + } |
62 | 58 | |
63 | 59 | $pageIds = $this->getPageSet()->getAllTitlesByNamespace(); |
64 | 60 | if (!empty($pageIds[NS_IMAGE])) { |
| 61 | + |
| 62 | + $result = $this->getResult(); |
65 | 63 | foreach ($pageIds[NS_IMAGE] as $dbKey => $pageId) { |
66 | 64 | |
67 | 65 | $title = Title :: makeTitle(NS_IMAGE, $dbKey); |
— | — | @@ -77,7 +75,7 @@ |
78 | 76 | // Check that the current version is within the start-end boundaries |
79 | 77 | if((is_null($params['start']) || $img->getTimestamp() <= $params['start']) && |
80 | 78 | (is_null($params['end']) || $img->getTimestamp() >= $params['end'])) { |
81 | | - $data[] = $this->getInfo($img); |
| 79 | + $data[] = self::getInfo( $img, $prop, $result, $scale ); |
82 | 80 | } |
83 | 81 | |
84 | 82 | // Now get the old revisions |
— | — | @@ -92,11 +90,11 @@ |
93 | 91 | $this->setContinueEnumParameter('start', $oldie->getTimestamp()); |
94 | 92 | break; |
95 | 93 | } |
96 | | - $data[] = $this->getInfo($oldie); |
| 94 | + $data[] = $this->getInfo( $oldie, $prop, $result ); |
97 | 95 | } |
98 | 96 | } |
99 | 97 | |
100 | | - $this->getResult()->addValue(array( |
| 98 | + $result->addValue(array( |
101 | 99 | 'query', 'pages', intval($pageId)), |
102 | 100 | 'imagerepository', $repository |
103 | 101 | ); |
— | — | @@ -111,45 +109,46 @@ |
112 | 110 | * @param File f The image |
113 | 111 | * @return array Result array |
114 | 112 | */ |
115 | | - protected function getInfo($f) { |
| 113 | + static function getInfo($file, $prop, $result, $scale = null) { |
116 | 114 | $vals = array(); |
117 | | - if($this->fld_timestamp) |
118 | | - $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $f->getTimestamp()); |
119 | | - if($this->fld_user) { |
120 | | - $vals['user'] = $f->getUser(); |
121 | | - if(!$f->getUser('id')) |
| 115 | + if( isset( $prop['timestamp'] ) ) |
| 116 | + $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $file->getTimestamp()); |
| 117 | + if( isset( $prop['user'] ) ) { |
| 118 | + $vals['user'] = $file->getUser(); |
| 119 | + if( !$file->getUser( 'id' ) ) |
122 | 120 | $vals['anon'] = ''; |
123 | 121 | } |
124 | | - if($this->fld_size) { |
125 | | - $vals['size'] = intval($f->getSize()); |
126 | | - $vals['width'] = intval($f->getWidth()); |
127 | | - $vals['height'] = intval($f->getHeight()); |
| 122 | + if( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) { |
| 123 | + $vals['size'] = intval( $file->getSize() ); |
| 124 | + $vals['width'] = intval( $file->getWidth() ); |
| 125 | + $vals['height'] = intval( $file->getHeight() ); |
128 | 126 | } |
129 | | - if($this->fld_url) { |
130 | | - if($this->scale && !$f->isOld()) { |
131 | | - $thumb = $f->getThumbnail($this->urlwidth, $this->urlheight); |
132 | | - if($thumb) |
| 127 | + if( isset( $prop['url'] ) ) { |
| 128 | + if( !is_null( $scale ) && !$file->isOld() ) { |
| 129 | + $thumb = $file->getThumbnail( $scale['width'], $scale['height'] ); |
| 130 | + if( $thumb ) |
133 | 131 | { |
134 | 132 | $vals['thumburl'] = wfExpandUrl( $thumb->getURL() ); |
135 | 133 | $vals['thumbwidth'] = $thumb->getWidth(); |
136 | 134 | $vals['thumbheight'] = $thumb->getHeight(); |
137 | 135 | } |
138 | 136 | } |
139 | | - $vals['url'] = $f->getFullURL(); |
| 137 | + $vals['url'] = $file->getFullURL(); |
140 | 138 | } |
141 | | - if($this->fld_comment) |
142 | | - $vals['comment'] = $f->getDescription(); |
143 | | - if($this->fld_sha1) |
144 | | - $vals['sha1'] = wfBaseConvert($f->getSha1(), 36, 16, 40); |
145 | | - if($this->fld_mime) |
146 | | - $vals['mime'] = $f->getMimeType(); |
147 | | - if($this->fld_metadata) { |
148 | | - $metadata = unserialize($f->getMetadata()); |
149 | | - $vals['metadata'] = $metadata ? $metadata : null; |
150 | | - $this->getResult()->setIndexedTagName_recursive($vals['metadata'], 'meta'); |
| 139 | + if( isset( $prop['comment'] ) ) |
| 140 | + $vals['comment'] = $file->getDescription(); |
| 141 | + if( isset( $prop['sha1'] ) ) |
| 142 | + $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 ); |
| 143 | + if( isset( $prop['metadata'] ) ) { |
| 144 | + $metadata = $file->getMetadata(); |
| 145 | + $vals['metadata'] = $metadata ? unserialize( $metadata ) : null; |
| 146 | + $result->setIndexedTagName_recursive( $vals['metadata'], 'meta' ); |
151 | 147 | } |
152 | | - if($this->fld_archivename && $f->isOld()) |
153 | | - $vals['archivename'] = $f->getArchiveName(); |
| 148 | + if( isset( $prop['mimetype'] ) ) |
| 149 | + $vals['mime'] = $file->getMimeType(); |
| 150 | + |
| 151 | + if( isset( $prop['archivename'] ) && $file->isOld() ) |
| 152 | + $vals['archivename'] = $file->getArchiveName(); |
154 | 153 | |
155 | 154 | return $vals; |
156 | 155 | } |
Index: trunk/phase3/includes/api/ApiQueryAllimages.php |
— | — | @@ -98,6 +98,7 @@ |
99 | 99 | |
100 | 100 | $data = array (); |
101 | 101 | $count = 0; |
| 102 | + $result = $this->getResult(); |
102 | 103 | while ($row = $db->fetchObject($res)) { |
103 | 104 | if (++ $count > $limit) { |
104 | 105 | // We've reached the one extra which shows that there are additional pages to be had. Stop here... |
— | — | @@ -108,29 +109,8 @@ |
109 | 110 | |
110 | 111 | if (is_null($resultPageSet)) { |
111 | 112 | $file = $repo->newFileFromRow( $row ); |
112 | | - $item['name'] = $row->img_name; |
113 | | - if(isset($prop['size'])) |
114 | | - $item['size'] = $file->getSize(); |
115 | | - if(isset($prop['dimensions'])) |
116 | | - { |
117 | | - $item['width'] = $file->getWidth(); |
118 | | - $item['height'] = $file->getHeight(); |
119 | | - } |
120 | | - if(isset($prop['mime'])) |
121 | | - $item['mime'] = $file->getMimeType(); |
122 | | - if(isset($prop['sha1'])) |
123 | | - $item['sha1'] = wfBaseConvert($file->getSha1(), 36, 16, 31); |
124 | | - if(isset($prop['timestamp'])) |
125 | | - $item['timestamp'] = wfTimestamp(TS_ISO_8601, $file->getTimestamp()); |
126 | | - if(isset($prop['url'])) |
127 | | - $item['url'] = $file->getFullUrl(); |
128 | | - if(isset($prop['metadata'])) |
129 | | - { |
130 | | - $metadata = unserialize($file->getMetadata()); |
131 | | - $item['metadata'] = $metadata ? $metadata : null; |
132 | | - $this->getResult()->setIndexedTagName_recursive($item['metadata'], 'meta'); |
133 | | - } |
134 | | - $data[] = $item; |
| 113 | + |
| 114 | + $data[] = ApiQueryImageInfo::getInfo( $file, $prop, $result ); |
135 | 115 | } else { |
136 | 116 | $data[] = Title::makeTitle( NS_IMAGE, $row->img_name ); |
137 | 117 | } |
— | — | @@ -175,9 +155,11 @@ |
176 | 156 | 'prop' => array ( |
177 | 157 | ApiBase :: PARAM_TYPE => array( |
178 | 158 | 'timestamp', |
| 159 | + 'user', |
| 160 | + 'comment', |
179 | 161 | 'url', |
180 | 162 | 'size', |
181 | | - 'dimensions', |
| 163 | + 'dimensions', // Obsolete |
182 | 164 | 'mime', |
183 | 165 | 'sha1', |
184 | 166 | 'metadata' |