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 getCacheMode( $params ) {
00122 return 'public';
00123 }
00124
00125 public function getAllowedParams() {
00126 global $wgRestrictionLevels;
00127 return array (
00128 'namespace' => array (
00129 ApiBase :: PARAM_ISMULTI => true,
00130 ApiBase :: PARAM_TYPE => 'namespace',
00131 ),
00132 'level' => array(
00133 ApiBase :: PARAM_ISMULTI => true,
00134 ApiBase :: PARAM_TYPE => array_diff($wgRestrictionLevels, array(''))
00135 ),
00136 'limit' => array (
00137 ApiBase :: PARAM_DFLT => 10,
00138 ApiBase :: PARAM_TYPE => 'limit',
00139 ApiBase :: PARAM_MIN => 1,
00140 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00141 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00142 ),
00143 'dir' => array (
00144 ApiBase :: PARAM_DFLT => 'older',
00145 ApiBase :: PARAM_TYPE => array (
00146 'older',
00147 'newer'
00148 )
00149 ),
00150 'start' => array(
00151 ApiBase :: PARAM_TYPE => 'timestamp'
00152 ),
00153 'end' => array(
00154 ApiBase :: PARAM_TYPE => 'timestamp'
00155 ),
00156 'prop' => array(
00157 ApiBase :: PARAM_ISMULTI => true,
00158 ApiBase :: PARAM_DFLT => 'timestamp|level',
00159 ApiBase :: PARAM_TYPE => array(
00160 'timestamp',
00161 'user',
00162 'comment',
00163 'expiry',
00164 'level'
00165 )
00166 ),
00167 );
00168 }
00169
00170 public function getParamDescription() {
00171 return array (
00172 'namespace' => 'Only list titles in these namespaces',
00173 'start' => 'Start listing at this protection timestamp',
00174 'end' => 'Stop listing at this protection timestamp',
00175 'dir' => 'The direction in which to list',
00176 'limit' => 'How many total pages to return.',
00177 'prop' => 'Which properties to get',
00178 'level' => 'Only list titles with these protection levels',
00179 );
00180 }
00181
00182 public function getDescription() {
00183 return 'List all titles protected from creation';
00184 }
00185
00186 protected function getExamples() {
00187 return array (
00188 'api.php?action=query&list=protectedtitles',
00189 );
00190 }
00191
00192 public function getVersion() {
00193 return __CLASS__ . ': $Id: ApiQueryProtectedTitles.php 69986 2010-07-27 03:57:39Z tstarling $';
00194 }
00195 }