// First, count anons
$this->addTables( 'revision' );
- $this->addFields( array(
+ $this->addFields( [
'page' => 'rev_page',
'anons' => 'COUNT(DISTINCT rev_user_text)',
- ) );
+ ] );
$this->addWhereFld( 'rev_page', $pages );
$this->addWhere( 'rev_user = 0' );
$this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
$this->addOption( 'GROUP BY', 'rev_page' );
$res = $this->select( __METHOD__ );
foreach ( $res as $row ) {
- $fit = $result->addValue( array( 'query', 'pages', $row->page ),
- 'anoncontributors', $row->anons
+ $fit = $result->addValue( [ 'query', 'pages', $row->page ],
+ 'anoncontributors', (int)$row->anons
);
if ( !$fit ) {
// This not fitting isn't reasonable, so it probably means that
// Next, add logged-in users
$this->resetQueryParams();
$this->addTables( 'revision' );
- $this->addFields( array(
+ $this->addFields( [
'page' => 'rev_page',
'user' => 'rev_user',
'username' => 'MAX(rev_user_text)', // Non-MySQL databases don't like partial group-by
- ) );
+ ] );
$this->addWhereFld( 'rev_page', $pages );
$this->addWhere( 'rev_user != 0' );
$this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
$this->addOption( 'ORDER BY', 'rev_user' );
}
- $limitGroups = array();
+ $limitGroups = [];
if ( $params['group'] ) {
$excludeGroups = false;
$limitGroups = $params['group'];
if ( $limitGroups ) {
$limitGroups = array_unique( $limitGroups );
$this->addTables( 'user_groups' );
- $this->addJoinConds( array( 'user_groups' => array(
+ $this->addJoinConds( [ 'user_groups' => [
$excludeGroups ? 'LEFT OUTER JOIN' : 'INNER JOIN',
- array( 'ug_user=rev_user', 'ug_group' => $limitGroups )
- ) ) );
+ [ 'ug_user=rev_user', 'ug_group' => $limitGroups ]
+ ] ] );
$this->addWhereIf( 'ug_user IS NULL', $excludeGroups );
}
}
$fit = $this->addPageSubItem( $row->page,
- array( 'userid' => $row->user, 'name' => $row->username ),
+ [ 'userid' => (int)$row->user, 'name' => $row->username ],
'user'
);
if ( !$fit ) {
$userGroups = User::getAllGroups();
$userRights = User::getAllRights();
- return array(
- 'group' => array(
+ return [
+ 'group' => [
ApiBase::PARAM_TYPE => $userGroups,
ApiBase::PARAM_ISMULTI => true,
- ),
- 'excludegroup' => array(
+ ],
+ 'excludegroup' => [
ApiBase::PARAM_TYPE => $userGroups,
ApiBase::PARAM_ISMULTI => true,
- ),
- 'rights' => array(
+ ],
+ 'rights' => [
ApiBase::PARAM_TYPE => $userRights,
ApiBase::PARAM_ISMULTI => true,
- ),
- 'excluderights' => array(
+ ],
+ 'excluderights' => [
ApiBase::PARAM_TYPE => $userRights,
ApiBase::PARAM_ISMULTI => true,
- ),
- 'limit' => array(
+ ],
+ 'limit' => [
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
- ),
- 'continue' => null,
- );
+ ],
+ 'continue' => [
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ],
+ ];
}
- public function getParamDescription() {
- return array(
- 'group' => array(
- 'Limit users to given group name(s)',
- 'Does not include implicit or auto-promoted groups like *, user, or autoconfirmed'
- ),
- 'excludegroup' => array(
- 'Exclude users in given group name(s)',
- 'Does not include implicit or auto-promoted groups like *, user, or autoconfirmed'
- ),
- 'rights' => array(
- 'Limit users to those having given right(s)',
- 'Does not include rights granted by implicit or auto-promoted groups ' .
- 'like *, user, or autoconfirmed'
- ),
- 'excluderights' => array(
- 'Limit users to those not having given right(s)',
- 'Does not include rights granted by implicit or auto-promoted groups ' .
- 'like *, user, or autoconfirmed'
- ),
- 'limit' => 'How many contributors to return',
- 'continue' => 'When more results are available, use this to continue',
- );
- }
-
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(),
- $this->getRequireMaxOneParameterErrorMessages(
- array( 'group', 'excludegroup', 'rights', 'excluderights' )
- )
- );
- }
-
- public function getDescription() {
- return 'Get the list of logged-in contributors and ' .
- 'the count of anonymous contributors to a page.';
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=query&prop=contributors&titles=Main_Page',
- );
+ protected function getExamplesMessages() {
+ return [
+ 'action=query&prop=contributors&titles=Main_Page'
+ => 'apihelp-query+contributors-example-simple',
+ ];
}
public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Properties#contributors_.2F_pc';
+ return 'https://www.mediawiki.org/wiki/API:Contributors';
}
}