r35085 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35084‎ | r35085 | r35086 >
Date:14:32, 20 May 2008
Author:btongminh
Status:old
Tags:
Comment:
Use ApiQueryImageInfo::getInfo for both ApiQueryAllimages and ApiQueryImageInfo. Should also give some more consistency between the two modules.
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllimages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryImageInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryImageInfo.php
@@ -43,24 +43,22 @@
4444 $params = $this->extractRequestParams();
4545
4646 $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']);
5647
5748 if($params['urlheight'] != -1 && $params['urlwidth'] == -1)
5849 $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+ }
6258
6359 $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
6460 if (!empty($pageIds[NS_IMAGE])) {
 61+
 62+ $result = $this->getResult();
6563 foreach ($pageIds[NS_IMAGE] as $dbKey => $pageId) {
6664
6765 $title = Title :: makeTitle(NS_IMAGE, $dbKey);
@@ -77,7 +75,7 @@
7876 // Check that the current version is within the start-end boundaries
7977 if((is_null($params['start']) || $img->getTimestamp() <= $params['start']) &&
8078 (is_null($params['end']) || $img->getTimestamp() >= $params['end'])) {
81 - $data[] = $this->getInfo($img);
 79+ $data[] = self::getInfo( $img, $prop, $result, $scale );
8280 }
8381
8482 // Now get the old revisions
@@ -92,11 +90,11 @@
9391 $this->setContinueEnumParameter('start', $oldie->getTimestamp());
9492 break;
9593 }
96 - $data[] = $this->getInfo($oldie);
 94+ $data[] = $this->getInfo( $oldie, $prop, $result );
9795 }
9896 }
9997
100 - $this->getResult()->addValue(array(
 98+ $result->addValue(array(
10199 'query', 'pages', intval($pageId)),
102100 'imagerepository', $repository
103101 );
@@ -111,45 +109,46 @@
112110 * @param File f The image
113111 * @return array Result array
114112 */
115 - protected function getInfo($f) {
 113+ static function getInfo($file, $prop, $result, $scale = null) {
116114 $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' ) )
122120 $vals['anon'] = '';
123121 }
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() );
128126 }
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 )
133131 {
134132 $vals['thumburl'] = wfExpandUrl( $thumb->getURL() );
135133 $vals['thumbwidth'] = $thumb->getWidth();
136134 $vals['thumbheight'] = $thumb->getHeight();
137135 }
138136 }
139 - $vals['url'] = $f->getFullURL();
 137+ $vals['url'] = $file->getFullURL();
140138 }
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' );
151147 }
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();
154153
155154 return $vals;
156155 }
Index: trunk/phase3/includes/api/ApiQueryAllimages.php
@@ -98,6 +98,7 @@
9999
100100 $data = array ();
101101 $count = 0;
 102+ $result = $this->getResult();
102103 while ($row = $db->fetchObject($res)) {
103104 if (++ $count > $limit) {
104105 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
@@ -108,29 +109,8 @@
109110
110111 if (is_null($resultPageSet)) {
111112 $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 );
135115 } else {
136116 $data[] = Title::makeTitle( NS_IMAGE, $row->img_name );
137117 }
@@ -175,9 +155,11 @@
176156 'prop' => array (
177157 ApiBase :: PARAM_TYPE => array(
178158 'timestamp',
 159+ 'user',
 160+ 'comment',
179161 'url',
180162 'size',
181 - 'dimensions',
 163+ 'dimensions', // Obsolete
182164 'mime',
183165 'sha1',
184166 'metadata'

Follow-up revisions

RevisionCommit summaryAuthorDate
r41303API: Add the name attribute back to list=allimages; it disappeared in r35085catrope11:04, 27 September 2008

Status & tagging log