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'] ) || isset( $prop['parsedcomment'] ) );
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
00095 if ( isset( $prop['user'] ) && !is_null( $row->user_name ) )
00096 $vals['user'] = $row->user_name;
00097
00098 if ( isset( $prop['comment'] ) )
00099 $vals['comment'] = $row->pt_reason;
00100
00101 if ( isset( $prop['parsedcomment'] ) ) {
00102 global $wgUser;
00103 $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->pt_reason, $title );
00104 }
00105
00106 if ( isset( $prop['expiry'] ) )
00107 $vals['expiry'] = Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 );
00108
00109 if ( isset( $prop['level'] ) )
00110 $vals['level'] = $row->pt_create_perm;
00111
00112 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
00113 if ( !$fit ) {
00114 $this->setContinueEnumParameter( 'start',
00115 wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) );
00116 break;
00117 }
00118 } else {
00119 $titles[] = $title;
00120 }
00121 }
00122 $db->freeResult( $res );
00123 if ( is_null( $resultPageSet ) )
00124 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->getModulePrefix() );
00125 else
00126 $resultPageSet->populateFromTitles( $titles );
00127 }
00128
00129 public function getCacheMode( $params ) {
00130 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
00131
00132 return 'anon-public-user-private';
00133 } else {
00134 return 'public';
00135 }
00136 }
00137
00138 public function getAllowedParams() {
00139 global $wgRestrictionLevels;
00140 return array (
00141 'namespace' => array (
00142 ApiBase :: PARAM_ISMULTI => true,
00143 ApiBase :: PARAM_TYPE => 'namespace',
00144 ),
00145 'level' => array(
00146 ApiBase :: PARAM_ISMULTI => true,
00147 ApiBase :: PARAM_TYPE => array_diff( $wgRestrictionLevels, array( '' ) )
00148 ),
00149 'limit' => array (
00150 ApiBase :: PARAM_DFLT => 10,
00151 ApiBase :: PARAM_TYPE => 'limit',
00152 ApiBase :: PARAM_MIN => 1,
00153 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00154 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00155 ),
00156 'dir' => array (
00157 ApiBase :: PARAM_DFLT => 'older',
00158 ApiBase :: PARAM_TYPE => array (
00159 'older',
00160 'newer'
00161 )
00162 ),
00163 'start' => array(
00164 ApiBase :: PARAM_TYPE => 'timestamp'
00165 ),
00166 'end' => array(
00167 ApiBase :: PARAM_TYPE => 'timestamp'
00168 ),
00169 'prop' => array(
00170 ApiBase :: PARAM_ISMULTI => true,
00171 ApiBase :: PARAM_DFLT => 'timestamp|level',
00172 ApiBase :: PARAM_TYPE => array(
00173 'timestamp',
00174 'user',
00175 'comment',
00176 'parsedcomment',
00177 'expiry',
00178 'level'
00179 )
00180 ),
00181 );
00182 }
00183
00184 public function getParamDescription() {
00185 return array (
00186 'namespace' => 'Only list titles in these namespaces',
00187 'start' => 'Start listing at this protection timestamp',
00188 'end' => 'Stop listing at this protection timestamp',
00189 'dir' => 'The direction in which to list',
00190 'limit' => 'How many total pages to return.',
00191 'prop' => 'Which properties to get',
00192 'level' => 'Only list titles with these protection levels',
00193 );
00194 }
00195
00196 public function getDescription() {
00197 return 'List all titles protected from creation';
00198 }
00199
00200 protected function getExamples() {
00201 return array (
00202 'api.php?action=query&list=protectedtitles',
00203 );
00204 }
00205
00206 public function getVersion() {
00207 return __CLASS__ . ': $Id: ApiQueryProtectedTitles.php 69932 2010-07-26 08:03:21Z tstarling $';
00208 }
00209 }