public function execute()
 {
     $params = $this->extractRequestParams();
     $modulePrefix = $this->getModulePrefix();
     $prop = array_flip($params['prop']);
     $scale = $this->getScale($params);
     $result = $this->getResult();
     if (!$params['filekey'] && !$params['sessionkey']) {
         $this->dieUsage("One of filekey or sessionkey must be supplied", 'nofilekey');
     }
     // Alias sessionkey to filekey, but give an existing filekey precedence.
     if (!$params['filekey'] && $params['sessionkey']) {
         $params['filekey'] = $params['sessionkey'];
     }
     try {
         $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash($this->getUser());
         foreach ($params['filekey'] as $filekey) {
             $file = $stash->getFile($filekey);
             $finalThumbParam = $this->mergeThumbParams($file, $scale, $params['urlparam']);
             $imageInfo = ApiQueryImageInfo::getInfo($file, $prop, $result, $finalThumbParam);
             $result->addValue(array('query', $this->getModuleName()), null, $imageInfo);
             $result->addIndexedTagName(array('query', $this->getModuleName()), $modulePrefix);
         }
         // @todo Update exception handling here to understand current getFile exceptions
     } catch (UploadStashFileNotFoundException $e) {
         $this->dieUsage("File not found: " . $e->getMessage(), "invalidsessiondata");
     } catch (UploadStashBadPathException $e) {
         $this->dieUsage("Bad path: " . $e->getMessage(), "invalidsessiondata");
     }
 }
 public function execute()
 {
     $user = $this->getUser();
     // Before doing anything at all, let's check permissions
     if (!$user->isAllowed('deletedhistory')) {
         $this->dieUsage('You don\'t have permission to view deleted file information', 'permissiondenied');
     }
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_sha1 = isset($prop['sha1']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_user = isset($prop['user']);
     $fld_size = isset($prop['size']);
     $fld_dimensions = isset($prop['dimensions']);
     $fld_description = isset($prop['description']) || isset($prop['parseddescription']);
     $fld_mime = isset($prop['mime']);
     $fld_mediatype = isset($prop['mediatype']);
     $fld_metadata = isset($prop['metadata']);
     $fld_bitdepth = isset($prop['bitdepth']);
     $fld_archivename = isset($prop['archivename']);
     $this->addTables('filearchive');
     $this->addFields(ArchivedFile::selectFields());
     $this->addFields(array('fa_id', 'fa_name', 'fa_timestamp', 'fa_deleted'));
     $this->addFieldsIf('fa_sha1', $fld_sha1);
     $this->addFieldsIf(array('fa_user', 'fa_user_text'), $fld_user);
     $this->addFieldsIf(array('fa_height', 'fa_width', 'fa_size'), $fld_dimensions || $fld_size);
     $this->addFieldsIf('fa_description', $fld_description);
     $this->addFieldsIf(array('fa_major_mime', 'fa_minor_mime'), $fld_mime);
     $this->addFieldsIf('fa_media_type', $fld_mediatype);
     $this->addFieldsIf('fa_metadata', $fld_metadata);
     $this->addFieldsIf('fa_bits', $fld_bitdepth);
     $this->addFieldsIf('fa_archive_name', $fld_archivename);
     if (!is_null($params['continue'])) {
         $cont = explode('|', $params['continue']);
         $this->dieContinueUsageIf(count($cont) != 3);
         $op = $params['dir'] == 'descending' ? '<' : '>';
         $cont_from = $db->addQuotes($cont[0]);
         $cont_timestamp = $db->addQuotes($db->timestamp($cont[1]));
         $cont_id = (int) $cont[2];
         $this->dieContinueUsageIf($cont[2] !== (string) $cont_id);
         $this->addWhere("fa_name {$op} {$cont_from} OR " . "(fa_name = {$cont_from} AND " . "(fa_timestamp {$op} {$cont_timestamp} OR " . "(fa_timestamp = {$cont_timestamp} AND " . "fa_id {$op}= {$cont_id} )))");
     }
     // Image filters
     $dir = $params['dir'] == 'descending' ? 'older' : 'newer';
     $from = $params['from'] === null ? null : $this->titlePartToKey($params['from'], NS_FILE);
     $to = $params['to'] === null ? null : $this->titlePartToKey($params['to'], NS_FILE);
     $this->addWhereRange('fa_name', $dir, $from, $to);
     if (isset($params['prefix'])) {
         $this->addWhere('fa_name' . $db->buildLike($this->titlePartToKey($params['prefix'], NS_FILE), $db->anyString()));
     }
     $sha1Set = isset($params['sha1']);
     $sha1base36Set = isset($params['sha1base36']);
     if ($sha1Set || $sha1base36Set) {
         $sha1 = false;
         if ($sha1Set) {
             $sha1 = strtolower($params['sha1']);
             if (!$this->validateSha1Hash($sha1)) {
                 $this->dieUsage('The SHA1 hash provided is not valid', 'invalidsha1hash');
             }
             $sha1 = wfBaseConvert($sha1, 16, 36, 31);
         } elseif ($sha1base36Set) {
             $sha1 = strtolower($params['sha1base36']);
             if (!$this->validateSha1Base36Hash($sha1)) {
                 $this->dieUsage('The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash');
             }
         }
         if ($sha1) {
             $this->addWhereFld('fa_sha1', $sha1);
         }
     }
     // Exclude files this user can't view.
     if (!$user->isAllowed('deletedtext')) {
         $bitmask = File::DELETED_FILE;
     } elseif (!$user->isAllowedAny('suppressrevision', 'viewsuppressed')) {
         $bitmask = File::DELETED_FILE | File::DELETED_RESTRICTED;
     } else {
         $bitmask = 0;
     }
     if ($bitmask) {
         $this->addWhere($this->getDB()->bitAnd('fa_deleted', $bitmask) . " != {$bitmask}");
     }
     $limit = $params['limit'];
     $this->addOption('LIMIT', $limit + 1);
     $sort = $params['dir'] == 'descending' ? ' DESC' : '';
     $this->addOption('ORDER BY', array('fa_name' . $sort, 'fa_timestamp' . $sort, 'fa_id' . $sort));
     $res = $this->select(__METHOD__);
     $count = 0;
     $result = $this->getResult();
     foreach ($res as $row) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are
             // additional pages to be had. Stop here...
             $this->setContinueEnumParameter('continue', "{$row->fa_name}|{$row->fa_timestamp}|{$row->fa_id}");
             break;
         }
         $file = array();
         $file['id'] = (int) $row->fa_id;
         $file['name'] = $row->fa_name;
         $title = Title::makeTitle(NS_FILE, $row->fa_name);
         self::addTitleInfo($file, $title);
         if ($fld_description && Revision::userCanBitfield($row->fa_deleted, File::DELETED_COMMENT, $user)) {
             $file['description'] = $row->fa_description;
             if (isset($prop['parseddescription'])) {
                 $file['parseddescription'] = Linker::formatComment($row->fa_description, $title);
             }
         }
         if ($fld_user && Revision::userCanBitfield($row->fa_deleted, File::DELETED_USER, $user)) {
             $file['userid'] = (int) $row->fa_user;
             $file['user'] = $row->fa_user_text;
         }
         if ($fld_sha1) {
             $file['sha1'] = wfBaseConvert($row->fa_sha1, 36, 16, 40);
         }
         if ($fld_timestamp) {
             $file['timestamp'] = wfTimestamp(TS_ISO_8601, $row->fa_timestamp);
         }
         if ($fld_size || $fld_dimensions) {
             $file['size'] = $row->fa_size;
             $pageCount = ArchivedFile::newFromRow($row)->pageCount();
             if ($pageCount !== false) {
                 $file['pagecount'] = $pageCount;
             }
             $file['height'] = $row->fa_height;
             $file['width'] = $row->fa_width;
         }
         if ($fld_mediatype) {
             $file['mediatype'] = $row->fa_media_type;
         }
         if ($fld_metadata) {
             $file['metadata'] = $row->fa_metadata ? ApiQueryImageInfo::processMetaData(unserialize($row->fa_metadata), $result) : null;
         }
         if ($fld_bitdepth) {
             $file['bitdepth'] = $row->fa_bits;
         }
         if ($fld_mime) {
             $file['mime'] = "{$row->fa_major_mime}/{$row->fa_minor_mime}";
         }
         if ($fld_archivename && !is_null($row->fa_archive_name)) {
             $file['archivename'] = $row->fa_archive_name;
         }
         if ($row->fa_deleted & File::DELETED_FILE) {
             $file['filehidden'] = true;
         }
         if ($row->fa_deleted & File::DELETED_COMMENT) {
             $file['commenthidden'] = true;
         }
         if ($row->fa_deleted & File::DELETED_USER) {
             $file['userhidden'] = true;
         }
         if ($row->fa_deleted & File::DELETED_RESTRICTED) {
             // This file is deleted for normal admins
             $file['suppressed'] = true;
         }
         $fit = $result->addValue(array('query', $this->getModuleName()), null, $file);
         if (!$fit) {
             $this->setContinueEnumParameter('continue', "{$row->fa_name}|{$row->fa_timestamp}|{$row->fa_id}");
             break;
         }
     }
     $result->addIndexedTagName(array('query', $this->getModuleName()), 'fa');
 }
 public static function getPropertyDescriptions($filter = array())
 {
     $s = parent::getPropertyDescriptions();
     $s[] = ' derivatives 	-Adds an array of video source derivatives';
     return $s;
 }
 public function getAllowedParams()
 {
     $ret = ['sort' => [ApiBase::PARAM_DFLT => 'name', ApiBase::PARAM_TYPE => ['name', 'timestamp']], 'dir' => [ApiBase::PARAM_DFLT => 'ascending', ApiBase::PARAM_TYPE => ['ascending', 'descending', 'newer', 'older']], 'from' => null, 'to' => null, 'continue' => [ApiBase::PARAM_HELP_MSG => 'api-help-param-continue'], 'start' => [ApiBase::PARAM_TYPE => 'timestamp'], 'end' => [ApiBase::PARAM_TYPE => 'timestamp'], 'prop' => [ApiBase::PARAM_TYPE => ApiQueryImageInfo::getPropertyNames($this->propertyFilter), ApiBase::PARAM_DFLT => 'timestamp|url', ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop', ApiBase::PARAM_HELP_MSG_PER_VALUE => ApiQueryImageInfo::getPropertyMessages($this->propertyFilter)], 'prefix' => null, 'minsize' => [ApiBase::PARAM_TYPE => 'integer'], 'maxsize' => [ApiBase::PARAM_TYPE => 'integer'], 'sha1' => null, 'sha1base36' => null, 'user' => [ApiBase::PARAM_TYPE => 'user'], 'filterbots' => [ApiBase::PARAM_DFLT => 'all', ApiBase::PARAM_TYPE => ['all', 'bots', 'nobots']], 'mime' => [ApiBase::PARAM_ISMULTI => true], 'limit' => [ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2]];
     if ($this->getConfig()->get('MiserMode')) {
         $ret['mime'][ApiBase::PARAM_HELP_MSG] = 'api-help-param-disabled-in-miser-mode';
     }
     return $ret;
 }
 public function getResultProperties()
 {
     return array_merge(array('' => array('name' => 'string', 'ns' => 'namespace', 'title' => 'string')), ApiQueryImageInfo::getResultPropertiesFiltered($this->propertyFilter));
 }
 public function execute()
 {
     $user = $this->getUser();
     // Before doing anything at all, let's check permissions
     if (!$user->isAllowed('deletedhistory')) {
         $this->dieUsage('You don\'t have permission to view deleted file information', 'permissiondenied');
     }
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_sha1 = isset($prop['sha1']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_user = isset($prop['user']);
     $fld_size = isset($prop['size']);
     $fld_dimensions = isset($prop['dimensions']);
     $fld_description = isset($prop['description']) || isset($prop['parseddescription']);
     $fld_mime = isset($prop['mime']);
     $fld_mediatype = isset($prop['mediatype']);
     $fld_metadata = isset($prop['metadata']);
     $fld_bitdepth = isset($prop['bitdepth']);
     $fld_archivename = isset($prop['archivename']);
     $this->addTables('filearchive');
     $this->addFields(array('fa_name', 'fa_deleted'));
     $this->addFieldsIf('fa_storage_key', $fld_sha1);
     $this->addFieldsIf('fa_timestamp', $fld_timestamp);
     $this->addFieldsIf(array('fa_user', 'fa_user_text'), $fld_user);
     $this->addFieldsIf(array('fa_height', 'fa_width', 'fa_size'), $fld_dimensions || $fld_size);
     $this->addFieldsIf('fa_description', $fld_description);
     $this->addFieldsIf(array('fa_major_mime', 'fa_minor_mime'), $fld_mime);
     $this->addFieldsIf('fa_media_type', $fld_mediatype);
     $this->addFieldsIf('fa_metadata', $fld_metadata);
     $this->addFieldsIf('fa_bits', $fld_bitdepth);
     $this->addFieldsIf('fa_archive_name', $fld_archivename);
     if (!is_null($params['continue'])) {
         $cont = explode('|', $params['continue']);
         if (count($cont) != 1) {
             $this->dieUsage("Invalid continue param. You should pass the " . "original value returned by the previous query", "_badcontinue");
         }
         $op = $params['dir'] == 'descending' ? '<' : '>';
         $cont_from = $db->addQuotes($cont[0]);
         $this->addWhere("fa_name {$op}= {$cont_from}");
     }
     // Image filters
     $dir = $params['dir'] == 'descending' ? 'older' : 'newer';
     $from = is_null($params['from']) ? null : $this->titlePartToKey($params['from']);
     if (!is_null($params['continue'])) {
         $from = $params['continue'];
     }
     $to = is_null($params['to']) ? null : $this->titlePartToKey($params['to']);
     $this->addWhereRange('fa_name', $dir, $from, $to);
     if (isset($params['prefix'])) {
         $this->addWhere('fa_name' . $db->buildLike($this->titlePartToKey($params['prefix']), $db->anyString()));
     }
     $sha1Set = isset($params['sha1']);
     $sha1base36Set = isset($params['sha1base36']);
     if ($sha1Set || $sha1base36Set) {
         global $wgMiserMode;
         if ($wgMiserMode) {
             $this->dieUsage('Search by hash disabled in Miser Mode', 'hashsearchdisabled');
         }
         $sha1 = false;
         if ($sha1Set) {
             if (!$this->validateSha1Hash($params['sha1'])) {
                 $this->dieUsage('The SHA1 hash provided is not valid', 'invalidsha1hash');
             }
             $sha1 = wfBaseConvert($params['sha1'], 16, 36, 31);
         } elseif ($sha1base36Set) {
             if (!$this->validateSha1Base36Hash($params['sha1base36'])) {
                 $this->dieUsage('The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash');
             }
             $sha1 = $params['sha1base36'];
         }
         if ($sha1) {
             $this->addWhere('fa_storage_key ' . $db->buildLike("{$sha1}.", $db->anyString()));
         }
     }
     if (!$user->isAllowed('suppressrevision')) {
         // Filter out revisions that the user is not allowed to see. There
         // is no way to indicate that we have skipped stuff because the
         // continuation parameter is fa_name
         // Note that this field is unindexed. This should however not be
         // a big problem as files with fa_deleted are rare
         $this->addWhereFld('fa_deleted', 0);
     }
     $limit = $params['limit'];
     $this->addOption('LIMIT', $limit + 1);
     $sort = $params['dir'] == 'descending' ? ' DESC' : '';
     $this->addOption('ORDER BY', 'fa_name' . $sort);
     $res = $this->select(__METHOD__);
     $count = 0;
     $result = $this->getResult();
     foreach ($res as $row) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             $this->setContinueEnumParameter('continue', $row->fa_name);
             break;
         }
         $file = array();
         $file['name'] = $row->fa_name;
         $title = Title::makeTitle(NS_FILE, $row->fa_name);
         self::addTitleInfo($file, $title);
         if ($fld_sha1) {
             $file['sha1'] = wfBaseConvert(LocalRepo::getHashFromKey($row->fa_storage_key), 36, 16, 40);
         }
         if ($fld_timestamp) {
             $file['timestamp'] = wfTimestamp(TS_ISO_8601, $row->fa_timestamp);
         }
         if ($fld_user) {
             $file['userid'] = $row->fa_user;
             $file['user'] = $row->fa_user_text;
         }
         if ($fld_size || $fld_dimensions) {
             $file['size'] = $row->fa_size;
             $pageCount = ArchivedFile::newFromRow($row)->pageCount();
             if ($pageCount !== false) {
                 $vals['pagecount'] = $pageCount;
             }
             $file['height'] = $row->fa_height;
             $file['width'] = $row->fa_width;
         }
         if ($fld_description) {
             $file['description'] = $row->fa_description;
             if (isset($prop['parseddescription'])) {
                 $file['parseddescription'] = Linker::formatComment($row->fa_description, $title);
             }
         }
         if ($fld_mediatype) {
             $file['mediatype'] = $row->fa_media_type;
         }
         if ($fld_metadata) {
             $file['metadata'] = $row->fa_metadata ? ApiQueryImageInfo::processMetaData(unserialize($row->fa_metadata), $result) : null;
         }
         if ($fld_bitdepth) {
             $file['bitdepth'] = $row->fa_bits;
         }
         if ($fld_mime) {
             $file['mime'] = "{$row->fa_major_mime}/{$row->fa_minor_mime}";
         }
         if ($fld_archivename && !is_null($row->fa_archive_name)) {
             $file['archivename'] = $row->fa_archive_name;
         }
         if ($row->fa_deleted & File::DELETED_FILE) {
             $file['filehidden'] = '';
         }
         if ($row->fa_deleted & File::DELETED_COMMENT) {
             $file['commenthidden'] = '';
         }
         if ($row->fa_deleted & File::DELETED_USER) {
             $file['userhidden'] = '';
         }
         if ($row->fa_deleted & File::DELETED_RESTRICTED) {
             // This file is deleted for normal admins
             $file['suppressed'] = '';
         }
         $fit = $result->addValue(array('query', $this->getModuleName()), null, $file);
         if (!$fit) {
             $this->setContinueEnumParameter('continue', $row->fa_name);
             break;
         }
     }
     $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'fa');
 }
 private function run($resultPageSet = null)
 {
     $repo = RepoGroup::singleton()->getLocalRepo();
     if (!$repo instanceof LocalRepo) {
         $this->dieUsage('Local file repository does not support querying all images', 'unsupportedrepo');
     }
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     // Image filters
     $dir = $params['dir'] == 'descending' ? 'older' : 'newer';
     $from = is_null($params['from']) ? null : $this->titlePartToKey($params['from']);
     $this->addWhereRange('img_name', $dir, $from, null);
     if (isset($params['prefix'])) {
         $this->addWhere("img_name LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
     }
     if (isset($params['minsize'])) {
         $this->addWhere('img_size>=' . intval($params['minsize']));
     }
     if (isset($params['maxsize'])) {
         $this->addWhere('img_size<=' . intval($params['maxsize']));
     }
     $sha1 = false;
     if (isset($params['sha1'])) {
         $sha1 = wfBaseConvert($params['sha1'], 16, 36, 31);
     } elseif (isset($params['sha1base36'])) {
         $sha1 = $params['sha1base36'];
     }
     if ($sha1) {
         $this->addWhere('img_sha1=' . $db->addQuotes($sha1));
     }
     $this->addTables('image');
     $prop = array_flip($params['prop']);
     $this->addFields(LocalFile::selectFields());
     $limit = $params['limit'];
     $this->addOption('LIMIT', $limit + 1);
     $this->addOption('ORDER BY', 'img_name' . ($params['dir'] == 'descending' ? ' DESC' : ''));
     $res = $this->select(__METHOD__);
     $titles = array();
     $count = 0;
     $result = $this->getResult();
     while ($row = $db->fetchObject($res)) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             // TODO: Security issue - if the user has no right to view next title, it will still be shown
             $this->setContinueEnumParameter('from', $this->keyToTitle($row->img_name));
             break;
         }
         if (is_null($resultPageSet)) {
             $file = $repo->newFileFromRow($row);
             $info = array_merge(array('name' => $row->img_name), ApiQueryImageInfo::getInfo($file, $prop, $result));
             $fit = $result->addValue(array('query', $this->getModuleName()), null, $info);
             if (!$fit) {
                 $this->setContinueEnumParameter('from', $this->keyToTitle($row->img_name));
                 break;
             }
         } else {
             $titles[] = Title::makeTitle(NS_IMAGE, $row->img_name);
         }
     }
     $db->freeResult($res);
     if (is_null($resultPageSet)) {
         $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'img');
     } else {
         $resultPageSet->populateFromTitles($titles);
     }
 }
 /**
  * Gets image info about the file just uploaded.
  *
  * Also has the effect of setting metadata to be an 'indexed tag name' in returned API result if
  * 'metadata' was requested. Oddly, we have to pass the "result" object down just so it can do that
  * with the appropriate format, presumably.
  *
  * @param $result ApiResult:
  * @return Array: image info
  */
 public function getImageInfo($result)
 {
     $file = $this->getLocalFile();
     // TODO This cries out for refactoring. We really want to say $file->getAllInfo(); here.
     // Perhaps "info" methods should be moved into files, and the API should just wrap them in queries.
     if ($file instanceof UploadStashFile) {
         $imParam = ApiQueryStashImageInfo::getPropertyNames();
         $info = ApiQueryStashImageInfo::getInfo($file, array_flip($imParam), $result);
     } else {
         $imParam = ApiQueryImageInfo::getPropertyNames();
         $info = ApiQueryImageInfo::getInfo($file, array_flip($imParam), $result);
     }
     return $info;
 }
Exemple #9
0
 /**
  * Gets image info about the file just uploaded.
  *
  * Also has the effect of setting metadata to be an 'indexed tag name' in
  * returned API result if 'metadata' was requested. Oddly, we have to pass
  * the "result" object down just so it can do that with the appropriate
  * format, presumably.
  *
  * @param ApiResult $result
  * @return array Image info
  */
 public function getImageInfo($result)
 {
     $localFile = $this->getLocalFile();
     $stashFile = $this->getStashFile();
     // Calling a different API module depending on whether the file was stashed is less than optimal.
     // In fact, calling API modules here at all is less than optimal. Maybe it should be refactored.
     if ($stashFile) {
         $imParam = ApiQueryStashImageInfo::getPropertyNames();
         $info = ApiQueryStashImageInfo::getInfo($stashFile, array_flip($imParam), $result);
     } else {
         $imParam = ApiQueryImageInfo::getPropertyNames();
         $info = ApiQueryImageInfo::getInfo($localFile, array_flip($imParam), $result);
     }
     return $info;
 }
 public function execute()
 {
     global $wgUser;
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('deletedhistory')) {
         $this->dieUsage('You don\'t have permission to view deleted file information', 'permissiondenied');
     }
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_sha1 = isset($prop['sha1']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_user = isset($prop['user']);
     $fld_size = isset($prop['size']);
     $fld_dimensions = isset($prop['dimensions']);
     $fld_description = isset($prop['description']);
     $fld_mime = isset($prop['mime']);
     $fld_metadata = isset($prop['metadata']);
     $fld_bitdepth = isset($prop['bitdepth']);
     $this->addTables('filearchive');
     $this->addFields(array('fa_name', 'fa_deleted'));
     $this->addFieldsIf('fa_storage_key', $fld_sha1);
     $this->addFieldsIf('fa_timestamp', $fld_timestamp);
     if ($fld_user) {
         $this->addFields(array('fa_user', 'fa_user_text'));
     }
     $this->addFieldsIf('fa_size', $fld_size);
     if ($fld_dimensions) {
         $this->addFields(array('fa_height', 'fa_width'));
     }
     $this->addFieldsIf('fa_description', $fld_description);
     if ($fld_mime) {
         $this->addFields(array('fa_major_mime', 'fa_minor_mime'));
     }
     $this->addFieldsIf('fa_metadata', $fld_metadata);
     $this->addFieldsIf('fa_bits', $fld_bitdepth);
     // Image filters
     $dir = $params['dir'] == 'descending' ? 'older' : 'newer';
     $from = is_null($params['from']) ? null : $this->titlePartToKey($params['from']);
     $this->addWhereRange('fa_name', $dir, $from, null);
     if (isset($params['prefix'])) {
         $this->addWhere('fa_name' . $db->buildLike($this->titlePartToKey($params['prefix']), $db->anyString()));
     }
     if (!$wgUser->isAllowed('suppressrevision')) {
         // Filter out revisions that the user is not allowed to see. There
         // is no way to indicate that we have skipped stuff because the
         // continuation parameter is fa_name
         // Note that this field is unindexed. This should however not be
         // a big problem as files with fa_deleted are rare
         $this->addWhereFld('fa_deleted', 0);
     }
     $limit = $params['limit'];
     $this->addOption('LIMIT', $limit + 1);
     $this->addOption('ORDER BY', 'fa_name' . ($params['dir'] == 'descending' ? ' DESC' : ''));
     $res = $this->select(__METHOD__);
     $count = 0;
     $result = $this->getResult();
     foreach ($res as $row) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             // TODO: Security issue - if the user has no right to view next title, it will still be shown
             $this->setContinueEnumParameter('from', $this->keyToTitle($row->fa_name));
             break;
         }
         $file = array();
         $file['name'] = $row->fa_name;
         if ($fld_sha1) {
             $file['sha1'] = wfBaseConvert($row->fa_storage_key, 36, 16, 40);
         }
         if ($fld_timestamp) {
             $file['timestamp'] = wfTimestamp(TS_ISO_8601, $row->fa_timestamp);
         }
         if ($fld_user) {
             $file['userid'] = $row->fa_user;
             $file['user'] = $row->fa_user_text;
         }
         if ($fld_size) {
             $file['size'] = $row->fa_size;
         }
         if ($fld_dimensions) {
             $file['height'] = $row->fa_height;
             $file['width'] = $row->fa_width;
         }
         if ($fld_description) {
             $file['description'] = $row->fa_description;
         }
         if ($fld_metadata) {
             $file['metadata'] = $row->fa_metadata ? ApiQueryImageInfo::processMetaData(unserialize($row->fa_metadata), $result) : null;
         }
         if ($fld_bitdepth) {
             $file['bitdepth'] = $row->fa_bits;
         }
         if ($fld_mime) {
             $file['mime'] = "{$row->fa_major_mime}/{$row->fa_minor_mime}";
         }
         if ($row->fa_deleted & File::DELETED_FILE) {
             $file['filehidden'] = '';
         }
         if ($row->fa_deleted & File::DELETED_COMMENT) {
             $file['commenthidden'] = '';
         }
         if ($row->fa_deleted & File::DELETED_USER) {
             $file['userhidden'] = '';
         }
         if ($row->fa_deleted & File::DELETED_RESTRICTED) {
             // This file is deleted for normal admins
             $file['suppressed'] = '';
         }
         $fit = $result->addValue(array('query', $this->getModuleName()), null, $file);
         if (!$fit) {
             $this->setContinueEnumParameter('from', $this->keyToTitle($row->fa_name));
             break;
         }
     }
     $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'fa');
 }
 public function getResultProperties()
 {
     return ApiQueryImageInfo::getResultPropertiesFiltered($this->propertyFilter);
 }
 public function getAllowedParams()
 {
     return array('from' => null, 'prefix' => null, 'minsize' => array(ApiBase::PARAM_TYPE => 'integer'), 'maxsize' => array(ApiBase::PARAM_TYPE => 'integer'), 'limit' => array(ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2), 'dir' => array(ApiBase::PARAM_DFLT => 'ascending', ApiBase::PARAM_TYPE => array('ascending', 'descending')), 'sha1' => null, 'sha1base36' => null, 'prop' => array(ApiBase::PARAM_TYPE => ApiQueryImageInfo::getPropertyNames(), ApiBase::PARAM_DFLT => 'timestamp|url', ApiBase::PARAM_ISMULTI => true));
 }
 public function getPossibleErrors()
 {
     return array_merge(parent::getPossibleErrors(), array(array('code' => 'siiurlwidth', 'info' => 'siiurlheight cannot be used without iiurlwidth')));
 }
 public function getParamDescription()
 {
     return array('from' => 'The image title to start enumerating from', 'to' => 'The image title to stop enumerating at', 'prefix' => 'Search for all image titles that begin with this value', 'dir' => 'The direction in which to list', 'minsize' => 'Limit to images with at least this many bytes', 'maxsize' => 'Limit to images with at most this many bytes', 'limit' => 'How many images in total to return', 'sha1' => "SHA1 hash of image. Overrides {$this->getModulePrefix()}sha1base36", 'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki)', 'prop' => ApiQueryImageInfo::getPropertyDescriptions($this->propertyFilter), 'mime' => 'What MIME type to search for. e.g. image/jpeg. Disabled in Miser Mode');
 }
Exemple #15
0
 public function getParamDescription()
 {
     $p = $this->getModulePrefix();
     return array('sort' => 'Property to sort by', 'dir' => 'The direction in which to list', 'from' => "The image title to start enumerating from. Can only be used with {$p}sort=name", 'to' => "The image title to stop enumerating at. Can only be used with {$p}sort=name", 'continue' => 'When more results are available, use this to continue', 'start' => "The timestamp to start enumerating from. Can only be used with {$p}sort=timestamp", 'end' => "The timestamp to end enumerating. Can only be used with {$p}sort=timestamp", 'prop' => ApiQueryImageInfo::getPropertyDescriptions($this->propertyFilter), 'prefix' => "Search for all image titles that begin with this " . "value. Can only be used with {$p}sort=name", 'minsize' => 'Limit to images with at least this many bytes', 'maxsize' => 'Limit to images with at most this many bytes', 'sha1' => "SHA1 hash of image. Overrides {$p}sha1base36", 'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki)', 'user' => "Only return files uploaded by this user. Can only be used " . "with {$p}sort=timestamp. Cannot be used together with {$p}filterbots", 'filterbots' => "How to filter files uploaded by bots. Can only be " . "used with {$p}sort=timestamp. Cannot be used together with {$p}user", 'mime' => 'What MIME type to search for. e.g. image/jpeg. Disabled in Miser Mode', 'limit' => 'How many images in total to return');
 }