00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if ( !defined( 'MEDIAWIKI' ) ) {
00027
00028 require_once ( 'ApiQueryBase.php' );
00029 }
00030
00037 class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
00038
00039 public function __construct( $query, $moduleName ) {
00040 parent :: __construct( $query, $moduleName, 'wr' );
00041 }
00042
00043 public function execute() {
00044 $this->run();
00045 }
00046
00047 public function executeGenerator( $resultPageSet ) {
00048 $this->run( $resultPageSet );
00049 }
00050
00051 private function run( $resultPageSet = null ) {
00052 global $wgUser;
00053
00054 $this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
00055
00056 if ( !$wgUser->isLoggedIn() )
00057 $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
00058 $params = $this->extractRequestParams();
00059 $prop = array_flip( (array)$params['prop'] );
00060 $show = array_flip( (array)$params['show'] );
00061 if ( isset( $show['changed'] ) && isset( $show['!changed'] ) )
00062 $this->dieUsageMsg( array( 'show' ) );
00063
00064 $this->addTables( 'watchlist' );
00065 $this->addFields( array( 'wl_namespace', 'wl_title' ) );
00066 $this->addFieldsIf( 'wl_notificationtimestamp', isset( $prop['changed'] ) );
00067 $this->addWhereFld( 'wl_user', $wgUser->getId() );
00068 $this->addWhereFld( 'wl_namespace', $params['namespace'] );
00069 $this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['changed'] ) );
00070 $this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!changed'] ) );
00071
00072 if ( isset( $params['continue'] ) )
00073 {
00074 $cont = explode( '|', $params['continue'] );
00075 if ( count( $cont ) != 2 )
00076 $this->dieUsage( "Invalid continue param. You should pass the " .
00077 "original value returned by the previous query", "_badcontinue" );
00078 $ns = intval( $cont[0] );
00079 $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
00080 $this->addWhere( "wl_namespace > '$ns' OR " .
00081 "(wl_namespace = '$ns' AND " .
00082 "wl_title >= '$title')" );
00083 }
00084
00085
00086 if ( count( $params['namespace'] ) == 1 )
00087 $this->addOption( 'ORDER BY', 'wl_title' );
00088 else
00089 $this->addOption( 'ORDER BY', 'wl_namespace, wl_title' );
00090 $this->addOption( 'LIMIT', $params['limit'] + 1 );
00091 $res = $this->select( __METHOD__ );
00092
00093 $db = $this->getDB();
00094 $titles = array();
00095 $count = 0;
00096 while ( $row = $db->fetchObject( $res ) )
00097 {
00098 if ( ++$count > $params['limit'] )
00099 {
00100
00101 $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' .
00102 $this->keyToTitle( $row->wl_title ) );
00103 break;
00104 }
00105 $t = Title::makeTitle( $row->wl_namespace, $row->wl_title );
00106
00107 if ( is_null( $resultPageSet ) )
00108 {
00109 $vals = array();
00110 ApiQueryBase::addTitleInfo( $vals, $t );
00111 if ( isset( $prop['changed'] ) && !is_null( $row->wl_notificationtimestamp ) )
00112 $vals['changed'] = wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp );
00113 $fit = $this->getResult()->addValue( $this->getModuleName(), null, $vals );
00114 if ( !$fit )
00115 {
00116 $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' .
00117 $this->keyToTitle( $row->wl_title ) );
00118 break;
00119 }
00120 }
00121 else
00122 $titles[] = $t;
00123 }
00124 if ( is_null( $resultPageSet ) )
00125 $this->getResult()->setIndexedTagName_internal( $this->getModuleName(), 'wr' );
00126 else
00127 $resultPageSet->populateFromTitles( $titles );
00128 }
00129
00130 public function getAllowedParams() {
00131 return array (
00132 'continue' => null,
00133 'namespace' => array (
00134 ApiBase :: PARAM_ISMULTI => true,
00135 ApiBase :: PARAM_TYPE => 'namespace'
00136 ),
00137 'limit' => array (
00138 ApiBase :: PARAM_DFLT => 10,
00139 ApiBase :: PARAM_TYPE => 'limit',
00140 ApiBase :: PARAM_MIN => 1,
00141 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00142 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00143 ),
00144 'prop' => array (
00145 ApiBase :: PARAM_ISMULTI => true,
00146 ApiBase :: PARAM_TYPE => array (
00147 'changed',
00148 )
00149 ),
00150 'show' => array (
00151 ApiBase :: PARAM_ISMULTI => true,
00152 ApiBase :: PARAM_TYPE => array (
00153 'changed',
00154 '!changed',
00155 )
00156 )
00157 );
00158 }
00159
00160 public function getParamDescription() {
00161 return array (
00162 'continue' => 'When more results are available, use this to continue',
00163 'namespace' => 'Only list pages in the given namespace(s).',
00164 'limit' => 'How many total results to return per request.',
00165 'prop' => 'Which additional properties to get (non-generator mode only).',
00166 'show' => 'Only list items that meet these criteria.',
00167 );
00168 }
00169
00170 public function getDescription() {
00171 return "Get all pages on the logged in user's watchlist";
00172 }
00173
00174 public function getPossibleErrors() {
00175 return array_merge( parent::getPossibleErrors(), array(
00176 array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
00177 array( 'show' ),
00178 ) );
00179 }
00180
00181 protected function getExamples() {
00182 return array (
00183 'api.php?action=query&list=watchlistraw',
00184 'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions',
00185 );
00186 }
00187
00188 public function getVersion() {
00189 return __CLASS__ . ': $Id: ApiQueryWatchlistRaw.php 69578 2010-07-20 02:46:20Z tstarling $';
00190 }
00191 }