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