Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ListConsumersPager
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 7
272
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
72
 getTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 formatRow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getStartBody
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getEndBody
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getIndexField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\OAuth\Frontend\Pagers;
4
5use MediaWiki\Extension\OAuth\Backend\Utils;
6use MediaWiki\Extension\OAuth\Frontend\SpecialPages\SpecialMWOAuthListConsumers;
7use MediaWiki\MediaWikiServices;
8use MediaWiki\Pager\AlphabeticPager;
9use MediaWiki\Title\Title;
10use stdClass;
11
12/**
13 * (c) Aaron Schulz 2013, GPL
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 * http://www.gnu.org/copyleft/gpl.html
29 */
30
31/**
32 * Query to list out consumers
33 */
34class ListConsumersPager extends AlphabeticPager {
35    /** @var SpecialMWOAuthListConsumers */
36    public $mForm;
37
38    /** @var array */
39    public $mConds;
40
41    public function __construct( $form, $conds, $name, $centralUserID, $stage ) {
42        $this->mForm = $form;
43        $this->mConds = $conds;
44
45        $indexField = null;
46        if ( $name !== '' ) {
47            $this->mConds['oarc_name'] = $name;
48            $indexField = 'oarc_id';
49        }
50        if ( $centralUserID !== null ) {
51            $this->mConds['oarc_user_id'] = $centralUserID;
52            $indexField = 'oarc_id';
53        }
54        if ( $stage >= 0 ) {
55            $this->mConds['oarc_stage'] = $stage;
56            if ( !$indexField ) {
57                $indexField = 'oarc_stage_timestamp';
58            }
59        }
60        if ( !$indexField ) {
61            $indexField = 'oarc_id';
62        }
63        $this->mIndexField = $indexField;
64
65        $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
66        if ( !$permissionManager->userHasRight( $this->getUser(), 'mwoauthviewsuppressed' ) ) {
67            $this->mConds['oarc_deleted'] = 0;
68        }
69
70        $this->mDb = Utils::getCentralDB( DB_REPLICA );
71        parent::__construct();
72
73        # Treat 20 as the default limit, since each entry takes up 5 rows.
74        $urlLimit = $this->mRequest->getInt( 'limit' );
75        $this->mLimit = $urlLimit ?: 20;
76    }
77
78    /**
79     * @return Title
80     */
81    public function getTitle() {
82        return $this->mForm->getFullTitle();
83    }
84
85    /**
86     * @param stdClass $row
87     * @return string
88     */
89    public function formatRow( $row ) {
90        return $this->mForm->formatRow( $this->mDb, $row );
91    }
92
93    /**
94     * @return string
95     */
96    public function getStartBody() {
97        if ( $this->getNumRows() ) {
98            return '<ul>';
99        } else {
100            return '';
101        }
102    }
103
104    /**
105     * @return string
106     */
107    public function getEndBody() {
108        if ( $this->getNumRows() ) {
109            return '</ul>';
110        } else {
111            return '';
112        }
113    }
114
115    /**
116     * @return array
117     */
118    public function getQueryInfo() {
119        return [
120            'tables' => [ 'oauth_registered_consumer' ],
121            'fields' => [ '*' ],
122            'conds'  => $this->mConds
123        ];
124    }
125
126    /**
127     * @return string
128     */
129    public function getIndexField() {
130        return $this->mIndexField;
131    }
132}