2009-02-13 21:34:46 +00:00
|
|
|
<?php
|
2010-02-24 14:45:19 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2009-02-13 21:34:46 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Feb 13, 2009
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
|
2009-02-13 21:34:46 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-13 21:34:46 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2009-02-13 21:34:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-13 21:36:34 +00:00
|
|
|
* Query module to enumerate all create-protected pages.
|
2009-02-13 21:34:46 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $query, $moduleName ) {
|
2010-02-24 14:45:19 +00:00
|
|
|
parent::__construct( $query, $moduleName, 'pt' );
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$this->run();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function executeGenerator( $resultPageSet ) {
|
|
|
|
|
$this->run( $resultPageSet );
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-19 00:30:18 +00:00
|
|
|
/**
|
|
|
|
|
* @param $resultPageSet ApiPageSet
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2011-02-19 00:30:18 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function run( $resultPageSet = null ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addTables( 'protected_titles' );
|
|
|
|
|
$this->addFields( array( 'pt_namespace', 'pt_title', 'pt_timestamp' ) );
|
2009-02-13 21:34:46 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$prop = array_flip( $params['prop'] );
|
2010-08-28 01:18:18 +00:00
|
|
|
$this->addFieldsIf( 'pt_user', isset( $prop['user'] ) || isset( $prop['userid'] ) );
|
2010-01-31 23:06:35 +00:00
|
|
|
$this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) );
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) );
|
|
|
|
|
$this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) );
|
2009-02-13 21:34:46 +00:00
|
|
|
|
2011-10-06 20:46:24 +00:00
|
|
|
$this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addWhereFld( 'pt_namespace', $params['namespace'] );
|
|
|
|
|
$this->addWhereFld( 'pt_create_perm', $params['level'] );
|
2010-02-24 14:45:19 +00:00
|
|
|
|
|
|
|
|
if ( isset( $prop['user'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addTables( 'user' );
|
|
|
|
|
$this->addFields( 'user_name' );
|
|
|
|
|
$this->addJoinConds( array( 'user' => array( 'LEFT JOIN',
|
2009-02-13 21:34:46 +00:00
|
|
|
'user_id=pt_user'
|
2010-01-11 15:55:52 +00:00
|
|
|
) ) );
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addOption( 'LIMIT', $params['limit'] + 1 );
|
|
|
|
|
$res = $this->select( __METHOD__ );
|
2009-02-13 21:34:46 +00:00
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
|
$result = $this->getResult();
|
2011-02-24 23:03:00 +00:00
|
|
|
|
|
|
|
|
$titles = array();
|
|
|
|
|
|
2010-06-20 18:48:34 +00:00
|
|
|
foreach ( $res as $row ) {
|
2013-11-14 12:56:06 +00:00
|
|
|
if ( ++$count > $params['limit'] ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) );
|
2009-02-13 21:34:46 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$title = Title::makeTitle( $row->pt_namespace, $row->pt_title );
|
|
|
|
|
if ( is_null( $resultPageSet ) ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$vals = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $vals, $title );
|
2010-02-24 14:45:19 +00:00
|
|
|
if ( isset( $prop['timestamp'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->pt_timestamp );
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $prop['user'] ) && !is_null( $row->user_name ) ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$vals['user'] = $row->user_name;
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-31 18:21:30 +00:00
|
|
|
if ( isset( $prop['userid'] ) || /*B/C*/isset( $prop['user'] ) ) {
|
2010-08-28 01:18:18 +00:00
|
|
|
$vals['userid'] = $row->pt_user;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-24 14:45:19 +00:00
|
|
|
if ( isset( $prop['comment'] ) ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$vals['comment'] = $row->pt_reason;
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-31 23:06:35 +00:00
|
|
|
if ( isset( $prop['parsedcomment'] ) ) {
|
2011-09-16 19:35:14 +00:00
|
|
|
$vals['parsedcomment'] = Linker::formatComment( $row->pt_reason, $title );
|
2010-01-31 23:06:35 +00:00
|
|
|
}
|
2010-02-24 14:45:19 +00:00
|
|
|
|
|
|
|
|
if ( isset( $prop['expiry'] ) ) {
|
2011-03-18 19:15:56 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
$vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 );
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $prop['level'] ) ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$vals['level'] = $row->pt_create_perm;
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
|
2010-01-31 23:06:35 +00:00
|
|
|
if ( !$fit ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->setContinueEnumParameter( 'start',
|
|
|
|
|
wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) );
|
2009-02-13 21:34:46 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$titles[] = $title;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-20 17:48:21 +00:00
|
|
|
|
2010-02-24 14:45:19 +00:00
|
|
|
if ( is_null( $resultPageSet ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->getModulePrefix() );
|
2010-02-24 14:45:19 +00:00
|
|
|
} else {
|
2010-01-11 15:55:52 +00:00
|
|
|
$resultPageSet->populateFromTitles( $titles );
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
public function getCacheMode( $params ) {
|
|
|
|
|
if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
|
2012-08-21 19:58:47 +00:00
|
|
|
// formatComment() calls wfMessage() among other things
|
2010-07-23 07:17:56 +00:00
|
|
|
return 'anon-public-user-private';
|
|
|
|
|
} else {
|
|
|
|
|
return 'public';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-13 21:34:46 +00:00
|
|
|
public function getAllowedParams() {
|
|
|
|
|
global $wgRestrictionLevels;
|
2013-11-14 12:56:06 +00:00
|
|
|
|
2010-02-24 14:45:19 +00:00
|
|
|
return array(
|
|
|
|
|
'namespace' => array(
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => 'namespace',
|
2009-02-13 21:34:46 +00:00
|
|
|
),
|
|
|
|
|
'level' => array(
|
2010-02-24 14:45:19 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => array_diff( $wgRestrictionLevels, array( '' ) )
|
2009-02-13 21:34:46 +00:00
|
|
|
),
|
2013-04-14 19:57:46 +00:00
|
|
|
'limit' => array(
|
2010-02-24 14:45:19 +00:00
|
|
|
ApiBase::PARAM_DFLT => 10,
|
|
|
|
|
ApiBase::PARAM_TYPE => 'limit',
|
|
|
|
|
ApiBase::PARAM_MIN => 1,
|
|
|
|
|
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
|
|
|
|
|
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
|
2009-02-13 21:34:46 +00:00
|
|
|
),
|
2010-02-24 14:45:19 +00:00
|
|
|
'dir' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => 'older',
|
|
|
|
|
ApiBase::PARAM_TYPE => array(
|
2011-02-24 00:52:09 +00:00
|
|
|
'newer',
|
|
|
|
|
'older'
|
2009-02-13 21:34:46 +00:00
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
'start' => array(
|
2010-02-24 14:45:19 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'timestamp'
|
2009-02-13 21:34:46 +00:00
|
|
|
),
|
|
|
|
|
'end' => array(
|
2010-02-24 14:45:19 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'timestamp'
|
2009-02-13 21:34:46 +00:00
|
|
|
),
|
|
|
|
|
'prop' => array(
|
2010-02-24 14:45:19 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_DFLT => 'timestamp|level',
|
|
|
|
|
ApiBase::PARAM_TYPE => array(
|
2009-02-13 21:34:46 +00:00
|
|
|
'timestamp',
|
|
|
|
|
'user',
|
2010-08-28 01:18:18 +00:00
|
|
|
'userid',
|
2009-02-13 21:34:46 +00:00
|
|
|
'comment',
|
2010-01-31 23:06:35 +00:00
|
|
|
'parsedcomment',
|
2009-02-13 21:34:46 +00:00
|
|
|
'expiry',
|
|
|
|
|
'level'
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getParamDescription() {
|
2010-02-24 14:45:19 +00:00
|
|
|
return array(
|
2009-02-13 21:34:46 +00:00
|
|
|
'namespace' => 'Only list titles in these namespaces',
|
|
|
|
|
'start' => 'Start listing at this protection timestamp',
|
|
|
|
|
'end' => 'Stop listing at this protection timestamp',
|
2011-03-12 23:39:15 +00:00
|
|
|
'dir' => $this->getDirectionDescription( $this->getModulePrefix() ),
|
2010-05-11 22:30:18 +00:00
|
|
|
'limit' => 'How many total pages to return',
|
2010-06-23 19:36:26 +00:00
|
|
|
'prop' => array(
|
|
|
|
|
'Which properties to get',
|
|
|
|
|
' timestamp - Adds the timestamp of when protection was added',
|
2011-02-27 00:40:06 +00:00
|
|
|
' user - Adds the user that added the protection',
|
|
|
|
|
' userid - Adds the user id that added the protection',
|
2010-06-23 19:36:26 +00:00
|
|
|
' comment - Adds the comment for the protection',
|
|
|
|
|
' parsedcomment - Adds the parsed comment for the protection',
|
|
|
|
|
' expiry - Adds the timestamp of when the protection will be lifted',
|
|
|
|
|
' level - Adds the protection level',
|
|
|
|
|
),
|
2009-02-13 21:53:08 +00:00
|
|
|
'level' => 'Only list titles with these protection levels',
|
2009-02-13 21:34:46 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
public function getResultProperties() {
|
|
|
|
|
global $wgRestrictionLevels;
|
2013-11-14 12:56:06 +00:00
|
|
|
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
return array(
|
|
|
|
|
'' => array(
|
|
|
|
|
'ns' => 'namespace',
|
|
|
|
|
'title' => 'string'
|
|
|
|
|
),
|
|
|
|
|
'timestamp' => array(
|
|
|
|
|
'timestamp' => 'timestamp'
|
|
|
|
|
),
|
|
|
|
|
'user' => array(
|
|
|
|
|
'user' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'string',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'userid' => 'integer'
|
|
|
|
|
),
|
2012-10-31 18:21:30 +00:00
|
|
|
'userid' => array(
|
|
|
|
|
'userid' => 'integer'
|
|
|
|
|
),
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
'comment' => array(
|
|
|
|
|
'comment' => 'string'
|
|
|
|
|
),
|
|
|
|
|
'parsedcomment' => array(
|
|
|
|
|
'parsedcomment' => 'string'
|
|
|
|
|
),
|
|
|
|
|
'expiry' => array(
|
|
|
|
|
'expiry' => 'timestamp'
|
|
|
|
|
),
|
|
|
|
|
'level' => array(
|
|
|
|
|
'level' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => array_diff( $wgRestrictionLevels, array( '' ) )
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-13 21:34:46 +00:00
|
|
|
public function getDescription() {
|
|
|
|
|
return 'List all titles protected from creation';
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getExamples() {
|
2010-02-24 14:45:19 +00:00
|
|
|
return array(
|
2009-02-13 21:34:46 +00:00
|
|
|
'api.php?action=query&list=protectedtitles',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 17:02:06 +00:00
|
|
|
public function getHelpUrls() {
|
2011-11-28 15:43:11 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/API:Protectedtitles';
|
2011-07-17 17:02:06 +00:00
|
|
|
}
|
2010-07-23 07:17:56 +00:00
|
|
|
}
|