Index: trunk/extensions/ArchiveLinks/ApiQueryArchiveFeed.php |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +class ApiQueryArchiveFeed extends ApiQueryBase {
|
| 5 | + function __construct ( $query, $moduleName ) {
|
| 6 | + parent::__construct( $query, $moduleName, 'al' );
|
| 7 | + }
|
| 8 | +
|
| 9 | + public function execute ( ) {
|
| 10 | + $params = $this->extractRequestParams();
|
| 11 | +
|
| 12 | + $this->addTables( 'el_archive_queue' );
|
| 13 | + $this->addFields( '*' );
|
| 14 | + $this->addWhereRange( 'insertion_time', $params['dir'], $params['start'], $params['end'] );
|
| 15 | + $this->addOption( 'LIMIT', $params['limit'] + 1 );
|
| 16 | +
|
| 17 | + $res = $this->select( __METHOD__ );
|
| 18 | +
|
| 19 | + $val = array( );
|
| 20 | + $count = 0;
|
| 21 | + $result = $this->getResult();
|
| 22 | +
|
| 23 | + foreach ( $res as $row ) {
|
| 24 | + //much of this is stolen from ApiQueryRecentChanges
|
| 25 | + if ( ++ $count > $params['limit'] ) {
|
| 26 | + $this->setContinueEnumParameter( 'start', wfTimestamp( TS_UNIX, $row->insertion_time ) );
|
| 27 | + break;
|
| 28 | + }
|
| 29 | +
|
| 30 | + $val['time'] = $row->insertion_time;
|
| 31 | + $val['page_id'] = $row->page_id;
|
| 32 | + $val['url'] = $row->url;
|
| 33 | +
|
| 34 | + $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $val );
|
| 35 | +
|
| 36 | + if ( !$fit ) {
|
| 37 | + $this->setContinueEnumParameter( 'start', wfTimestamp( TS_UNIX, $row->insertion_time ) );
|
| 38 | + break;
|
| 39 | + }
|
| 40 | + }
|
| 41 | +
|
| 42 | + $result = $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'al' );
|
| 43 | + }
|
| 44 | +
|
| 45 | + function getVersion() {
|
| 46 | + return __CLASS__;
|
| 47 | + }
|
| 48 | +
|
| 49 | + function getAllowedParams() {
|
| 50 | + return array(
|
| 51 | + 'limit' => array(
|
| 52 | + ApiBase::PARAM_DFLT => 10,
|
| 53 | + ApiBase::PARAM_TYPE => 'limit',
|
| 54 | + ApiBase::PARAM_MIN => 1,
|
| 55 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
|
| 56 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
|
| 57 | + ),
|
| 58 | + 'start' => array(
|
| 59 | + ApiBase::PARAM_TYPE => 'timestamp'
|
| 60 | + ),
|
| 61 | + 'end' => array(
|
| 62 | + ApiBase::PARAM_TYPE => 'timestamp'
|
| 63 | + ),
|
| 64 | + 'dir' => array(
|
| 65 | + ApiBase::PARAM_DFLT => 'older',
|
| 66 | + ApiBase::PARAM_TYPE => array(
|
| 67 | + 'newer',
|
| 68 | + 'older'
|
| 69 | + )
|
| 70 | + )
|
| 71 | + );
|
| 72 | + }
|
| 73 | +} |
\ No newline at end of file |