r34941 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34940‎ | r34941 | r34942 >
Date:21:25, 16 May 2008
Author:btongminh
Status:old
Tags:
Comment:
Throw an error if the local repository is not a LocalRepo or one of its derived classes. Use proper newFileFrom row to prevent double fetching from database.
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllimages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllimages.php
@@ -52,6 +52,9 @@
5353 }
5454
5555 private function run($resultPageSet = null) {
 56+ $repo = RepoGroup::singleton()->getLocalRepo();
 57+ if ( !is_a( $repo, 'LocalRepo' ) )
 58+ $this->dieUsage('Local file repository does not support querying all images', 'unsupportedrepo');
5659
5760 $db = $this->getDB();
5861
@@ -84,11 +87,7 @@
8588 $this->addTables('image');
8689
8790 $prop = array_flip($params['prop']);
88 - $this->addFields('img_name');
89 - $this->addFieldsIf('img_size', isset($prop['size']));
90 - $this->addFieldsIf(array('img_width', 'img_height'), isset($prop['dimensions']));
91 - $this->addFieldsIf(array('img_major_mime', 'img_minor_mime'), isset($prop['mime']));
92 - $this->addFieldsIf('img_timestamp', isset($prop['timestamp']));
 91+ $this->addFields( LocalFile::selectFields() );
9392
9493 $limit = $params['limit'];
9594 $this->addOption('LIMIT', $limit+1);
@@ -108,7 +107,7 @@
109108 }
110109
111110 if (is_null($resultPageSet)) {
112 - $file = wfLocalFile( $row->img_name );
 111+ $file = $repo->newFileFromRow( $row );
113112 $item['name'] = $row->img_name;
114113 if(isset($prop['size']))
115114 $item['size'] = $file->getSize();
@@ -118,13 +117,13 @@
119118 $item['height'] = $file->getHeight();
120119 }
121120 if(isset($prop['mime']))
122 - $item['mime'] = $row->img_major_mime . '/' . $row->img_minor_mime;
 121+ $item['mime'] = $file->getMimeType();
123122 if(isset($prop['sha1']))
124123 $item['sha1'] = wfBaseConvert($file->getSha1(), 36, 16, 31);
125124 if(isset($prop['timestamp']))
126125 $item['timestamp'] = wfTimestamp(TS_ISO_8601, $file->getTimestamp());
127126 if(isset($prop['url']))
128 - $item['url'] = $file->getUrl();
 127+ $item['url'] = $file->getFullUrl();
129128 $data[] = $item;
130129 } else {
131130 $data[] = Title::makeTitle( NS_IMAGE, $row->img_name );

Status & tagging log