Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -270,6 +270,7 @@ |
271 | 271 | |
272 | 272 | $wgAutoloadClasses['FlaggedRevs'] = $dir.'FlaggedRevs.class.php'; |
273 | 273 | $wgAutoloadClasses['FlaggedRevsHooks'] = $dir.'FlaggedRevs.hooks.php'; |
| 274 | +$wgAutoloadClasses['FlaggedRevsApiHooks'] = $dir.'FlaggedRevs.hooks.php'; |
274 | 275 | $wgAutoloadClasses['FRCacheUpdate'] = $dir.'FRCacheUpdate.php'; |
275 | 276 | $wgAutoloadClasses['FRCacheUpdateJob'] = $dir.'FRCacheUpdate.php'; |
276 | 277 | |
— | — | @@ -336,6 +337,11 @@ |
337 | 338 | $wgAutoloadClasses['ValidationStatistics'] = $dir . 'specialpages/ValidationStatistics_body.php'; |
338 | 339 | $wgExtensionMessagesFiles['ValidationStatistics'] = $langDir . 'ValidationStatistics.i18n.php'; |
339 | 340 | $wgSpecialPageGroups['ValidationStatistics'] = 'quality'; |
| 341 | +# API Modules |
| 342 | +$wgAutoloadClasses['ApiQueryOldreviewedpages'] = $dir . 'api/ApiQueryOldreviewedpages.php'; |
| 343 | +$wgAPIListModules['oldreviewedpages'] = 'ApiQueryOldreviewedpages'; |
| 344 | +$wgAutoloadClasses['ApiQueryFlagged'] = $dir . 'api/ApiQueryFlagged.php'; |
| 345 | +$wgAPIPropModules['flagged'] = 'ApiQueryFlagged'; |
340 | 346 | |
341 | 347 | ######### Hook attachments ######### |
342 | 348 | # Remove stand-alone patrolling |
— | — | @@ -420,6 +426,10 @@ |
421 | 427 | # Duplicate flagged* tables in parserTests.php |
422 | 428 | $wgHooks['ParserTestTables'][] = 'FlaggedRevsHooks::onParserTestTables'; |
423 | 429 | |
| 430 | +# Add flagging data to ApiQueryRevisions |
| 431 | +$wgHooks['APIGetAllowedParams'][] = 'FlaggedRevsApiHooks::addApiRevisionParams'; |
| 432 | +$wgHooks['APIQueryAfterExecute'][] = 'FlaggedRevsApiHooks::addApiRevisionData'; |
| 433 | + |
424 | 434 | ######### |
425 | 435 | |
426 | 436 | function efLoadFlaggedRevs() { |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -212,6 +212,24 @@ |
213 | 213 | self::load(); |
214 | 214 | return empty(self::$dimensions); |
215 | 215 | } |
| 216 | + |
| 217 | + /** |
| 218 | + * Get corresponding text for the api output of flagging levels |
| 219 | + * |
| 220 | + * @param int $level |
| 221 | + * @return string |
| 222 | + */ |
| 223 | + public static function getQualityLevelText( $level ) { |
| 224 | + static $levelText = array( |
| 225 | + 0 => 'stable', |
| 226 | + 1 => 'quality', |
| 227 | + 2 => 'pristine' |
| 228 | + ); |
| 229 | + if ( isset( $levelText[$level] ) ) |
| 230 | + return $levelText[$level]; |
| 231 | + else |
| 232 | + return ''; |
| 233 | + } |
216 | 234 | |
217 | 235 | ################# Parsing functions ################# |
218 | 236 | |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -1264,3 +1264,85 @@ |
1265 | 1265 | return true; |
1266 | 1266 | } |
1267 | 1267 | } |
| 1268 | + |
| 1269 | +abstract class FlaggedRevsApiHooks extends ApiQueryBase { |
| 1270 | + |
| 1271 | + public static function addApiRevisionParams ( &$module, &$params ) { |
| 1272 | + if (!$module instanceof ApiQueryRevisions) |
| 1273 | + return true; |
| 1274 | + $params['prop'][ApiBase::PARAM_TYPE][] = 'flagged'; |
| 1275 | + return true; |
| 1276 | + } |
| 1277 | + |
| 1278 | + public static function addApiRevisionData( &$module ) { |
| 1279 | + if (!$module instanceof ApiQueryRevisions) |
| 1280 | + return true; |
| 1281 | + $params = $module->extractRequestParams( false ); |
| 1282 | + if ( empty( $params['prop'] ) || !in_array( 'flagged', $params['prop'] ) ) |
| 1283 | + return true; |
| 1284 | + if ( !in_array( 'ids', $params['prop'] ) ) |
| 1285 | + $module->dieUsage( 'if rvprop=flagged is set, you must also set rvprop=ids', 'missingparam' ); |
| 1286 | + |
| 1287 | + // Get all requested pageids/revids in a mapping: |
| 1288 | + // pageid => revid => array_index of the revision |
| 1289 | + // we will need this later to add data to the result array |
| 1290 | + $result = $module->getResult(); |
| 1291 | + $data = $result->getData(); |
| 1292 | + if ( !isset( $data['query'] ) || !isset( $data['query']['pages'] ) ) |
| 1293 | + return true; |
| 1294 | + foreach ( $data['query']['pages'] as $pageid => $page ) |
| 1295 | + if ( array_key_exists( 'revisions', (array)$page ) ) |
| 1296 | + foreach ( $page['revisions'] as $index => $rev ) |
| 1297 | + if ( array_key_exists( 'revid', (array)$rev ) ) |
| 1298 | + $pageids[$pageid][$rev['revid']] = $index; |
| 1299 | + if ( empty( $pageids ) ) |
| 1300 | + return true; |
| 1301 | + |
| 1302 | + //Construct SQL Query |
| 1303 | + $db = $module->getDB(); |
| 1304 | + $module->resetQueryParams(); |
| 1305 | + $module->addTables( array( 'flaggedrevs', 'user' ) ); |
| 1306 | + $module->addFields( array( |
| 1307 | + 'fr_page_id', |
| 1308 | + 'fr_rev_id', |
| 1309 | + 'fr_timestamp', |
| 1310 | + 'fr_comment', |
| 1311 | + 'fr_quality', |
| 1312 | + 'fr_tags', |
| 1313 | + 'user_name' |
| 1314 | + ) ); |
| 1315 | + $module->addWhere( 'fr_user=user_id' ); |
| 1316 | + |
| 1317 | + //Construct WHERE-clause to avoid multiplying the number of scanned rows |
| 1318 | + //as flaggedrevs table has composite primary key (fr_page_id,fr_rev_id) |
| 1319 | + foreach ( $pageids as $pageid => $revids ) |
| 1320 | + $where[] = $db->makeList( array( |
| 1321 | + 'fr_page_id' => $pageid, |
| 1322 | + 'fr_rev_id' => array_keys( $revids ) ), LIST_AND ); |
| 1323 | + $module->addWhere( $db->makeList( $where, LIST_OR ) ); |
| 1324 | + $module->addOption( 'USE INDEX', array( 'flaggedrevs' => 'PRIMARY' ) ); |
| 1325 | + |
| 1326 | + $res = $module->select( __METHOD__ ); |
| 1327 | + |
| 1328 | + //Add flagging data to result array |
| 1329 | + while ( $row = $db->fetchObject( $res ) ) { |
| 1330 | + $index = $pageids[$row->fr_page_id][$row->fr_rev_id]; |
| 1331 | + $data = array( |
| 1332 | + 'user' => $row->user_name, |
| 1333 | + 'timestamp' => wfTimestamp( TS_ISO_8601, $row->fr_timestamp ), |
| 1334 | + 'level' => intval( $row->fr_quality ), |
| 1335 | + 'level_text' => FlaggedRevs::getQualityLevelText( $row->fr_quality ), |
| 1336 | + 'tags' => FlaggedRevision::expandRevisionTags( $row->fr_tags ) |
| 1337 | + ); |
| 1338 | + if ( $row->fr_comment ) |
| 1339 | + $data['comment'] = $row->fr_comment; |
| 1340 | + $result->addValue( |
| 1341 | + array( 'query', 'pages', $row->fr_page_id, 'revisions', $index ), |
| 1342 | + 'flagged', |
| 1343 | + $data |
| 1344 | + ); |
| 1345 | + } |
| 1346 | + $db->freeResult( $res ); |
| 1347 | + return true; |
| 1348 | + } |
| 1349 | +} |
Index: trunk/extensions/FlaggedRevs/api/ApiQueryFlagged.php |
— | — | @@ -0,0 +1,87 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Sep 17, 2008 |
| 6 | + * |
| 7 | + * API module for MediaWiki's FlaggedRevs extension |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License along |
| 20 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | + * http://www.gnu.org/copyleft/gpl.html |
| 23 | + */ |
| 24 | + |
| 25 | +/** |
| 26 | + * Query module to get flagging information about pages via 'prop=flagged' |
| 27 | + * |
| 28 | + * @ingroup FlaggedRevs |
| 29 | + */ |
| 30 | +class ApiQueryFlagged extends ApiQueryBase { |
| 31 | + |
| 32 | + public function execute() { |
| 33 | + $params = $this->extractRequestParams(); |
| 34 | + $pageSet = $this->getPageSet(); |
| 35 | + $pageids = array_keys( $pageSet->getGoodTitles() ); |
| 36 | + if ( !$pageids ) |
| 37 | + return true; |
| 38 | + |
| 39 | + //Construct SQL Query |
| 40 | + $this->addTables( 'flaggedpages' ); |
| 41 | + $this->addFields( array( |
| 42 | + 'fp_page_id', 'fp_stable', 'fp_quality', 'fp_pending_since' |
| 43 | + ) ); |
| 44 | + $this->addWhereFld( 'fp_page_id', $pageids ); |
| 45 | + $res = $this->select( __METHOD__ ); |
| 46 | + |
| 47 | + $result = $this->getResult(); |
| 48 | + $db = $this->getDB(); |
| 49 | + while ( $row = $db->fetchObject( $res ) ) { |
| 50 | + $pageid = $row->fp_page_id; |
| 51 | + $data = array( |
| 52 | + 'stable_revid' => intval( $row->fp_stable ), |
| 53 | + 'level' => intval( $row->fp_quality ), |
| 54 | + 'level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality ) |
| 55 | + ); |
| 56 | + if ( $row->fp_pending_since ) |
| 57 | + $data['pending_since'] = wfTimestamp( TS_ISO_8601, $row->fp_pending_since ); |
| 58 | + $result->addValue( array( 'query', 'pages', $pageid ), 'flagged', $data ); |
| 59 | + } |
| 60 | + $db->freeResult( $res ); |
| 61 | + } |
| 62 | + |
| 63 | + public function getAllowedParams() { |
| 64 | + return array(); |
| 65 | + } |
| 66 | + |
| 67 | + public function getDescription() { |
| 68 | + return array( |
| 69 | + 'Get information about the flagging status of the given pages.', |
| 70 | + 'If a page is flagged, the following parameters are returned:', |
| 71 | + '* stable_revid : The revision id of the latest stable revision', |
| 72 | + '* level, level_text : The highest flagging level of the page', |
| 73 | + '* pending_since : If there are any current unreviewed revisions' |
| 74 | + .' for that page, holds the timestamp of the first of them' |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + protected function getExamples() { |
| 79 | + return array ( |
| 80 | + 'api.php?action=query&prop=info|flagged&titles=Main%20Page', |
| 81 | + 'api.php?action=query&generator=allpages&gapfrom=K&prop=flagged' |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function getVersion() { |
| 86 | + return __CLASS__.': $Id$'; |
| 87 | + } |
| 88 | +} |
Property changes on: trunk/extensions/FlaggedRevs/api/ApiQueryFlagged.php |
___________________________________________________________________ |
Name: svn:keywords |
1 | 89 | + Id |
Name: svn:eol-style |
2 | 90 | + native |
Index: trunk/extensions/FlaggedRevs/api/ApiQueryOldreviewedpages.php |
— | — | @@ -0,0 +1,201 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Sep 17, 2008 |
| 6 | + * |
| 7 | + * API module for MediaWiki's FlaggedRevs extension |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License along |
| 20 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | + * http://www.gnu.org/copyleft/gpl.html |
| 23 | + */ |
| 24 | + |
| 25 | +/** |
| 26 | + * Query module to list pages with outdated review flag. |
| 27 | + * |
| 28 | + * @ingroup FlaggedRevs |
| 29 | + */ |
| 30 | +class ApiQueryOldreviewedpages extends ApiQueryGeneratorBase { |
| 31 | + |
| 32 | + public function __construct( $query, $moduleName ) { |
| 33 | + parent::__construct( $query, $moduleName, 'or' ); |
| 34 | + } |
| 35 | + |
| 36 | + public function execute() { |
| 37 | + $this->run(); |
| 38 | + } |
| 39 | + |
| 40 | + public function executeGenerator( $resultPageSet ) { |
| 41 | + $this->run( $resultPageSet ); |
| 42 | + } |
| 43 | + |
| 44 | + private function run( $resultPageSet = null ) { |
| 45 | + // Permission check |
| 46 | + global $wgUser; |
| 47 | + if ( !$wgUser->isAllowed( 'unreviewedpages' ) ) |
| 48 | + $this->dieUsage( |
| 49 | + "You need the unreviewedpages right to request the list of" |
| 50 | + ." old reviewed pages.", |
| 51 | + 'permissiondenied' |
| 52 | + ); |
| 53 | + |
| 54 | + $params = $this->extractRequestParams(); |
| 55 | + |
| 56 | + // Construct SQL Query |
| 57 | + $this->addTables( array( 'page', 'flaggedpages' ) ); |
| 58 | + $this->addWhereFld( 'page_namespace', $params['namespace'] ); |
| 59 | + $this->addWhereRange( |
| 60 | + 'fp_pending_since', |
| 61 | + $params['dir'], |
| 62 | + $params['start'], |
| 63 | + $params['end'] |
| 64 | + ); |
| 65 | + $this->addWhere( 'page_id=fp_page_id' ); |
| 66 | + if ( !isset( $params['start'] ) && !isset( $params['end'] ) ) |
| 67 | + $this->addWhere( 'fp_pending_since IS NOT NULL' ); |
| 68 | + $this->addOption( |
| 69 | + 'USE INDEX', |
| 70 | + array( 'flaggedpages' => 'fp_pending_since' ) |
| 71 | + ); |
| 72 | + |
| 73 | + if ( is_null( $resultPageSet ) ) { |
| 74 | + $this->addFields( array ( |
| 75 | + 'page_id', |
| 76 | + 'page_namespace', |
| 77 | + 'page_title', |
| 78 | + 'page_latest', |
| 79 | + 'fp_stable', |
| 80 | + 'fp_pending_since', |
| 81 | + 'fp_quality' |
| 82 | + ) ); |
| 83 | + } else { |
| 84 | + $this->addFields( $resultPageSet->getPageTableFields() ); |
| 85 | + $this->addFields ( 'fp_pending_since' ); |
| 86 | + } |
| 87 | + |
| 88 | + $limit = $params['limit']; |
| 89 | + $this->addOption( 'LIMIT', $limit+1 ); |
| 90 | + $res = $this->select( __METHOD__ ); |
| 91 | + |
| 92 | + $data = array (); |
| 93 | + $count = 0; |
| 94 | + $db = $this->getDB(); |
| 95 | + while ( $row = $db->fetchObject( $res ) ) { |
| 96 | + if ( ++$count > $limit ) { |
| 97 | + // We've reached the one extra which shows that there are |
| 98 | + // additional pages to be had. Stop here... |
| 99 | + $this->setContinueEnumParameter( |
| 100 | + 'start', |
| 101 | + wfTimestamp( TS_ISO_8601, $row->fp_pending_since ) |
| 102 | + ); |
| 103 | + break; |
| 104 | + } |
| 105 | + |
| 106 | + if ( is_null( $resultPageSet ) ) { |
| 107 | + $title = Title::makeTitle( |
| 108 | + $row->page_namespace, |
| 109 | + $row->page_title |
| 110 | + ); |
| 111 | + $data[] = array( |
| 112 | + 'pageid' => intval( $row->page_id ), |
| 113 | + 'ns' => intval( $title->getNamespace() ), |
| 114 | + 'title' => $title->getPrefixedText(), |
| 115 | + 'revid' => intval( $row->page_latest ), |
| 116 | + 'stable_revid' => intval( $row->fp_stable ), |
| 117 | + 'pending_since' => |
| 118 | + wfTimestamp( TS_ISO_8601, $row->fp_pending_since ), |
| 119 | + 'flagged_level' => intval( $row->fp_quality ), |
| 120 | + 'flagged_level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality ) |
| 121 | + ); |
| 122 | + } else { |
| 123 | + $resultPageSet->processDbRow( $row ); |
| 124 | + } |
| 125 | + } |
| 126 | + $db->freeResult( $res ); |
| 127 | + |
| 128 | + if ( is_null( $resultPageSet ) ) { |
| 129 | + $result = $this->getResult(); |
| 130 | + $result->setIndexedTagName( $data, 'p' ); |
| 131 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + public function getAllowedParams() { |
| 136 | + global $wgFlaggedRevsNamespaces; |
| 137 | + return array ( |
| 138 | + 'start' => array ( |
| 139 | + ApiBase::PARAM_TYPE => 'timestamp' |
| 140 | + ), |
| 141 | + 'end' => array ( |
| 142 | + ApiBase::PARAM_TYPE => 'timestamp' |
| 143 | + ), |
| 144 | + 'dir' => array ( |
| 145 | + ApiBase::PARAM_DFLT => 'newer', |
| 146 | + ApiBase::PARAM_TYPE => array ( |
| 147 | + 'newer', |
| 148 | + 'older' |
| 149 | + ) |
| 150 | + ), |
| 151 | + 'namespace' => array ( |
| 152 | + ApiBase::PARAM_DFLT => |
| 153 | + !$wgFlaggedRevsNamespaces ? |
| 154 | + NS_MAIN : |
| 155 | + $wgFlaggedRevsNamespaces[0], |
| 156 | + ApiBase :: PARAM_TYPE => 'namespace', |
| 157 | + ApiBase :: PARAM_ISMULTI => true, |
| 158 | + ), |
| 159 | + 'limit' => array ( |
| 160 | + ApiBase::PARAM_DFLT => 10, |
| 161 | + ApiBase::PARAM_TYPE => 'limit', |
| 162 | + ApiBase::PARAM_MIN => 1, |
| 163 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 164 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 165 | + ) |
| 166 | + ); |
| 167 | + } |
| 168 | + |
| 169 | + public function getParamDescription() { |
| 170 | + return array ( |
| 171 | + 'start' => 'Start listing at this timestamp.', |
| 172 | + 'end' => 'Stop listing at this timestamp.', |
| 173 | + 'namespace' => 'The namespaces to enumerate.', |
| 174 | + 'limit' => 'How many total pages to return.', |
| 175 | + 'dir' => array( |
| 176 | + 'In which direction to list.', |
| 177 | + '*newer: list the longest waiting pages first', |
| 178 | + '*older: list the newest items first' |
| 179 | + ) |
| 180 | + ); |
| 181 | + } |
| 182 | + |
| 183 | + public function getDescription() { |
| 184 | + return array( |
| 185 | + 'Returns a list of pages, that have an outdated review flag,', |
| 186 | + 'sorted by timestamp of the first unreviewed edit of that page.' |
| 187 | + ); |
| 188 | + } |
| 189 | + |
| 190 | + protected function getExamples() { |
| 191 | + return array ( |
| 192 | + 'Show a list of pages with pending unreviewed changes', |
| 193 | + ' api.php?action=query&list=oldreviewedpages&ornamespace=0', |
| 194 | + 'Show info about some old reviewed pages', |
| 195 | + ' api.php?action=query&generator=oldreviewedpages&gorlimit=4&prop=info', |
| 196 | + ); |
| 197 | + } |
| 198 | + |
| 199 | + public function getVersion() { |
| 200 | + return __CLASS__.': $Id$'; |
| 201 | + } |
| 202 | +} |
Property changes on: trunk/extensions/FlaggedRevs/api/ApiQueryOldreviewedpages.php |
___________________________________________________________________ |
Name: svn:keywords |
1 | 203 | + Id |
Name: svn:eol-style |
2 | 204 | + native |