MediaWiki
REL1_24
|
00001 <?php 00032 class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { 00033 00034 public function __construct( ApiQuery $query, $moduleName ) { 00035 parent::__construct( $query, $moduleName, 'pt' ); 00036 } 00037 00038 public function execute() { 00039 $this->run(); 00040 } 00041 00042 public function executeGenerator( $resultPageSet ) { 00043 $this->run( $resultPageSet ); 00044 } 00045 00050 private function run( $resultPageSet = null ) { 00051 $params = $this->extractRequestParams(); 00052 00053 $this->addTables( 'protected_titles' ); 00054 $this->addFields( array( 'pt_namespace', 'pt_title', 'pt_timestamp' ) ); 00055 00056 $prop = array_flip( $params['prop'] ); 00057 $this->addFieldsIf( 'pt_user', isset( $prop['user'] ) || isset( $prop['userid'] ) ); 00058 $this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) ); 00059 $this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) ); 00060 $this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) ); 00061 00062 $this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] ); 00063 $this->addWhereFld( 'pt_namespace', $params['namespace'] ); 00064 $this->addWhereFld( 'pt_create_perm', $params['level'] ); 00065 00066 // Include in ORDER BY for uniqueness 00067 $this->addWhereRange( 'pt_namespace', $params['dir'], null, null ); 00068 $this->addWhereRange( 'pt_title', $params['dir'], null, null ); 00069 00070 if ( !is_null( $params['continue'] ) ) { 00071 $cont = explode( '|', $params['continue'] ); 00072 $this->dieContinueUsageIf( count( $cont ) != 3 ); 00073 $op = ( $params['dir'] === 'newer' ? '>' : '<' ); 00074 $db = $this->getDB(); 00075 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) ); 00076 $continueNs = (int)$cont[1]; 00077 $this->dieContinueUsageIf( $continueNs != $cont[1] ); 00078 $continueTitle = $db->addQuotes( $cont[2] ); 00079 $this->addWhere( "pt_timestamp $op $continueTimestamp OR " . 00080 "(pt_timestamp = $continueTimestamp AND " . 00081 "(pt_namespace $op $continueNs OR " . 00082 "(pt_namespace = $continueNs AND " . 00083 "pt_title $op= $continueTitle)))" 00084 ); 00085 } 00086 00087 if ( isset( $prop['user'] ) ) { 00088 $this->addTables( 'user' ); 00089 $this->addFields( 'user_name' ); 00090 $this->addJoinConds( array( 'user' => array( 'LEFT JOIN', 00091 'user_id=pt_user' 00092 ) ) ); 00093 } 00094 00095 $this->addOption( 'LIMIT', $params['limit'] + 1 ); 00096 $res = $this->select( __METHOD__ ); 00097 00098 $count = 0; 00099 $result = $this->getResult(); 00100 00101 $titles = array(); 00102 00103 foreach ( $res as $row ) { 00104 if ( ++$count > $params['limit'] ) { 00105 // We've reached the one extra which shows that there are 00106 // additional pages to be had. Stop here... 00107 $this->setContinueEnumParameter( 'continue', 00108 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title" 00109 ); 00110 break; 00111 } 00112 00113 $title = Title::makeTitle( $row->pt_namespace, $row->pt_title ); 00114 if ( is_null( $resultPageSet ) ) { 00115 $vals = array(); 00116 ApiQueryBase::addTitleInfo( $vals, $title ); 00117 if ( isset( $prop['timestamp'] ) ) { 00118 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->pt_timestamp ); 00119 } 00120 00121 if ( isset( $prop['user'] ) && !is_null( $row->user_name ) ) { 00122 $vals['user'] = $row->user_name; 00123 } 00124 00125 if ( isset( $prop['userid'] ) || /*B/C*/isset( $prop['user'] ) ) { 00126 $vals['userid'] = $row->pt_user; 00127 } 00128 00129 if ( isset( $prop['comment'] ) ) { 00130 $vals['comment'] = $row->pt_reason; 00131 } 00132 00133 if ( isset( $prop['parsedcomment'] ) ) { 00134 $vals['parsedcomment'] = Linker::formatComment( $row->pt_reason, $title ); 00135 } 00136 00137 if ( isset( $prop['expiry'] ) ) { 00138 global $wgContLang; 00139 $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 ); 00140 } 00141 00142 if ( isset( $prop['level'] ) ) { 00143 $vals['level'] = $row->pt_create_perm; 00144 } 00145 00146 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); 00147 if ( !$fit ) { 00148 $this->setContinueEnumParameter( 'continue', 00149 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title" 00150 ); 00151 break; 00152 } 00153 } else { 00154 $titles[] = $title; 00155 } 00156 } 00157 00158 if ( is_null( $resultPageSet ) ) { 00159 $result->setIndexedTagName_internal( 00160 array( 'query', $this->getModuleName() ), 00161 $this->getModulePrefix() 00162 ); 00163 } else { 00164 $resultPageSet->populateFromTitles( $titles ); 00165 } 00166 } 00167 00168 public function getCacheMode( $params ) { 00169 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { 00170 // formatComment() calls wfMessage() among other things 00171 return 'anon-public-user-private'; 00172 } else { 00173 return 'public'; 00174 } 00175 } 00176 00177 public function getAllowedParams() { 00178 return array( 00179 'namespace' => array( 00180 ApiBase::PARAM_ISMULTI => true, 00181 ApiBase::PARAM_TYPE => 'namespace', 00182 ), 00183 'level' => array( 00184 ApiBase::PARAM_ISMULTI => true, 00185 ApiBase::PARAM_TYPE => array_diff( $this->getConfig()->get( 'RestrictionLevels' ), array( '' ) ) 00186 ), 00187 'limit' => array( 00188 ApiBase::PARAM_DFLT => 10, 00189 ApiBase::PARAM_TYPE => 'limit', 00190 ApiBase::PARAM_MIN => 1, 00191 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, 00192 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 00193 ), 00194 'dir' => array( 00195 ApiBase::PARAM_DFLT => 'older', 00196 ApiBase::PARAM_TYPE => array( 00197 'newer', 00198 'older' 00199 ) 00200 ), 00201 'start' => array( 00202 ApiBase::PARAM_TYPE => 'timestamp' 00203 ), 00204 'end' => array( 00205 ApiBase::PARAM_TYPE => 'timestamp' 00206 ), 00207 'prop' => array( 00208 ApiBase::PARAM_ISMULTI => true, 00209 ApiBase::PARAM_DFLT => 'timestamp|level', 00210 ApiBase::PARAM_TYPE => array( 00211 'timestamp', 00212 'user', 00213 'userid', 00214 'comment', 00215 'parsedcomment', 00216 'expiry', 00217 'level' 00218 ) 00219 ), 00220 'continue' => null, 00221 ); 00222 } 00223 00224 public function getParamDescription() { 00225 return array( 00226 'namespace' => 'Only list titles in these namespaces', 00227 'start' => 'Start listing at this protection timestamp', 00228 'end' => 'Stop listing at this protection timestamp', 00229 'dir' => $this->getDirectionDescription( $this->getModulePrefix() ), 00230 'limit' => 'How many total pages to return', 00231 'prop' => array( 00232 'Which properties to get', 00233 ' timestamp - Adds the timestamp of when protection was added', 00234 ' user - Adds the user that added the protection', 00235 ' userid - Adds the user id that added the protection', 00236 ' comment - Adds the comment for the protection', 00237 ' parsedcomment - Adds the parsed comment for the protection', 00238 ' expiry - Adds the timestamp of when the protection will be lifted', 00239 ' level - Adds the protection level', 00240 ), 00241 'level' => 'Only list titles with these protection levels', 00242 'continue' => 'When more results are available, use this to continue', 00243 ); 00244 } 00245 00246 public function getDescription() { 00247 return 'List all titles protected from creation.'; 00248 } 00249 00250 public function getExamples() { 00251 return array( 00252 'api.php?action=query&list=protectedtitles', 00253 ); 00254 } 00255 00256 public function getHelpUrls() { 00257 return 'https://www.mediawiki.org/wiki/API:Protectedtitles'; 00258 } 00259 }