Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -51,13 +51,11 @@ |
52 | 52 | 'links' => 'ApiQueryLinks', |
53 | 53 | 'langlinks' => 'ApiQueryLangLinks', |
54 | 54 | 'images' => 'ApiQueryImages', |
| 55 | + 'imageinfo' => 'ApiQueryImageInfo', |
55 | 56 | 'templates' => 'ApiQueryLinks', |
56 | 57 | 'categories' => 'ApiQueryCategories', |
57 | 58 | 'extlinks' => 'ApiQueryExternalLinks', |
58 | 59 | ); |
59 | | - // 'categories' => 'ApiQueryCategories', |
60 | | - // 'imageinfo' => 'ApiQueryImageinfo', |
61 | | - // 'templates' => 'ApiQueryTemplates', |
62 | 60 | |
63 | 61 | private $mQueryListModules = array ( |
64 | 62 | 'allpages' => 'ApiQueryAllpages', |
— | — | @@ -69,15 +67,13 @@ |
70 | 68 | 'recentchanges' => 'ApiQueryRecentChanges', |
71 | 69 | 'usercontribs' => 'ApiQueryContributions', |
72 | 70 | 'watchlist' => 'ApiQueryWatchlist', |
73 | | - ); |
74 | | - // 'recentchanges' => 'ApiQueryRecentchanges', |
75 | 71 | // 'users' => 'ApiQueryUsers', |
76 | | - // 'watchlist' => 'ApiQueryWatchlist', |
| 72 | + ); |
77 | 73 | |
78 | 74 | private $mQueryMetaModules = array ( |
79 | | - 'siteinfo' => 'ApiQuerySiteinfo' |
80 | | - ); |
| 75 | + 'siteinfo' => 'ApiQuerySiteinfo', |
81 | 76 | // 'userinfo' => 'ApiQueryUserinfo', |
| 77 | + ); |
82 | 78 | |
83 | 79 | private $mSlaveDB = null; |
84 | 80 | private $mNamedDB = array(); |
— | — | @@ -293,12 +289,11 @@ |
294 | 290 | $pages = array (); |
295 | 291 | |
296 | 292 | // Report any missing titles |
297 | | - $fakepageid = -1; |
298 | | - foreach ($pageSet->getMissingTitles() as $title) { |
| 293 | + foreach ($pageSet->getMissingTitles() as $fakeId => $title) { |
299 | 294 | $vals = array(); |
300 | 295 | ApiQueryBase :: addTitleInfo($vals, $title, true); |
301 | 296 | $vals['missing'] = ''; |
302 | | - $pages[$fakepageid--] = $vals; |
| 297 | + $pages[$fakeId] = $vals; |
303 | 298 | } |
304 | 299 | |
305 | 300 | // Report any missing page ids |
Index: trunk/phase3/includes/api/ApiQueryLinks.php |
— | — | @@ -126,14 +126,6 @@ |
127 | 127 | $db->freeResult($res); |
128 | 128 | } |
129 | 129 | |
130 | | - private function addPageSubItems($pageId, $data) { |
131 | | - $result = $this->getResult(); |
132 | | - $result->setIndexedTagName($data, $this->prefix); |
133 | | - $result->addValue(array ('query', 'pages', intval($pageId)), |
134 | | - $this->getModuleName(), |
135 | | - $data); |
136 | | - } |
137 | | - |
138 | 130 | protected function getAllowedParams() |
139 | 131 | { |
140 | 132 | return array( |
Index: trunk/phase3/includes/api/ApiQueryLangLinks.php |
— | — | @@ -76,14 +76,6 @@ |
77 | 77 | $db->freeResult($res); |
78 | 78 | } |
79 | 79 | |
80 | | - private function addPageSubItems($pageId, $data) { |
81 | | - $result = $this->getResult(); |
82 | | - $result->setIndexedTagName($data, 'll'); |
83 | | - $result->addValue(array ('query', 'pages', intval($pageId)), |
84 | | - 'langlinks', |
85 | | - $data); |
86 | | - } |
87 | | - |
88 | 80 | protected function getDescription() { |
89 | 81 | return 'Returns all interlanguage links from the given page(s)'; |
90 | 82 | } |
Index: trunk/phase3/includes/api/ApiQueryImageInfo.php |
— | — | @@ -0,0 +1,143 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on July 6, 2007 |
| 6 | + * |
| 7 | + * API for MediaWiki 1.8+ |
| 8 | + * |
| 9 | + * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 10 | + * |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License along |
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 24 | + * http://www.gnu.org/copyleft/gpl.html |
| 25 | + */ |
| 26 | + |
| 27 | +if (!defined('MEDIAWIKI')) { |
| 28 | + // Eclipse helper - will be ignored in production |
| 29 | + require_once ('ApiQueryBase.php'); |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * A query action to get image information and upload history. |
| 34 | + * |
| 35 | + * @addtogroup API |
| 36 | + */ |
| 37 | +class ApiQueryImageInfo extends ApiQueryBase { |
| 38 | + |
| 39 | + public function __construct($query, $moduleName) { |
| 40 | + parent :: __construct($query, $moduleName, 'ii'); |
| 41 | + } |
| 42 | + |
| 43 | + public function execute() { |
| 44 | + $params = $this->extractRequestParams(); |
| 45 | + |
| 46 | + $history = $params['history']; |
| 47 | + |
| 48 | + $prop = array_flip($params['prop']); |
| 49 | + $fld_timestamp = isset($prop['timestamp']); |
| 50 | + $fld_user = isset($prop['user']); |
| 51 | + $fld_comment = isset($prop['comment']); |
| 52 | + $fld_url = isset($prop['url']); |
| 53 | + $fld_size = isset($prop['size']); |
| 54 | + |
| 55 | + $pageIds = $this->getPageSet()->getAllTitlesByNamespace(); |
| 56 | + if (!empty($pageIds[NS_IMAGE])) { |
| 57 | + foreach ($pageIds[NS_IMAGE] as $dbKey => $pageId) { |
| 58 | + |
| 59 | + $title = Title :: makeTitle(NS_IMAGE, $dbKey); |
| 60 | + $img = wfFindFile($title); |
| 61 | + |
| 62 | + $vals = array(); |
| 63 | + if ( !$img ) { |
| 64 | + $data['missing'] = ''; |
| 65 | + } else { |
| 66 | + |
| 67 | + $data['repository'] = $img->getRepoName(); |
| 68 | + |
| 69 | + $isCur = true; |
| 70 | + while($line = $img->nextHistoryLine()) { // assignment |
| 71 | + $vals = array(); |
| 72 | + |
| 73 | + if ($fld_timestamp) |
| 74 | + $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $line->img_timestamp); |
| 75 | + if ($fld_user) |
| 76 | + $vals['user'] = $line->img_user_text; |
| 77 | + if ($fld_size) { |
| 78 | + $vals['size'] = $line->img_size; |
| 79 | + $vals['width'] = $line->img_width; |
| 80 | + $vals['height'] = $line->img_height; |
| 81 | + } |
| 82 | + if ($fld_url) |
| 83 | + $vals['url'] = $isCur ? $img->getURL() : $img->getArchiveUrl($line->oi_archive_name); |
| 84 | + if ($fld_comment) |
| 85 | + $vals['comment'] = $line->img_description; |
| 86 | + |
| 87 | + $data[] = $vals; |
| 88 | + |
| 89 | + if (!$history) // Stop after the first line. |
| 90 | + break; |
| 91 | + |
| 92 | + $isCur = false; |
| 93 | + } |
| 94 | + |
| 95 | + $img->resetHistory(); |
| 96 | + } |
| 97 | + |
| 98 | + $this->addPageSubItems($pageId, $data); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + protected function getAllowedParams() { |
| 104 | + return array ( |
| 105 | + 'prop' => array ( |
| 106 | + ApiBase :: PARAM_ISMULTI => true, |
| 107 | + ApiBase :: PARAM_DFLT => 'timestamp|user', |
| 108 | + ApiBase :: PARAM_TYPE => array ( |
| 109 | + 'timestamp', |
| 110 | + 'user', |
| 111 | + 'comment', |
| 112 | + 'url', |
| 113 | + 'size', |
| 114 | + ) |
| 115 | + ), |
| 116 | + 'history' => false, |
| 117 | + ); |
| 118 | + } |
| 119 | + |
| 120 | + protected function getParamDescription() { |
| 121 | + return array ( |
| 122 | + 'prop' => 'What image information to get.', |
| 123 | + 'history' => 'Include upload history', |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + protected function getDescription() { |
| 128 | + return array ( |
| 129 | + 'Returns image information and upload history' |
| 130 | + ); |
| 131 | + } |
| 132 | + |
| 133 | + protected function getExamples() { |
| 134 | + return array ( |
| 135 | + 'api.php?action=query&titles=Image:Albert%20Einstein%20Head.jpg&prop=imageinfo', |
| 136 | + 'api.php?action=query&titles=Image:Test.jpg&prop=imageinfo&iihistory&iiprop=timestamp|user|url', |
| 137 | + ); |
| 138 | + } |
| 139 | + |
| 140 | + public function getVersion() { |
| 141 | + return __CLASS__ . ': $Id:$'; |
| 142 | + } |
| 143 | +} |
| 144 | +?> |
Property changes on: trunk/phase3/includes/api/ApiQueryImageInfo.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 145 | + native |
Name: svn:keywords |
2 | 146 | + Id |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -389,11 +389,11 @@ |
390 | 390 | } |
391 | 391 | |
392 | 392 | public static function makeHelpMsgHeader($module, $paramName) { |
393 | | - $paramPrefix = $module->getParamPrefix(); |
394 | | - if (!empty($paramPrefix)) |
395 | | - $paramPrefix = "($paramPrefix) "; |
| 393 | + $modulePrefix = $module->getModulePrefix(); |
| 394 | + if (!empty($modulePrefix)) |
| 395 | + $modulePrefix = "($modulePrefix) "; |
396 | 396 | |
397 | | - return "* $paramName={$module->getModuleName()} $paramPrefix*"; |
| 397 | + return "* $paramName={$module->getModuleName()} $modulePrefix*"; |
398 | 398 | } |
399 | 399 | |
400 | 400 | private $mIsBot = null; |
Index: trunk/phase3/includes/api/ApiPageSet.php |
— | — | @@ -43,9 +43,11 @@ |
44 | 44 | class ApiPageSet extends ApiQueryBase { |
45 | 45 | |
46 | 46 | private $mAllPages; // [ns][dbkey] => page_id or 0 when missing |
47 | | - private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles, $mNormalizedTitles, $mInterwikiTitles; |
| 47 | + private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles; |
| 48 | + private $mNormalizedTitles, $mInterwikiTitles; |
48 | 49 | private $mResolveRedirects, $mPendingRedirectIDs; |
49 | 50 | private $mGoodRevIDs, $mMissingRevIDs; |
| 51 | + private $mFakePageId; |
50 | 52 | |
51 | 53 | private $mRequestedPageFields; |
52 | 54 | |
— | — | @@ -67,6 +69,8 @@ |
68 | 70 | $this->mResolveRedirects = $resolveRedirects; |
69 | 71 | if($resolveRedirects) |
70 | 72 | $this->mPendingRedirectIDs = array(); |
| 73 | + |
| 74 | + $this->mFakePageId = -1; |
71 | 75 | } |
72 | 76 | |
73 | 77 | public function isResolvingRedirects() { |
— | — | @@ -103,6 +107,14 @@ |
104 | 108 | } |
105 | 109 | |
106 | 110 | /** |
| 111 | + * Returns an array [ns][dbkey] => page_id for all requested titles |
| 112 | + * page_id is a unique negative number in case title was not found |
| 113 | + */ |
| 114 | + public function getAllTitlesByNamespace() { |
| 115 | + return $this->mAllPages; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
107 | 119 | * All Title objects provided. |
108 | 120 | * @return array of Title objects |
109 | 121 | */ |
— | — | @@ -134,6 +146,7 @@ |
135 | 147 | |
136 | 148 | /** |
137 | 149 | * Title objects that were NOT found in the database. |
| 150 | + * The array's index will be negative for each item |
138 | 151 | * @return array of Title objects |
139 | 152 | */ |
140 | 153 | public function getMissingTitles() { |
— | — | @@ -406,8 +419,9 @@ |
407 | 420 | foreach ($remaining as $ns => $dbkeys) { |
408 | 421 | foreach ( $dbkeys as $dbkey => $unused ) { |
409 | 422 | $title = Title :: makeTitle($ns, $dbkey); |
410 | | - $this->mMissingTitles[] = $title; |
411 | | - $this->mAllPages[$ns][$dbkey] = 0; |
| 423 | + $this->mAllPages[$ns][$dbkey] = $this->mFakePageId; |
| 424 | + $this->mMissingTitles[$this->mFakePageId] = $title; |
| 425 | + $this->mFakePageId--; |
412 | 426 | $this->mTitles[] = $title; |
413 | 427 | } |
414 | 428 | } |
Index: trunk/phase3/includes/api/ApiQueryBase.php |
— | — | @@ -151,10 +151,20 @@ |
152 | 152 | return $this->mQueryModule; |
153 | 153 | } |
154 | 154 | |
| 155 | + /** |
| 156 | + * Add sub-element under the page element with the given pageId. |
| 157 | + */ |
| 158 | + protected function addPageSubItems($pageId, $data) { |
| 159 | + $result = $this->getResult(); |
| 160 | + $result->setIndexedTagName($data, $this->getModulePrefix()); |
| 161 | + $result->addValue(array ('query', 'pages', intval($pageId)), |
| 162 | + $this->getModuleName(), |
| 163 | + $data); |
| 164 | + } |
| 165 | + |
155 | 166 | protected function setContinueEnumParameter($paramName, $paramValue) { |
156 | | - $msg = array ( |
157 | | - $this->encodeParamName($paramName |
158 | | - ) => $paramValue); |
| 167 | + |
| 168 | + $msg = array( $this->encodeParamName($paramName) => $paramValue ); |
159 | 169 | $this->getResult()->addValue('query-continue', $this->getModuleName(), $msg); |
160 | 170 | } |
161 | 171 | |
Index: trunk/phase3/includes/api/ApiQueryExternalLinks.php |
— | — | @@ -75,14 +75,6 @@ |
76 | 76 | $db->freeResult($res); |
77 | 77 | } |
78 | 78 | |
79 | | - private function addPageSubItems($pageId, $data) { |
80 | | - $result = $this->getResult(); |
81 | | - $result->setIndexedTagName($data, 'el'); |
82 | | - $result->addValue(array ('query', 'pages', intval($pageId)), |
83 | | - 'extlinks', |
84 | | - $data); |
85 | | - } |
86 | | - |
87 | 79 | protected function getDescription() { |
88 | 80 | return 'Returns all external urls (not interwikies) from the given page(s)'; |
89 | 81 | } |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -52,15 +52,15 @@ |
53 | 53 | const LIMIT_SML1 = 50; // Slow query, std user limit |
54 | 54 | const LIMIT_SML2 = 500; // Slow query, bot/sysop limit |
55 | 55 | |
56 | | - private $mMainModule, $mModuleName, $mParamPrefix; |
| 56 | + private $mMainModule, $mModuleName, $mModulePrefix; |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Constructor |
60 | 60 | */ |
61 | | - public function __construct($mainModule, $moduleName, $paramPrefix = '') { |
| 61 | + public function __construct($mainModule, $moduleName, $modulePrefix = '') { |
62 | 62 | $this->mMainModule = $mainModule; |
63 | 63 | $this->mModuleName = $moduleName; |
64 | | - $this->mParamPrefix = $paramPrefix; |
| 64 | + $this->mModulePrefix = $modulePrefix; |
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
— | — | @@ -78,8 +78,8 @@ |
79 | 79 | /** |
80 | 80 | * Get parameter prefix (usually two letters or an empty string). |
81 | 81 | */ |
82 | | - public function getParamPrefix() { |
83 | | - return $this->mParamPrefix; |
| 82 | + public function getModulePrefix() { |
| 83 | + return $this->mModulePrefix; |
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
— | — | @@ -296,7 +296,7 @@ |
297 | 297 | * Override this method to change parameter name during runtime |
298 | 298 | */ |
299 | 299 | public function encodeParamName($paramName) { |
300 | | - return $this->mParamPrefix . $paramName; |
| 300 | + return $this->mModulePrefix . $paramName; |
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
Index: trunk/phase3/includes/api/ApiQueryCategories.php |
— | — | @@ -124,14 +124,6 @@ |
125 | 125 | $db->freeResult($res); |
126 | 126 | } |
127 | 127 | |
128 | | - private function addPageSubItems($pageId, $data) { |
129 | | - $result = $this->getResult(); |
130 | | - $result->setIndexedTagName($data, 'cl'); |
131 | | - $result->addValue(array ('query', 'pages', intval($pageId)), |
132 | | - 'categories', |
133 | | - $data); |
134 | | - } |
135 | | - |
136 | 128 | protected function getAllowedParams() { |
137 | 129 | return array ( |
138 | 130 | 'prop' => array ( |
Index: trunk/phase3/includes/api/ApiQueryImages.php |
— | — | @@ -102,14 +102,6 @@ |
103 | 103 | $db->freeResult($res); |
104 | 104 | } |
105 | 105 | |
106 | | - private function addPageSubItems($pageId, $data) { |
107 | | - $result = $this->getResult(); |
108 | | - $result->setIndexedTagName($data, 'im'); |
109 | | - $result->addValue(array ('query', 'pages', intval($pageId)), |
110 | | - 'images', |
111 | | - $data); |
112 | | - } |
113 | | - |
114 | 106 | protected function getDescription() { |
115 | 107 | return 'Returns all images contained on the given page(s)'; |
116 | 108 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -314,6 +314,7 @@ |
315 | 315 | 'ApiQueryContributions' => 'includes/api/ApiQueryUserContributions.php', |
316 | 316 | 'ApiQueryExternalLinks' => 'includes/api/ApiQueryExternalLinks.php', |
317 | 317 | 'ApiQueryImages' => 'includes/api/ApiQueryImages.php', |
| 318 | + 'ApiQueryImageInfo' => 'includes/api/ApiQueryImageInfo.php', |
318 | 319 | 'ApiQueryInfo' => 'includes/api/ApiQueryInfo.php', |
319 | 320 | 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php', |
320 | 321 | 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -263,7 +263,7 @@ |
264 | 264 | |
265 | 265 | == API changes since 1.10 == |
266 | 266 | |
267 | | -(For ongoing development discussion, see http://www.mediawiki.org/wiki/API) |
| 267 | +Full API documentation is available at http://www.mediawiki.org/wiki/API |
268 | 268 | |
269 | 269 | * New properties: links, templates, images, langlinks, categories, external |
270 | 270 | links |
— | — | @@ -302,6 +302,7 @@ |
303 | 303 | * (bug 10297) include previous revision ID in prop=revisions |
304 | 304 | * backlinks, embeddedin and imageusage lists should use (bl|ei|iu)title parameter |
305 | 305 | instead of titles. Titles for these lists is obsolete and might stop working soon. |
| 306 | +* Added prop=imageinfo - gets image properties and upload history |
306 | 307 | |
307 | 308 | == Maintenance script changes since 1.10 == |
308 | 309 | |