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->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", '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 if(isset($params['continue']))
00072 {
00073 $cont = explode('|', $params['continue']);
00074 if(count($cont) != 2)
00075 $this->dieUsage("Invalid continue param. You should pass the " .
00076 "original value returned by the previous query", "_badcontinue");
00077 $ns = intval($cont[0]);
00078 $title = $this->getDB()->strencode($this->titleToKey($cont[1]));
00079 $this->addWhere("wl_namespace > '$ns' OR ".
00080 "(wl_namespace = '$ns' AND ".
00081 "wl_title >= '$title')");
00082 }
00083
00084 if(count($params['namespace']) == 1)
00085 $this->addOption('ORDER BY', 'wl_title');
00086 else
00087 $this->addOption('ORDER BY', 'wl_namespace, wl_title');
00088 $this->addOption('LIMIT', $params['limit'] + 1);
00089 $res = $this->select(__METHOD__);
00090
00091 $db = $this->getDB();
00092 $titles = array();
00093 $count = 0;
00094 while($row = $db->fetchObject($res))
00095 {
00096 if(++$count > $params['limit'])
00097 {
00098
00099 $this->setContinueEnumParameter('continue', $row->wl_namespace . '|' .
00100 $this->keyToTitle($row->wl_title));
00101 break;
00102 }
00103 $t = Title::makeTitle($row->wl_namespace, $row->wl_title);
00104 if(is_null($resultPageSet))
00105 {
00106 $vals = array();
00107 ApiQueryBase::addTitleInfo($vals, $t);
00108 if(isset($prop['changed']) && !is_null($row->wl_notificationtimestamp))
00109 $vals['changed'] = wfTimestamp(TS_ISO_8601, $row->wl_notificationtimestamp);
00110 $fit = $this->getResult()->addValue($this->getModuleName(), null, $vals);
00111 if(!$fit)
00112 {
00113 $this->setContinueEnumParameter('continue', $row->wl_namespace . '|' .
00114 $this->keyToTitle($row->wl_title));
00115 break;
00116 }
00117 }
00118 else
00119 $titles[] = $t;
00120 }
00121 if(is_null($resultPageSet))
00122 $this->getResult()->setIndexedTagName_internal($this->getModuleName(), 'wr');
00123 else
00124 $resultPageSet->populateFromTitles($titles);
00125 }
00126
00127 public function getAllowedParams() {
00128 return array (
00129 'continue' => null,
00130 'namespace' => array (
00131 ApiBase :: PARAM_ISMULTI => true,
00132 ApiBase :: PARAM_TYPE => 'namespace'
00133 ),
00134 'limit' => array (
00135 ApiBase :: PARAM_DFLT => 10,
00136 ApiBase :: PARAM_TYPE => 'limit',
00137 ApiBase :: PARAM_MIN => 1,
00138 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00139 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00140 ),
00141 'prop' => array (
00142 ApiBase :: PARAM_ISMULTI => true,
00143 ApiBase :: PARAM_TYPE => array (
00144 'changed',
00145 )
00146 ),
00147 'show' => array (
00148 ApiBase :: PARAM_ISMULTI => true,
00149 ApiBase :: PARAM_TYPE => array (
00150 'changed',
00151 '!changed',
00152 )
00153 )
00154 );
00155 }
00156
00157 public function getParamDescription() {
00158 return array (
00159 'continue' => 'When more results are available, use this to continue',
00160 'namespace' => 'Only list pages in the given namespace(s).',
00161 'limit' => 'How many total results to return per request.',
00162 'prop' => 'Which additional properties to get (non-generator mode only).',
00163 'show' => 'Only list items that meet these criteria.',
00164 );
00165 }
00166
00167 public function getDescription() {
00168 return "Get all pages on the logged in user's watchlist";
00169 }
00170
00171 protected function getExamples() {
00172 return array (
00173 'api.php?action=query&list=watchlistraw',
00174 'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions',
00175 );
00176 }
00177
00178 public function getVersion() {
00179 return __CLASS__ . ': $Id: ApiQueryWatchlistRaw.php 46845 2009-02-05 14:30:59Z catrope $';
00180 }
00181 }