MediaWiki
REL1_23
|
00001 <?php 00033 class ApiQueryRecentChanges extends ApiQueryGeneratorBase { 00034 00035 public function __construct( $query, $moduleName ) { 00036 parent::__construct( $query, $moduleName, 'rc' ); 00037 } 00038 00039 private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false, 00040 $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false, 00041 $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false, 00042 $fld_tags = false, $fld_sha1 = false, $token = array(); 00043 00044 private $tokenFunctions; 00045 00052 protected function getTokenFunctions() { 00053 // Don't call the hooks twice 00054 if ( isset( $this->tokenFunctions ) ) { 00055 return $this->tokenFunctions; 00056 } 00057 00058 // If we're in JSON callback mode, no tokens can be obtained 00059 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) { 00060 return array(); 00061 } 00062 00063 $this->tokenFunctions = array( 00064 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' ) 00065 ); 00066 wfRunHooks( 'APIQueryRecentChangesTokens', array( &$this->tokenFunctions ) ); 00067 00068 return $this->tokenFunctions; 00069 } 00070 00077 public static function getPatrolToken( $pageid, $title, $rc = null ) { 00078 global $wgUser; 00079 00080 $validTokenUser = false; 00081 00082 if ( $rc ) { 00083 if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) || 00084 ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW ) 00085 ) { 00086 $validTokenUser = true; 00087 } 00088 } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) { 00089 $validTokenUser = true; 00090 } 00091 00092 if ( $validTokenUser ) { 00093 // The patrol token is always the same, let's exploit that 00094 static $cachedPatrolToken = null; 00095 00096 if ( is_null( $cachedPatrolToken ) ) { 00097 $cachedPatrolToken = $wgUser->getEditToken( 'patrol' ); 00098 } 00099 00100 return $cachedPatrolToken; 00101 } 00102 00103 return false; 00104 } 00105 00110 public function initProperties( $prop ) { 00111 $this->fld_comment = isset( $prop['comment'] ); 00112 $this->fld_parsedcomment = isset( $prop['parsedcomment'] ); 00113 $this->fld_user = isset( $prop['user'] ); 00114 $this->fld_userid = isset( $prop['userid'] ); 00115 $this->fld_flags = isset( $prop['flags'] ); 00116 $this->fld_timestamp = isset( $prop['timestamp'] ); 00117 $this->fld_title = isset( $prop['title'] ); 00118 $this->fld_ids = isset( $prop['ids'] ); 00119 $this->fld_sizes = isset( $prop['sizes'] ); 00120 $this->fld_redirect = isset( $prop['redirect'] ); 00121 $this->fld_patrolled = isset( $prop['patrolled'] ); 00122 $this->fld_loginfo = isset( $prop['loginfo'] ); 00123 $this->fld_tags = isset( $prop['tags'] ); 00124 $this->fld_sha1 = isset( $prop['sha1'] ); 00125 } 00126 00127 public function execute() { 00128 $this->run(); 00129 } 00130 00131 public function executeGenerator( $resultPageSet ) { 00132 $this->run( $resultPageSet ); 00133 } 00134 00140 public function run( $resultPageSet = null ) { 00141 $user = $this->getUser(); 00142 /* Get the parameters of the request. */ 00143 $params = $this->extractRequestParams(); 00144 00145 /* Build our basic query. Namely, something along the lines of: 00146 * SELECT * FROM recentchanges WHERE rc_timestamp > $start 00147 * AND rc_timestamp < $end AND rc_namespace = $namespace 00148 */ 00149 $this->addTables( 'recentchanges' ); 00150 $index = array( 'recentchanges' => 'rc_timestamp' ); // May change 00151 $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] ); 00152 00153 if ( !is_null( $params['continue'] ) ) { 00154 $cont = explode( '|', $params['continue'] ); 00155 $this->dieContinueUsageIf( count( $cont ) != 2 ); 00156 $db = $this->getDB(); 00157 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) ); 00158 $id = intval( $cont[1] ); 00159 $this->dieContinueUsageIf( $id != $cont[1] ); 00160 $op = $params['dir'] === 'older' ? '<' : '>'; 00161 $this->addWhere( 00162 "rc_timestamp $op $timestamp OR " . 00163 "(rc_timestamp = $timestamp AND " . 00164 "rc_id $op= $id)" 00165 ); 00166 } 00167 00168 $order = $params['dir'] === 'older' ? 'DESC' : 'ASC'; 00169 $this->addOption( 'ORDER BY', array( 00170 "rc_timestamp $order", 00171 "rc_id $order", 00172 ) ); 00173 00174 $this->addWhereFld( 'rc_namespace', $params['namespace'] ); 00175 00176 if ( !is_null( $params['type'] ) ) { 00177 $this->addWhereFld( 'rc_type', $this->parseRCType( $params['type'] ) ); 00178 } 00179 00180 if ( !is_null( $params['show'] ) ) { 00181 $show = array_flip( $params['show'] ); 00182 00183 /* Check for conflicting parameters. */ 00184 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) ) 00185 || ( isset( $show['bot'] ) && isset( $show['!bot'] ) ) 00186 || ( isset( $show['anon'] ) && isset( $show['!anon'] ) ) 00187 || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) ) 00188 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) 00189 || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) ) 00190 || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) ) 00191 ) { 00192 $this->dieUsageMsg( 'show' ); 00193 } 00194 00195 // Check permissions 00196 if ( isset( $show['patrolled'] ) 00197 || isset( $show['!patrolled'] ) 00198 || isset( $show['unpatrolled'] ) 00199 ) { 00200 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) { 00201 $this->dieUsage( 00202 'You need the patrol right to request the patrolled flag', 00203 'permissiondenied' 00204 ); 00205 } 00206 } 00207 00208 /* Add additional conditions to query depending upon parameters. */ 00209 $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) ); 00210 $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) ); 00211 $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) ); 00212 $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) ); 00213 $this->addWhereIf( 'rc_user = 0', isset( $show['anon'] ) ); 00214 $this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) ); 00215 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) ); 00216 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) ); 00217 $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) ); 00218 00219 if ( isset( $show['unpatrolled'] ) ) { 00220 // See ChangesList:isUnpatrolled 00221 if ( $user->useRCPatrol() ) { 00222 $this->addWhere( 'rc_patrolled = 0' ); 00223 } elseif ( $user->useNPPatrol() ) { 00224 $this->addWhere( 'rc_patrolled = 0' ); 00225 $this->addWhereFld( 'rc_type', RC_NEW ); 00226 } 00227 } 00228 00229 // Don't throw log entries out the window here 00230 $this->addWhereIf( 00231 'page_is_redirect = 0 OR page_is_redirect IS NULL', 00232 isset( $show['!redirect'] ) 00233 ); 00234 } 00235 00236 if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) { 00237 $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' ); 00238 } 00239 00240 if ( !is_null( $params['user'] ) ) { 00241 $this->addWhereFld( 'rc_user_text', $params['user'] ); 00242 $index['recentchanges'] = 'rc_user_text'; 00243 } 00244 00245 if ( !is_null( $params['excludeuser'] ) ) { 00246 // We don't use the rc_user_text index here because 00247 // * it would require us to sort by rc_user_text before rc_timestamp 00248 // * the != condition doesn't throw out too many rows anyway 00249 $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) ); 00250 } 00251 00252 /* Add the fields we're concerned with to our query. */ 00253 $this->addFields( array( 00254 'rc_id', 00255 'rc_timestamp', 00256 'rc_namespace', 00257 'rc_title', 00258 'rc_cur_id', 00259 'rc_type', 00260 'rc_deleted' 00261 ) ); 00262 00263 $showRedirects = false; 00264 /* Determine what properties we need to display. */ 00265 if ( !is_null( $params['prop'] ) ) { 00266 $prop = array_flip( $params['prop'] ); 00267 00268 /* Set up internal members based upon params. */ 00269 $this->initProperties( $prop ); 00270 00271 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) { 00272 $this->dieUsage( 00273 'You need the patrol right to request the patrolled flag', 00274 'permissiondenied' 00275 ); 00276 } 00277 00278 /* Add fields to our query if they are specified as a needed parameter. */ 00279 $this->addFieldsIf( array( 'rc_this_oldid', 'rc_last_oldid' ), $this->fld_ids ); 00280 $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment ); 00281 $this->addFieldsIf( 'rc_user', $this->fld_user || $this->fld_userid ); 00282 $this->addFieldsIf( 'rc_user_text', $this->fld_user ); 00283 $this->addFieldsIf( array( 'rc_minor', 'rc_type', 'rc_bot' ), $this->fld_flags ); 00284 $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len' ), $this->fld_sizes ); 00285 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled ); 00286 $this->addFieldsIf( 00287 array( 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ), 00288 $this->fld_loginfo 00289 ); 00290 $showRedirects = $this->fld_redirect || isset( $show['redirect'] ) 00291 || isset( $show['!redirect'] ); 00292 } 00293 00294 if ( $this->fld_tags ) { 00295 $this->addTables( 'tag_summary' ); 00296 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rc_id=ts_rc_id' ) ) ) ); 00297 $this->addFields( 'ts_tags' ); 00298 } 00299 00300 if ( $this->fld_sha1 ) { 00301 $this->addTables( 'revision' ); 00302 $this->addJoinConds( array( 'revision' => array( 'LEFT JOIN', 00303 array( 'rc_this_oldid=rev_id' ) ) ) ); 00304 $this->addFields( array( 'rev_sha1', 'rev_deleted' ) ); 00305 } 00306 00307 if ( $params['toponly'] || $showRedirects ) { 00308 $this->addTables( 'page' ); 00309 $this->addJoinConds( array( 'page' => array( 'LEFT JOIN', 00310 array( 'rc_namespace=page_namespace', 'rc_title=page_title' ) ) ) ); 00311 $this->addFields( 'page_is_redirect' ); 00312 00313 if ( $params['toponly'] ) { 00314 $this->addWhere( 'rc_this_oldid = page_latest' ); 00315 } 00316 } 00317 00318 if ( !is_null( $params['tag'] ) ) { 00319 $this->addTables( 'change_tag' ); 00320 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rc_id=ct_rc_id' ) ) ) ); 00321 $this->addWhereFld( 'ct_tag', $params['tag'] ); 00322 } 00323 00324 // Paranoia: avoid brute force searches (bug 17342) 00325 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) { 00326 if ( !$user->isAllowed( 'deletedhistory' ) ) { 00327 $bitmask = Revision::DELETED_USER; 00328 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) { 00329 $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED; 00330 } else { 00331 $bitmask = 0; 00332 } 00333 if ( $bitmask ) { 00334 $this->addWhere( $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" ); 00335 } 00336 } 00337 if ( $this->getRequest()->getCheck( 'namespace' ) ) { 00338 // LogPage::DELETED_ACTION hides the affected page, too. 00339 if ( !$user->isAllowed( 'deletedhistory' ) ) { 00340 $bitmask = LogPage::DELETED_ACTION; 00341 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) { 00342 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED; 00343 } else { 00344 $bitmask = 0; 00345 } 00346 if ( $bitmask ) { 00347 $this->addWhere( $this->getDB()->makeList( array( 00348 'rc_type != ' . RC_LOG, 00349 $this->getDB()->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask", 00350 ), LIST_OR ) ); 00351 } 00352 } 00353 00354 $this->token = $params['token']; 00355 $this->addOption( 'LIMIT', $params['limit'] + 1 ); 00356 $this->addOption( 'USE INDEX', $index ); 00357 00358 $count = 0; 00359 /* Perform the actual query. */ 00360 $res = $this->select( __METHOD__ ); 00361 00362 $titles = array(); 00363 00364 $result = $this->getResult(); 00365 00366 /* Iterate through the rows, adding data extracted from them to our query result. */ 00367 foreach ( $res as $row ) { 00368 if ( ++$count > $params['limit'] ) { 00369 // We've reached the one extra which shows that there are 00370 // additional pages to be had. Stop here... 00371 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" ); 00372 break; 00373 } 00374 00375 if ( is_null( $resultPageSet ) ) { 00376 /* Extract the data from a single row. */ 00377 $vals = $this->extractRowInfo( $row ); 00378 00379 /* Add that row's data to our final output. */ 00380 if ( !$vals ) { 00381 continue; 00382 } 00383 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); 00384 if ( !$fit ) { 00385 $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" ); 00386 break; 00387 } 00388 } else { 00389 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title ); 00390 } 00391 } 00392 00393 if ( is_null( $resultPageSet ) ) { 00394 /* Format the result */ 00395 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' ); 00396 } else { 00397 $resultPageSet->populateFromTitles( $titles ); 00398 } 00399 } 00400 00408 public function extractRowInfo( $row ) { 00409 /* Determine the title of the page that has been changed. */ 00410 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title ); 00411 $user = $this->getUser(); 00412 00413 /* Our output data. */ 00414 $vals = array(); 00415 00416 $type = intval( $row->rc_type ); 00417 00418 /* Determine what kind of change this was. */ 00419 switch ( $type ) { 00420 case RC_EDIT: 00421 $vals['type'] = 'edit'; 00422 break; 00423 case RC_NEW: 00424 $vals['type'] = 'new'; 00425 break; 00426 case RC_MOVE: 00427 $vals['type'] = 'move'; 00428 break; 00429 case RC_LOG: 00430 $vals['type'] = 'log'; 00431 break; 00432 case RC_EXTERNAL: 00433 $vals['type'] = 'external'; 00434 break; 00435 case RC_MOVE_OVER_REDIRECT: 00436 $vals['type'] = 'move over redirect'; 00437 break; 00438 default: 00439 $vals['type'] = $type; 00440 } 00441 00442 $anyHidden = false; 00443 00444 /* Create a new entry in the result for the title. */ 00445 if ( $this->fld_title || $this->fld_ids ) { 00446 if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) { 00447 $vals['actionhidden'] = ''; 00448 $anyHidden = true; 00449 } 00450 if ( $type !== RC_LOG || 00451 LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) 00452 ) { 00453 if ( $this->fld_title ) { 00454 ApiQueryBase::addTitleInfo( $vals, $title ); 00455 } 00456 if ( $this->fld_ids ) { 00457 $vals['pageid'] = intval( $row->rc_cur_id ); 00458 $vals['revid'] = intval( $row->rc_this_oldid ); 00459 $vals['old_revid'] = intval( $row->rc_last_oldid ); 00460 } 00461 } 00462 } 00463 00464 if ( $this->fld_ids ) { 00465 $vals['rcid'] = intval( $row->rc_id ); 00466 } 00467 00468 /* Add user data and 'anon' flag, if user is anonymous. */ 00469 if ( $this->fld_user || $this->fld_userid ) { 00470 if ( $row->rc_deleted & Revision::DELETED_USER ) { 00471 $vals['userhidden'] = ''; 00472 $anyHidden = true; 00473 } 00474 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) { 00475 if ( $this->fld_user ) { 00476 $vals['user'] = $row->rc_user_text; 00477 } 00478 00479 if ( $this->fld_userid ) { 00480 $vals['userid'] = $row->rc_user; 00481 } 00482 00483 if ( !$row->rc_user ) { 00484 $vals['anon'] = ''; 00485 } 00486 } 00487 } 00488 00489 /* Add flags, such as new, minor, bot. */ 00490 if ( $this->fld_flags ) { 00491 if ( $row->rc_bot ) { 00492 $vals['bot'] = ''; 00493 } 00494 if ( $row->rc_type == RC_NEW ) { 00495 $vals['new'] = ''; 00496 } 00497 if ( $row->rc_minor ) { 00498 $vals['minor'] = ''; 00499 } 00500 } 00501 00502 /* Add sizes of each revision. (Only available on 1.10+) */ 00503 if ( $this->fld_sizes ) { 00504 $vals['oldlen'] = intval( $row->rc_old_len ); 00505 $vals['newlen'] = intval( $row->rc_new_len ); 00506 } 00507 00508 /* Add the timestamp. */ 00509 if ( $this->fld_timestamp ) { 00510 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp ); 00511 } 00512 00513 /* Add edit summary / log summary. */ 00514 if ( $this->fld_comment || $this->fld_parsedcomment ) { 00515 if ( $row->rc_deleted & Revision::DELETED_COMMENT ) { 00516 $vals['commenthidden'] = ''; 00517 $anyHidden = true; 00518 } 00519 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) { 00520 if ( $this->fld_comment && isset( $row->rc_comment ) ) { 00521 $vals['comment'] = $row->rc_comment; 00522 } 00523 00524 if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) { 00525 $vals['parsedcomment'] = Linker::formatComment( $row->rc_comment, $title ); 00526 } 00527 } 00528 } 00529 00530 if ( $this->fld_redirect ) { 00531 if ( $row->page_is_redirect ) { 00532 $vals['redirect'] = ''; 00533 } 00534 } 00535 00536 /* Add the patrolled flag */ 00537 if ( $this->fld_patrolled && $row->rc_patrolled == 1 ) { 00538 $vals['patrolled'] = ''; 00539 } 00540 00541 if ( $this->fld_patrolled && ChangesList::isUnpatrolled( $row, $user ) ) { 00542 $vals['unpatrolled'] = ''; 00543 } 00544 00545 if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) { 00546 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) { 00547 $vals['actionhidden'] = ''; 00548 $anyHidden = true; 00549 } 00550 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) { 00551 $vals['logid'] = intval( $row->rc_logid ); 00552 $vals['logtype'] = $row->rc_log_type; 00553 $vals['logaction'] = $row->rc_log_action; 00554 $logEntry = DatabaseLogEntry::newFromRow( (array)$row ); 00555 ApiQueryLogEvents::addLogParams( 00556 $this->getResult(), 00557 $vals, 00558 $logEntry->getParameters(), 00559 $logEntry->getType(), 00560 $logEntry->getSubtype(), 00561 $logEntry->getTimestamp() 00562 ); 00563 } 00564 } 00565 00566 if ( $this->fld_tags ) { 00567 if ( $row->ts_tags ) { 00568 $tags = explode( ',', $row->ts_tags ); 00569 $this->getResult()->setIndexedTagName( $tags, 'tag' ); 00570 $vals['tags'] = $tags; 00571 } else { 00572 $vals['tags'] = array(); 00573 } 00574 } 00575 00576 if ( $this->fld_sha1 && $row->rev_sha1 !== null ) { 00577 if ( $row->rev_deleted & Revision::DELETED_TEXT ) { 00578 $vals['sha1hidden'] = ''; 00579 $anyHidden = true; 00580 } 00581 if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) { 00582 if ( $row->rev_sha1 !== '' ) { 00583 $vals['sha1'] = wfBaseConvert( $row->rev_sha1, 36, 16, 40 ); 00584 } else { 00585 $vals['sha1'] = ''; 00586 } 00587 } 00588 } 00589 00590 if ( !is_null( $this->token ) ) { 00591 $tokenFunctions = $this->getTokenFunctions(); 00592 foreach ( $this->token as $t ) { 00593 $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id, 00594 $title, RecentChange::newFromRow( $row ) ); 00595 if ( $val === false ) { 00596 $this->setWarning( "Action '$t' is not allowed for the current user" ); 00597 } else { 00598 $vals[$t . 'token'] = $val; 00599 } 00600 } 00601 } 00602 00603 if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) { 00604 $vals['suppressed'] = ''; 00605 } 00606 00607 return $vals; 00608 } 00609 00610 private function parseRCType( $type ) { 00611 if ( is_array( $type ) ) { 00612 $retval = array(); 00613 foreach ( $type as $t ) { 00614 $retval[] = $this->parseRCType( $t ); 00615 } 00616 00617 return $retval; 00618 } 00619 00620 switch ( $type ) { 00621 case 'edit': 00622 return RC_EDIT; 00623 case 'new': 00624 return RC_NEW; 00625 case 'log': 00626 return RC_LOG; 00627 case 'external': 00628 return RC_EXTERNAL; 00629 default: 00630 ApiBase::dieDebug( __METHOD__, "Unknown type '$type'" ); 00631 } 00632 } 00633 00634 public function getCacheMode( $params ) { 00635 if ( isset( $params['show'] ) ) { 00636 foreach ( $params['show'] as $show ) { 00637 if ( $show === 'patrolled' || $show === '!patrolled' ) { 00638 return 'private'; 00639 } 00640 } 00641 } 00642 if ( isset( $params['token'] ) ) { 00643 return 'private'; 00644 } 00645 if ( $this->userCanSeeRevDel() ) { 00646 return 'private'; 00647 } 00648 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { 00649 // formatComment() calls wfMessage() among other things 00650 return 'anon-public-user-private'; 00651 } 00652 00653 return 'public'; 00654 } 00655 00656 public function getAllowedParams() { 00657 return array( 00658 'start' => array( 00659 ApiBase::PARAM_TYPE => 'timestamp' 00660 ), 00661 'end' => array( 00662 ApiBase::PARAM_TYPE => 'timestamp' 00663 ), 00664 'dir' => array( 00665 ApiBase::PARAM_DFLT => 'older', 00666 ApiBase::PARAM_TYPE => array( 00667 'newer', 00668 'older' 00669 ) 00670 ), 00671 'namespace' => array( 00672 ApiBase::PARAM_ISMULTI => true, 00673 ApiBase::PARAM_TYPE => 'namespace' 00674 ), 00675 'user' => array( 00676 ApiBase::PARAM_TYPE => 'user' 00677 ), 00678 'excludeuser' => array( 00679 ApiBase::PARAM_TYPE => 'user' 00680 ), 00681 'tag' => null, 00682 'prop' => array( 00683 ApiBase::PARAM_ISMULTI => true, 00684 ApiBase::PARAM_DFLT => 'title|timestamp|ids', 00685 ApiBase::PARAM_TYPE => array( 00686 'user', 00687 'userid', 00688 'comment', 00689 'parsedcomment', 00690 'flags', 00691 'timestamp', 00692 'title', 00693 'ids', 00694 'sizes', 00695 'redirect', 00696 'patrolled', 00697 'loginfo', 00698 'tags', 00699 'sha1', 00700 ) 00701 ), 00702 'token' => array( 00703 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ), 00704 ApiBase::PARAM_ISMULTI => true 00705 ), 00706 'show' => array( 00707 ApiBase::PARAM_ISMULTI => true, 00708 ApiBase::PARAM_TYPE => array( 00709 'minor', 00710 '!minor', 00711 'bot', 00712 '!bot', 00713 'anon', 00714 '!anon', 00715 'redirect', 00716 '!redirect', 00717 'patrolled', 00718 '!patrolled', 00719 'unpatrolled' 00720 ) 00721 ), 00722 'limit' => array( 00723 ApiBase::PARAM_DFLT => 10, 00724 ApiBase::PARAM_TYPE => 'limit', 00725 ApiBase::PARAM_MIN => 1, 00726 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, 00727 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 00728 ), 00729 'type' => array( 00730 ApiBase::PARAM_ISMULTI => true, 00731 ApiBase::PARAM_TYPE => array( 00732 'edit', 00733 'external', 00734 'new', 00735 'log' 00736 ) 00737 ), 00738 'toponly' => false, 00739 'continue' => null, 00740 ); 00741 } 00742 00743 public function getParamDescription() { 00744 $p = $this->getModulePrefix(); 00745 00746 return array( 00747 'start' => 'The timestamp to start enumerating from', 00748 'end' => 'The timestamp to end enumerating', 00749 'dir' => $this->getDirectionDescription( $p ), 00750 'namespace' => 'Filter log entries to only this namespace(s)', 00751 'user' => 'Only list changes by this user', 00752 'excludeuser' => 'Don\'t list changes by this user', 00753 'prop' => array( 00754 'Include additional pieces of information', 00755 ' user - Adds the user responsible for the edit and tags if they are an IP', 00756 ' userid - Adds the user id responsible for the edit', 00757 ' comment - Adds the comment for the edit', 00758 ' parsedcomment - Adds the parsed comment for the edit', 00759 ' flags - Adds flags for the edit', 00760 ' timestamp - Adds timestamp of the edit', 00761 ' title - Adds the page title of the edit', 00762 ' ids - Adds the page ID, recent changes ID and the new and old revision ID', 00763 ' sizes - Adds the new and old page length in bytes', 00764 ' redirect - Tags edit if page is a redirect', 00765 ' patrolled - Tags patrollable edits as being patrolled or unpatrolled', 00766 ' loginfo - Adds log information (logid, logtype, etc) to log entries', 00767 ' tags - Lists tags for the entry', 00768 ' sha1 - Adds the content checksum for entries associated with a revision', 00769 ), 00770 'token' => 'Which tokens to obtain for each change', 00771 'show' => array( 00772 'Show only items that meet this criteria.', 00773 "For example, to see only minor edits done by logged-in users, set {$p}show=minor|!anon" 00774 ), 00775 'type' => 'Which types of changes to show', 00776 'limit' => 'How many total changes to return', 00777 'tag' => 'Only list changes tagged with this tag', 00778 'toponly' => 'Only list changes which are the latest revision', 00779 'continue' => 'When more results are available, use this to continue', 00780 ); 00781 } 00782 00783 public function getResultProperties() { 00784 global $wgLogTypes; 00785 $props = array( 00786 '' => array( 00787 'type' => array( 00788 ApiBase::PROP_TYPE => array( 00789 'edit', 00790 'new', 00791 'move', 00792 'log', 00793 'move over redirect' 00794 ) 00795 ) 00796 ), 00797 'title' => array( 00798 'ns' => 'namespace', 00799 'title' => 'string', 00800 'new_ns' => array( 00801 ApiBase::PROP_TYPE => 'namespace', 00802 ApiBase::PROP_NULLABLE => true 00803 ), 00804 'new_title' => array( 00805 ApiBase::PROP_TYPE => 'string', 00806 ApiBase::PROP_NULLABLE => true 00807 ) 00808 ), 00809 'ids' => array( 00810 'rcid' => 'integer', 00811 'pageid' => 'integer', 00812 'revid' => 'integer', 00813 'old_revid' => 'integer' 00814 ), 00815 'user' => array( 00816 'user' => 'string', 00817 'anon' => 'boolean' 00818 ), 00819 'userid' => array( 00820 'userid' => 'integer', 00821 'anon' => 'boolean' 00822 ), 00823 'flags' => array( 00824 'bot' => 'boolean', 00825 'new' => 'boolean', 00826 'minor' => 'boolean' 00827 ), 00828 'sizes' => array( 00829 'oldlen' => 'integer', 00830 'newlen' => 'integer' 00831 ), 00832 'timestamp' => array( 00833 'timestamp' => 'timestamp' 00834 ), 00835 'comment' => array( 00836 'comment' => array( 00837 ApiBase::PROP_TYPE => 'string', 00838 ApiBase::PROP_NULLABLE => true 00839 ) 00840 ), 00841 'parsedcomment' => array( 00842 'parsedcomment' => array( 00843 ApiBase::PROP_TYPE => 'string', 00844 ApiBase::PROP_NULLABLE => true 00845 ) 00846 ), 00847 'redirect' => array( 00848 'redirect' => 'boolean' 00849 ), 00850 'patrolled' => array( 00851 'patrolled' => 'boolean', 00852 'unpatrolled' => 'boolean' 00853 ), 00854 'loginfo' => array( 00855 'logid' => array( 00856 ApiBase::PROP_TYPE => 'integer', 00857 ApiBase::PROP_NULLABLE => true 00858 ), 00859 'logtype' => array( 00860 ApiBase::PROP_TYPE => $wgLogTypes, 00861 ApiBase::PROP_NULLABLE => true 00862 ), 00863 'logaction' => array( 00864 ApiBase::PROP_TYPE => 'string', 00865 ApiBase::PROP_NULLABLE => true 00866 ) 00867 ), 00868 'sha1' => array( 00869 'sha1' => array( 00870 ApiBase::PROP_TYPE => 'string', 00871 ApiBase::PROP_NULLABLE => true 00872 ), 00873 'sha1hidden' => array( 00874 ApiBase::PROP_TYPE => 'boolean', 00875 ApiBase::PROP_NULLABLE => true 00876 ), 00877 ), 00878 ); 00879 00880 self::addTokenProperties( $props, $this->getTokenFunctions() ); 00881 00882 return $props; 00883 } 00884 00885 public function getDescription() { 00886 return 'Enumerate recent changes.'; 00887 } 00888 00889 public function getPossibleErrors() { 00890 return array_merge( parent::getPossibleErrors(), array( 00891 array( 'show' ), 00892 array( 00893 'code' => 'permissiondenied', 00894 'info' => 'You need the patrol right to request the patrolled flag' 00895 ), 00896 array( 'code' => 'user-excludeuser', 'info' => 'user and excludeuser cannot be used together' ), 00897 ) ); 00898 } 00899 00900 public function getExamples() { 00901 return array( 00902 'api.php?action=query&list=recentchanges' 00903 ); 00904 } 00905 00906 public function getHelpUrls() { 00907 return 'https://www.mediawiki.org/wiki/API:Recentchanges'; 00908 } 00909 }