== API changes since 1.10 ==
-(For ongoing development discussion, see http://www.mediawiki.org/wiki/API)
+Full API documentation is available at http://www.mediawiki.org/wiki/API
* New properties: links, templates, images, langlinks, categories, external
links
* (bug 10297) include previous revision ID in prop=revisions
* backlinks, embeddedin and imageusage lists should use (bl|ei|iu)title parameter
instead of titles. Titles for these lists is obsolete and might stop working soon.
+* Added prop=imageinfo - gets image properties and upload history
== Maintenance script changes since 1.10 ==
'ApiQueryContributions' => 'includes/api/ApiQueryUserContributions.php',
'ApiQueryExternalLinks' => 'includes/api/ApiQueryExternalLinks.php',
'ApiQueryImages' => 'includes/api/ApiQueryImages.php',
+ 'ApiQueryImageInfo' => 'includes/api/ApiQueryImageInfo.php',
'ApiQueryInfo' => 'includes/api/ApiQueryInfo.php',
'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php',
'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php',
const LIMIT_SML1 = 50; // Slow query, std user limit
const LIMIT_SML2 = 500; // Slow query, bot/sysop limit
- private $mMainModule, $mModuleName, $mParamPrefix;
+ private $mMainModule, $mModuleName, $mModulePrefix;
/**
* Constructor
*/
- public function __construct($mainModule, $moduleName, $paramPrefix = '') {
+ public function __construct($mainModule, $moduleName, $modulePrefix = '') {
$this->mMainModule = $mainModule;
$this->mModuleName = $moduleName;
- $this->mParamPrefix = $paramPrefix;
+ $this->mModulePrefix = $modulePrefix;
}
/**
/**
* Get parameter prefix (usually two letters or an empty string).
*/
- public function getParamPrefix() {
- return $this->mParamPrefix;
+ public function getModulePrefix() {
+ return $this->mModulePrefix;
}
/**
* Override this method to change parameter name during runtime
*/
public function encodeParamName($paramName) {
- return $this->mParamPrefix . $paramName;
+ return $this->mModulePrefix . $paramName;
}
/**
}
public static function makeHelpMsgHeader($module, $paramName) {
- $paramPrefix = $module->getParamPrefix();
- if (!empty($paramPrefix))
- $paramPrefix = "($paramPrefix) ";
+ $modulePrefix = $module->getModulePrefix();
+ if (!empty($modulePrefix))
+ $modulePrefix = "($modulePrefix) ";
- return "* $paramName={$module->getModuleName()} $paramPrefix*";
+ return "* $paramName={$module->getModuleName()} $modulePrefix*";
}
private $mIsBot = null;
class ApiPageSet extends ApiQueryBase {
private $mAllPages; // [ns][dbkey] => page_id or 0 when missing
- private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles, $mNormalizedTitles, $mInterwikiTitles;
+ private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles;
+ private $mNormalizedTitles, $mInterwikiTitles;
private $mResolveRedirects, $mPendingRedirectIDs;
private $mGoodRevIDs, $mMissingRevIDs;
+ private $mFakePageId;
private $mRequestedPageFields;
$this->mResolveRedirects = $resolveRedirects;
if($resolveRedirects)
$this->mPendingRedirectIDs = array();
+
+ $this->mFakePageId = -1;
}
public function isResolvingRedirects() {
return array_keys($pageFlds);
}
+ /**
+ * Returns an array [ns][dbkey] => page_id for all requested titles
+ * page_id is a unique negative number in case title was not found
+ */
+ public function getAllTitlesByNamespace() {
+ return $this->mAllPages;
+ }
+
/**
* All Title objects provided.
* @return array of Title objects
/**
* Title objects that were NOT found in the database.
+ * The array's index will be negative for each item
* @return array of Title objects
*/
public function getMissingTitles() {
foreach ($remaining as $ns => $dbkeys) {
foreach ( $dbkeys as $dbkey => $unused ) {
$title = Title :: makeTitle($ns, $dbkey);
- $this->mMissingTitles[] = $title;
- $this->mAllPages[$ns][$dbkey] = 0;
+ $this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
+ $this->mMissingTitles[$this->mFakePageId] = $title;
+ $this->mFakePageId--;
$this->mTitles[] = $title;
}
}
'links' => 'ApiQueryLinks',
'langlinks' => 'ApiQueryLangLinks',
'images' => 'ApiQueryImages',
+ 'imageinfo' => 'ApiQueryImageInfo',
'templates' => 'ApiQueryLinks',
'categories' => 'ApiQueryCategories',
'extlinks' => 'ApiQueryExternalLinks',
);
- // 'categories' => 'ApiQueryCategories',
- // 'imageinfo' => 'ApiQueryImageinfo',
- // 'templates' => 'ApiQueryTemplates',
private $mQueryListModules = array (
'allpages' => 'ApiQueryAllpages',
'recentchanges' => 'ApiQueryRecentChanges',
'usercontribs' => 'ApiQueryContributions',
'watchlist' => 'ApiQueryWatchlist',
- );
- // 'recentchanges' => 'ApiQueryRecentchanges',
// 'users' => 'ApiQueryUsers',
- // 'watchlist' => 'ApiQueryWatchlist',
+ );
private $mQueryMetaModules = array (
- 'siteinfo' => 'ApiQuerySiteinfo'
- );
+ 'siteinfo' => 'ApiQuerySiteinfo',
// 'userinfo' => 'ApiQueryUserinfo',
+ );
private $mSlaveDB = null;
private $mNamedDB = array();
$pages = array ();
// Report any missing titles
- $fakepageid = -1;
- foreach ($pageSet->getMissingTitles() as $title) {
+ foreach ($pageSet->getMissingTitles() as $fakeId => $title) {
$vals = array();
ApiQueryBase :: addTitleInfo($vals, $title, true);
$vals['missing'] = '';
- $pages[$fakepageid--] = $vals;
+ $pages[$fakeId] = $vals;
}
// Report any missing page ids
return $this->mQueryModule;
}
+ /**
+ * Add sub-element under the page element with the given pageId.
+ */
+ protected function addPageSubItems($pageId, $data) {
+ $result = $this->getResult();
+ $result->setIndexedTagName($data, $this->getModulePrefix());
+ $result->addValue(array ('query', 'pages', intval($pageId)),
+ $this->getModuleName(),
+ $data);
+ }
+
protected function setContinueEnumParameter($paramName, $paramValue) {
- $msg = array (
- $this->encodeParamName($paramName
- ) => $paramValue);
+
+ $msg = array( $this->encodeParamName($paramName) => $paramValue );
$this->getResult()->addValue('query-continue', $this->getModuleName(), $msg);
}
$db->freeResult($res);
}
- private function addPageSubItems($pageId, $data) {
- $result = $this->getResult();
- $result->setIndexedTagName($data, 'cl');
- $result->addValue(array ('query', 'pages', intval($pageId)),
- 'categories',
- $data);
- }
-
protected function getAllowedParams() {
return array (
'prop' => array (
$db->freeResult($res);
}
- private function addPageSubItems($pageId, $data) {
- $result = $this->getResult();
- $result->setIndexedTagName($data, 'el');
- $result->addValue(array ('query', 'pages', intval($pageId)),
- 'extlinks',
- $data);
- }
-
protected function getDescription() {
return 'Returns all external urls (not interwikies) from the given page(s)';
}
--- /dev/null
+<?php
+
+/*
+ * Created on July 6, 2007
+ *
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+if (!defined('MEDIAWIKI')) {
+ // Eclipse helper - will be ignored in production
+ require_once ('ApiQueryBase.php');
+}
+
+/**
+ * A query action to get image information and upload history.
+ *
+ * @addtogroup API
+ */
+class ApiQueryImageInfo extends ApiQueryBase {
+
+ public function __construct($query, $moduleName) {
+ parent :: __construct($query, $moduleName, 'ii');
+ }
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+
+ $history = $params['history'];
+
+ $prop = array_flip($params['prop']);
+ $fld_timestamp = isset($prop['timestamp']);
+ $fld_user = isset($prop['user']);
+ $fld_comment = isset($prop['comment']);
+ $fld_url = isset($prop['url']);
+ $fld_size = isset($prop['size']);
+
+ $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
+ if (!empty($pageIds[NS_IMAGE])) {
+ foreach ($pageIds[NS_IMAGE] as $dbKey => $pageId) {
+
+ $title = Title :: makeTitle(NS_IMAGE, $dbKey);
+ $img = wfFindFile($title);
+
+ $vals = array();
+ if ( !$img ) {
+ $data['missing'] = '';
+ } else {
+
+ $data['repository'] = $img->getRepoName();
+
+ $isCur = true;
+ while($line = $img->nextHistoryLine()) { // assignment
+ $vals = array();
+
+ if ($fld_timestamp)
+ $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $line->img_timestamp);
+ if ($fld_user)
+ $vals['user'] = $line->img_user_text;
+ if ($fld_size) {
+ $vals['size'] = $line->img_size;
+ $vals['width'] = $line->img_width;
+ $vals['height'] = $line->img_height;
+ }
+ if ($fld_url)
+ $vals['url'] = $isCur ? $img->getURL() : $img->getArchiveUrl($line->oi_archive_name);
+ if ($fld_comment)
+ $vals['comment'] = $line->img_description;
+
+ $data[] = $vals;
+
+ if (!$history) // Stop after the first line.
+ break;
+
+ $isCur = false;
+ }
+
+ $img->resetHistory();
+ }
+
+ $this->addPageSubItems($pageId, $data);
+ }
+ }
+ }
+
+ protected function getAllowedParams() {
+ return array (
+ 'prop' => array (
+ ApiBase :: PARAM_ISMULTI => true,
+ ApiBase :: PARAM_DFLT => 'timestamp|user',
+ ApiBase :: PARAM_TYPE => array (
+ 'timestamp',
+ 'user',
+ 'comment',
+ 'url',
+ 'size',
+ )
+ ),
+ 'history' => false,
+ );
+ }
+
+ protected function getParamDescription() {
+ return array (
+ 'prop' => 'What image information to get.',
+ 'history' => 'Include upload history',
+ );
+ }
+
+ protected function getDescription() {
+ return array (
+ 'Returns image information and upload history'
+ );
+ }
+
+ protected function getExamples() {
+ return array (
+ 'api.php?action=query&titles=Image:Albert%20Einstein%20Head.jpg&prop=imageinfo',
+ 'api.php?action=query&titles=Image:Test.jpg&prop=imageinfo&iihistory&iiprop=timestamp|user|url',
+ );
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id:$';
+ }
+}
+?>
$db->freeResult($res);
}
- private function addPageSubItems($pageId, $data) {
- $result = $this->getResult();
- $result->setIndexedTagName($data, 'im');
- $result->addValue(array ('query', 'pages', intval($pageId)),
- 'images',
- $data);
- }
-
protected function getDescription() {
return 'Returns all images contained on the given page(s)';
}
$db->freeResult($res);
}
- private function addPageSubItems($pageId, $data) {
- $result = $this->getResult();
- $result->setIndexedTagName($data, 'll');
- $result->addValue(array ('query', 'pages', intval($pageId)),
- 'langlinks',
- $data);
- }
-
protected function getDescription() {
return 'Returns all interlanguage links from the given page(s)';
}
$db->freeResult($res);
}
- private function addPageSubItems($pageId, $data) {
- $result = $this->getResult();
- $result->setIndexedTagName($data, $this->prefix);
- $result->addValue(array ('query', 'pages', intval($pageId)),
- $this->getModuleName(),
- $data);
- }
-
protected function getAllowedParams()
{
return array(