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
00036 class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
00037
00038 public function __construct($query, $moduleName) {
00039 parent :: __construct($query, $moduleName, 'pt');
00040 }
00041
00042 public function execute() {
00043 $this->run();
00044 }
00045
00046 public function executeGenerator($resultPageSet) {
00047 $this->run($resultPageSet);
00048 }
00049
00050 private function run($resultPageSet = null) {
00051 $db = $this->getDB();
00052 $params = $this->extractRequestParams();
00053
00054 $this->addTables('protected_titles');
00055 $this->addFields(array('pt_namespace', 'pt_title', 'pt_timestamp'));
00056
00057 $prop = array_flip($params['prop']);
00058 $this->addFieldsIf('pt_user', isset($prop['user']));
00059 $this->addFieldsIf('pt_reason', isset($prop['comment']));
00060 $this->addFieldsIf('pt_expiry', isset($prop['expiry']));
00061 $this->addFieldsIf('pt_create_perm', isset($prop['level']));
00062
00063 $this->addWhereRange('pt_timestamp', $params['dir'], $params['start'], $params['end']);
00064 $this->addWhereFld('pt_namespace', $params['namespace']);
00065 $this->addWhereFld('pt_create_perm', $params['level']);
00066
00067 if(isset($prop['user']))
00068 {
00069 $this->addTables('user');
00070 $this->addFields('user_name');
00071 $this->addJoinConds(array('user' => array('LEFT JOIN',
00072 'user_id=pt_user'
00073 )));
00074 }
00075
00076 $this->addOption('LIMIT', $params['limit'] + 1);
00077 $res = $this->select(__METHOD__);
00078
00079 $count = 0;
00080 $result = $this->getResult();
00081 while ($row = $db->fetchObject($res)) {
00082 if (++ $count > $params['limit']) {
00083
00084 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
00085 break;
00086 }
00087
00088 $title = Title::makeTitle($row->pt_namespace, $row->pt_title);
00089 if (is_null($resultPageSet)) {
00090 $vals = array();
00091 ApiQueryBase::addTitleInfo($vals, $title);
00092 if(isset($prop['timestamp']))
00093 $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->pt_timestamp);
00094 if(isset($prop['user']) && !is_null($row->user_name))
00095 $vals['user'] = $row->user_name;
00096 if(isset($prop['comment']))
00097 $vals['comment'] = $row->pt_reason;
00098 if(isset($prop['expiry']))
00099 $vals['expiry'] = Block::decodeExpiry($row->pt_expiry, TS_ISO_8601);
00100 if(isset($prop['level']))
00101 $vals['level'] = $row->pt_create_perm;
00102
00103 $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
00104 if(!$fit)
00105 {
00106 $this->setContinueEnumParameter('start',
00107 wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
00108 break;
00109 }
00110 } else {
00111 $titles[] = $title;
00112 }
00113 }
00114 $db->freeResult($res);
00115 if(is_null($resultPageSet))
00116 $result->setIndexedTagName_internal(array('query', $this->getModuleName()), $this->getModulePrefix());
00117 else
00118 $resultPageSet->populateFromTitles($titles);
00119 }
00120
00121 public function getAllowedParams() {
00122 global $wgRestrictionLevels;
00123 return array (
00124 'namespace' => array (
00125 ApiBase :: PARAM_ISMULTI => true,
00126 ApiBase :: PARAM_TYPE => 'namespace',
00127 ),
00128 'level' => array(
00129 ApiBase :: PARAM_ISMULTI => true,
00130 ApiBase :: PARAM_TYPE => array_diff($wgRestrictionLevels, array(''))
00131 ),
00132 'limit' => array (
00133 ApiBase :: PARAM_DFLT => 10,
00134 ApiBase :: PARAM_TYPE => 'limit',
00135 ApiBase :: PARAM_MIN => 1,
00136 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00137 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00138 ),
00139 'dir' => array (
00140 ApiBase :: PARAM_DFLT => 'older',
00141 ApiBase :: PARAM_TYPE => array (
00142 'older',
00143 'newer'
00144 )
00145 ),
00146 'start' => array(
00147 ApiBase :: PARAM_TYPE => 'timestamp'
00148 ),
00149 'end' => array(
00150 ApiBase :: PARAM_TYPE => 'timestamp'
00151 ),
00152 'prop' => array(
00153 ApiBase :: PARAM_ISMULTI => true,
00154 ApiBase :: PARAM_DFLT => 'timestamp|level',
00155 ApiBase :: PARAM_TYPE => array(
00156 'timestamp',
00157 'user',
00158 'comment',
00159 'expiry',
00160 'level'
00161 )
00162 ),
00163 );
00164 }
00165
00166 public function getParamDescription() {
00167 return array (
00168 'namespace' => 'Only list titles in these namespaces',
00169 'start' => 'Start listing at this protection timestamp',
00170 'end' => 'Stop listing at this protection timestamp',
00171 'dir' => 'The direction in which to list',
00172 'limit' => 'How many total pages to return.',
00173 'prop' => 'Which properties to get',
00174 'level' => 'Only list titles with these protection levels',
00175 );
00176 }
00177
00178 public function getDescription() {
00179 return 'List all titles protected from creation';
00180 }
00181
00182 protected function getExamples() {
00183 return array (
00184 'api.php?action=query&list=protectedtitles',
00185 );
00186 }
00187
00188 public function getVersion() {
00189 return __CLASS__ . ': $Id: ApiQueryProtectedTitles.php 47235 2009-02-13 21:53:08Z catrope $';
00190 }
00191 }