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 class BlockListPager
extends TablePager
{
31 * @param SpecialPage $page
34 function __construct( $page, $conds ) {
36 $this->conds
= $conds;
37 $this->mDefaultDirection
= IndexPager
::DIR_DESCENDING
;
38 parent
::__construct( $page->getContext() );
41 function getFieldNames() {
42 static $headers = null;
44 if ( $headers === null ) {
46 'ipb_timestamp' => 'blocklist-timestamp',
47 'ipb_target' => 'blocklist-target',
48 'ipb_expiry' => 'blocklist-expiry',
49 'ipb_by' => 'blocklist-by',
50 'ipb_params' => 'blocklist-params',
51 'ipb_reason' => 'blocklist-reason',
53 foreach ( $headers as $key => $val ) {
54 $headers[$key] = $this->msg( $val )->text();
61 function formatValue( $name, $value ) {
63 if ( $msg === null ) {
69 'blocklist-nousertalk',
74 foreach ( $keys as $key ) {
75 $msg[$key] = $this->msg( $key )->escaped();
79 /** @var $row object */
80 $row = $this->mCurrentRow
;
82 $language = $this->getLanguage();
88 $formatted = htmlspecialchars( $language->userTimeAndDate( $value, $this->getUser() ) );
92 if ( $row->ipb_auto
) {
93 $formatted = $this->msg( 'autoblockid', $row->ipb_id
)->parse();
95 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
97 case Block
::TYPE_USER
:
99 $formatted = Linker
::userLink( $target->getId(), $target );
100 $formatted .= Linker
::userToolLinks(
104 Linker
::TOOL_LINKS_NOBLOCK
107 case Block
::TYPE_RANGE
:
108 $formatted = htmlspecialchars( $target );
114 $formatted = htmlspecialchars( $language->formatExpiry(
116 /* User preference timezone */true
118 if ( $this->getUser()->isAllowed( 'block' ) ) {
119 if ( $row->ipb_auto
) {
120 $links[] = Linker
::linkKnown(
121 SpecialPage
::getTitleFor( 'Unblock' ),
124 [ 'wpTarget' => "#{$row->ipb_id}" ]
127 $links[] = Linker
::linkKnown(
128 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
131 $links[] = Linker
::linkKnown(
132 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
133 $msg['change-blocklink']
136 $formatted .= ' ' . Html
::rawElement(
138 [ 'class' => 'mw-blocklist-actions' ],
139 $this->msg( 'parentheses' )->rawParams(
140 $language->pipeList( $links ) )->escaped()
143 if ( $value !== 'infinity' ) {
144 $timestamp = new MWTimestamp( $value );
145 $formatted .= '<br />' . $this->msg(
146 'ipb-blocklist-duration-left',
147 $language->formatDuration(
148 $timestamp->getTimestamp() - time(),
162 if ( isset( $row->by_user_name
) ) {
163 $formatted = Linker
::userLink( $value, $row->by_user_name
);
164 $formatted .= Linker
::userToolLinks( $value, $row->by_user_name
);
166 $formatted = htmlspecialchars( $row->ipb_by_text
); // foreign user?
171 $formatted = Linker
::formatComment( $value );
176 if ( $row->ipb_anon_only
) {
177 $properties[] = $msg['anononlyblock'];
179 if ( $row->ipb_create_account
) {
180 $properties[] = $msg['createaccountblock'];
182 if ( $row->ipb_user
&& !$row->ipb_enable_autoblock
) {
183 $properties[] = $msg['noautoblockblock'];
186 if ( $row->ipb_block_email
) {
187 $properties[] = $msg['emailblock'];
190 if ( !$row->ipb_allow_usertalk
) {
191 $properties[] = $msg['blocklist-nousertalk'];
194 $formatted = $language->commaList( $properties );
198 $formatted = "Unable to format $name";
205 function getQueryInfo() {
207 'tables' => [ 'ipblocks', 'user' ],
214 'by_user_name' => 'user_name',
219 'ipb_create_account',
220 'ipb_enable_autoblock',
226 'ipb_allow_usertalk',
228 'conds' => $this->conds
,
229 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id = ipb_by' ] ]
232 # Filter out any expired blocks
233 $db = $this->getDatabase();
234 $info['conds'][] = 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() );
236 # Is the user allowed to see hidden blocks?
237 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
238 $info['conds']['ipb_deleted'] = 0;
244 protected function getTableClass() {
245 return parent
::getTableClass() . ' mw-blocklist';
248 function getIndexField() {
249 return 'ipb_timestamp';
252 function getDefaultSort() {
253 return 'ipb_timestamp';
256 function isFieldSortable( $name ) {
261 * Do a LinkBatch query to minimise database load when generating all these links
262 * @param ResultWrapper $result
264 function preprocessResults( $result ) {
265 # Do a link batch query
267 $lb->setCaller( __METHOD__
);
269 foreach ( $result as $row ) {
270 $lb->add( NS_USER
, $row->ipb_address
);
271 $lb->add( NS_USER_TALK
, $row->ipb_address
);
273 if ( isset( $row->by_user_name
) ) {
274 $lb->add( NS_USER
, $row->by_user_name
);
275 $lb->add( NS_USER_TALK
, $row->by_user_name
);