r93856 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93855‎ | r93856 | r93857 >
Date:21:42, 3 August 2011
Author:kbrown
Status:deferred (Comments)
Tags:
Comment:
Add archive feed API list module for external archival services.
Modified paths:
  • /trunk/extensions/ArchiveLinks/ApiQueryArchiveFeed.php (added) (history)

Diff [purge]

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

Sign-offs

UserFlagDate
Kevin Browninspected02:33, 17 August 2011 (struck 02:34, 17 August 2011)

Follow-up revisions

RevisionCommit summaryAuthorDate
r93857fix EOL style from r83856.kbrown21:44, 3 August 2011

Comments

#Comment by NeilK (talk | contribs)   18:10, 5 August 2011

Does the prefix "al" conflict with the "alllinks" API methods? http://www.mediawiki.org/wiki/API:Alllinks

#Comment by Catrope (talk | contribs)   13:15, 10 August 2011

Yes. Such conflicts should be avoided, because it breaks support for combining arbitrary queries in one request.

#Comment by NeilK (talk | contribs)   19:19, 10 August 2011

marking fixme due to the prefix issue

#Comment by Kevin Brown (talk | contribs)   00:22, 11 August 2011

Thanks for catching this, I didn't notice it at the time. Would "afl" be a good prefix?

#Comment by NeilK (talk | contribs)   02:36, 11 August 2011

I have no idea how to ensure your API key is unique. I have trouble with this myself.

I just used this command to grep through the whole source tree, and it MAY have discovered all the possible keys that exist already...

$ find includes/api extensions/ -name 'Api*.php' | xargs grep __construct | perl -wlne '/moduleName\s*,\s*([^)]+)/ and print $1' | sort | uniq

$code $modulePrefix = $paramPrefix $paramPrefix = $prefix $prefix = 'ii' $prefix = 'vi' $this->prefix 'abf' 'ac' 'af' 'afl' 'ai' 'al' 'am' 'ap' 'au' 'bg' 'bk' 'cc' 'ci' 'cl' 'cm' 'cp' 'cr' 'cs' 'ct' 'df' 'dr' 'el' 'eu' 'fa' 'ga' 'gc' 'gu' 'gui' 'ii' 'im' 'in' 'iw' 'iwbl' 'lbl' 'le' 'll' 'mc' 'mg' 'or' 'pa' 'pp' 'pt' 'qp' 'rc' 'rn' 'rp' 'rt' 'rv' 'si' 'sii' 'sr' 'tb' 'tg' 'th' 'ti' 'uc' 'ui' 'ur' 'us' 've' 'wl' 'wr'

#Comment by Catrope (talk | contribs)   12:24, 11 August 2011

What I usually do is go to the API help page (the autogenerated one, which you get to by calling api.php without any parameters) and Ctrl+F for the desired prefix preceded by a space, or prefix+'limit'. That's pretty sure to find an existing prefix.

Status & tagging log