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
;
26 use Wikimedia\Rdbms\ResultWrapper
;
28 class BlockListPager
extends TablePager
{
34 * @param SpecialPage $page
37 function __construct( $page, $conds ) {
39 $this->conds
= $conds;
40 $this->mDefaultDirection
= IndexPager
::DIR_DESCENDING
;
41 parent
::__construct( $page->getContext() );
44 function getFieldNames() {
45 static $headers = null;
47 if ( $headers === null ) {
49 'ipb_timestamp' => 'blocklist-timestamp',
50 'ipb_target' => 'blocklist-target',
51 'ipb_expiry' => 'blocklist-expiry',
52 'ipb_by' => 'blocklist-by',
53 'ipb_params' => 'blocklist-params',
54 'ipb_reason' => 'blocklist-reason',
56 foreach ( $headers as $key => $val ) {
57 $headers[$key] = $this->msg( $val )->text();
64 function formatValue( $name, $value ) {
66 if ( $msg === null ) {
72 'blocklist-nousertalk',
77 foreach ( $keys as $key ) {
78 $msg[$key] = $this->msg( $key )->text();
82 /** @var $row object */
83 $row = $this->mCurrentRow
;
85 $language = $this->getLanguage();
89 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
93 $formatted = htmlspecialchars( $language->userTimeAndDate( $value, $this->getUser() ) );
97 if ( $row->ipb_auto
) {
98 $formatted = $this->msg( 'autoblockid', $row->ipb_id
)->parse();
100 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
102 case Block
::TYPE_USER
:
104 $formatted = Linker
::userLink( $target->getId(), $target );
105 $formatted .= Linker
::userToolLinks(
109 Linker
::TOOL_LINKS_NOBLOCK
112 case Block
::TYPE_RANGE
:
113 $formatted = htmlspecialchars( $target );
119 $formatted = htmlspecialchars( $language->formatExpiry(
121 /* User preference timezone */true
123 if ( $this->getUser()->isAllowed( 'block' ) ) {
124 if ( $row->ipb_auto
) {
125 $links[] = $linkRenderer->makeKnownLink(
126 SpecialPage
::getTitleFor( 'Unblock' ),
129 [ 'wpTarget' => "#{$row->ipb_id}" ]
132 $links[] = $linkRenderer->makeKnownLink(
133 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
136 $links[] = $linkRenderer->makeKnownLink(
137 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
138 $msg['change-blocklink']
141 $formatted .= ' ' . Html
::rawElement(
143 [ 'class' => 'mw-blocklist-actions' ],
144 $this->msg( 'parentheses' )->rawParams(
145 $language->pipeList( $links ) )->escaped()
148 if ( $value !== 'infinity' ) {
149 $timestamp = new MWTimestamp( $value );
150 $formatted .= '<br />' . $this->msg(
151 'ipb-blocklist-duration-left',
152 $language->formatDuration(
153 $timestamp->getTimestamp() - time(),
167 if ( isset( $row->by_user_name
) ) {
168 $formatted = Linker
::userLink( $value, $row->by_user_name
);
169 $formatted .= Linker
::userToolLinks( $value, $row->by_user_name
);
171 $formatted = htmlspecialchars( $row->ipb_by_text
); // foreign user?
176 $formatted = Linker
::formatComment( $value );
181 if ( $row->ipb_anon_only
) {
182 $properties[] = htmlspecialchars( $msg['anononlyblock'] );
184 if ( $row->ipb_create_account
) {
185 $properties[] = htmlspecialchars( $msg['createaccountblock'] );
187 if ( $row->ipb_user
&& !$row->ipb_enable_autoblock
) {
188 $properties[] = htmlspecialchars( $msg['noautoblockblock'] );
191 if ( $row->ipb_block_email
) {
192 $properties[] = htmlspecialchars( $msg['emailblock'] );
195 if ( !$row->ipb_allow_usertalk
) {
196 $properties[] = htmlspecialchars( $msg['blocklist-nousertalk'] );
199 $formatted = $language->commaList( $properties );
203 $formatted = "Unable to format $name";
210 function getQueryInfo() {
212 'tables' => [ 'ipblocks', 'user' ],
219 'by_user_name' => 'user_name',
224 'ipb_create_account',
225 'ipb_enable_autoblock',
231 'ipb_allow_usertalk',
233 'conds' => $this->conds
,
234 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id = ipb_by' ] ]
237 # Filter out any expired blocks
238 $db = $this->getDatabase();
239 $info['conds'][] = 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() );
241 # Is the user allowed to see hidden blocks?
242 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
243 $info['conds']['ipb_deleted'] = 0;
249 protected function getTableClass() {
250 return parent
::getTableClass() . ' mw-blocklist';
253 function getIndexField() {
254 return 'ipb_timestamp';
257 function getDefaultSort() {
258 return 'ipb_timestamp';
261 function isFieldSortable( $name ) {
266 * Do a LinkBatch query to minimise database load when generating all these links
267 * @param ResultWrapper $result
269 function preprocessResults( $result ) {
270 # Do a link batch query
272 $lb->setCaller( __METHOD__
);
274 foreach ( $result as $row ) {
275 $lb->add( NS_USER
, $row->ipb_address
);
276 $lb->add( NS_USER_TALK
, $row->ipb_address
);
278 if ( isset( $row->by_user_name
) ) {
279 $lb->add( NS_USER
, $row->by_user_name
);
280 $lb->add( NS_USER_TALK
, $row->by_user_name
);