3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
25 use MediaWiki\MediaWikiServices
;
27 class BlockListPager
extends TablePager
{
33 * @param SpecialPage $page
36 function __construct( $page, $conds ) {
38 $this->conds
= $conds;
39 $this->mDefaultDirection
= IndexPager
::DIR_DESCENDING
;
40 parent
::__construct( $page->getContext() );
43 function getFieldNames() {
44 static $headers = null;
46 if ( $headers === null ) {
48 'ipb_timestamp' => 'blocklist-timestamp',
49 'ipb_target' => 'blocklist-target',
50 'ipb_expiry' => 'blocklist-expiry',
51 'ipb_by' => 'blocklist-by',
52 'ipb_params' => 'blocklist-params',
53 'ipb_reason' => 'blocklist-reason',
55 foreach ( $headers as $key => $val ) {
56 $headers[$key] = $this->msg( $val )->text();
63 function formatValue( $name, $value ) {
65 if ( $msg === null ) {
71 'blocklist-nousertalk',
76 foreach ( $keys as $key ) {
77 $msg[$key] = $this->msg( $key )->text();
81 /** @var $row object */
82 $row = $this->mCurrentRow
;
84 $language = $this->getLanguage();
88 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
92 $formatted = htmlspecialchars( $language->userTimeAndDate( $value, $this->getUser() ) );
96 if ( $row->ipb_auto
) {
97 $formatted = $this->msg( 'autoblockid', $row->ipb_id
)->parse();
99 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
101 case Block
::TYPE_USER
:
103 $formatted = Linker
::userLink( $target->getId(), $target );
104 $formatted .= Linker
::userToolLinks(
108 Linker
::TOOL_LINKS_NOBLOCK
111 case Block
::TYPE_RANGE
:
112 $formatted = htmlspecialchars( $target );
118 $formatted = htmlspecialchars( $language->formatExpiry(
120 /* User preference timezone */true
122 if ( $this->getUser()->isAllowed( 'block' ) ) {
123 if ( $row->ipb_auto
) {
124 $links[] = $linkRenderer->makeKnownLink(
125 SpecialPage
::getTitleFor( 'Unblock' ),
128 [ 'wpTarget' => "#{$row->ipb_id}" ]
131 $links[] = $linkRenderer->makeKnownLink(
132 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
135 $links[] = $linkRenderer->makeKnownLink(
136 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
137 $msg['change-blocklink']
140 $formatted .= ' ' . Html
::rawElement(
142 [ 'class' => 'mw-blocklist-actions' ],
143 $this->msg( 'parentheses' )->rawParams(
144 $language->pipeList( $links ) )->escaped()
147 if ( $value !== 'infinity' ) {
148 $timestamp = new MWTimestamp( $value );
149 $formatted .= '<br />' . $this->msg(
150 'ipb-blocklist-duration-left',
151 $language->formatDuration(
152 $timestamp->getTimestamp() - time(),
166 if ( isset( $row->by_user_name
) ) {
167 $formatted = Linker
::userLink( $value, $row->by_user_name
);
168 $formatted .= Linker
::userToolLinks( $value, $row->by_user_name
);
170 $formatted = htmlspecialchars( $row->ipb_by_text
); // foreign user?
175 $formatted = Linker
::formatComment( $value );
180 if ( $row->ipb_anon_only
) {
181 $properties[] = htmlspecialchars( $msg['anononlyblock'] );
183 if ( $row->ipb_create_account
) {
184 $properties[] = htmlspecialchars( $msg['createaccountblock'] );
186 if ( $row->ipb_user
&& !$row->ipb_enable_autoblock
) {
187 $properties[] = htmlspecialchars( $msg['noautoblockblock'] );
190 if ( $row->ipb_block_email
) {
191 $properties[] = htmlspecialchars( $msg['emailblock'] );
194 if ( !$row->ipb_allow_usertalk
) {
195 $properties[] = htmlspecialchars( $msg['blocklist-nousertalk'] );
198 $formatted = $language->commaList( $properties );
202 $formatted = "Unable to format $name";
209 function getQueryInfo() {
211 'tables' => [ 'ipblocks', 'user' ],
218 'by_user_name' => 'user_name',
223 'ipb_create_account',
224 'ipb_enable_autoblock',
230 'ipb_allow_usertalk',
232 'conds' => $this->conds
,
233 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id = ipb_by' ] ]
236 # Filter out any expired blocks
237 $db = $this->getDatabase();
238 $info['conds'][] = 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() );
240 # Is the user allowed to see hidden blocks?
241 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
242 $info['conds']['ipb_deleted'] = 0;
248 protected function getTableClass() {
249 return parent
::getTableClass() . ' mw-blocklist';
252 function getIndexField() {
253 return 'ipb_timestamp';
256 function getDefaultSort() {
257 return 'ipb_timestamp';
260 function isFieldSortable( $name ) {
265 * Do a LinkBatch query to minimise database load when generating all these links
266 * @param ResultWrapper $result
268 function preprocessResults( $result ) {
269 # Do a link batch query
271 $lb->setCaller( __METHOD__
);
273 foreach ( $result as $row ) {
274 $lb->add( NS_USER
, $row->ipb_address
);
275 $lb->add( NS_USER_TALK
, $row->ipb_address
);
277 if ( isset( $row->by_user_name
) ) {
278 $lb->add( NS_USER
, $row->by_user_name
);
279 $lb->add( NS_USER_TALK
, $row->by_user_name
);