3 * Implements Special:BlockList
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page that lists existing blocks
27 * @ingroup SpecialPage
29 class SpecialBlockList
extends SpecialPage
{
31 protected $target, $options;
33 function __construct() {
34 parent
::__construct( 'BlockList' );
38 * Main execution point
40 * @param $par String title fragment
42 public function execute( $par ) {
44 $this->outputHeader();
45 $out = $this->getOutput();
46 $out->setPageTitle( wfMsg( 'ipblocklist' ) );
47 $out->addModuleStyles( 'mediawiki.special' );
49 $request = $this->getRequest();
50 $par = $request->getVal( 'ip', $par );
51 $this->target
= trim( $request->getVal( 'wpTarget', $par ) );
53 $this->options
= $request->getArray( 'wpOptions', array() );
55 $action = $request->getText( 'action' );
57 if( $action == 'unblock' ||
$action == 'submit' && $request->wasPosted() ) {
58 # B/C @since 1.18: Unblock interface is now at Special:Unblock
59 $title = SpecialPage
::getTitleFor( 'Unblock', $this->target
);
60 $out->redirect( $title->getFullUrl() );
64 # Just show the block list
68 'label-message' => 'ipadressorusername',
73 'type' => 'multiselect',
75 wfMsg( 'blocklist-userblocks' ) => 'userblocks',
76 wfMsg( 'blocklist-tempblocks' ) => 'tempblocks',
77 wfMsg( 'blocklist-addressblocks' ) => 'addressblocks',
78 wfMsg( 'blocklist-rangeblocks' ) => 'rangeblocks',
83 $form = new HTMLForm( $fields, $this->getContext() );
84 $form->setMethod( 'get' );
85 $form->setWrapperLegend( wfMsg( 'ipblocklist-legend' ) );
86 $form->setSubmitText( wfMsg( 'ipblocklist-submit' ) );
89 $form->displayForm( '' );
94 # Purge expired entries on one in every 10 queries
95 if ( !mt_rand( 0, 10 ) ) {
96 Block
::purgeExpired();
100 # Is the user allowed to see hidden blocks?
101 if ( !$this->getUser()->isAllowed( 'hideuser' ) ){
102 $conds['ipb_deleted'] = 0;
105 if ( $this->target
!== '' ){
106 list( $target, $type ) = Block
::parseTarget( $this->target
);
110 $conds['ipb_id'] = $target;
114 case Block
::TYPE_RANGE
:
115 list( $start, $end ) = IP
::parseRange( $target );
116 $dbr = wfGetDB( DB_SLAVE
);
117 $conds[] = $dbr->makeList(
119 'ipb_address' => $target,
120 Block
::getRangeCond( $start, $end )
124 $conds['ipb_auto'] = 0;
127 case Block
::TYPE_USER
:
128 $conds['ipb_address'] = (string)$this->target
;
129 $conds['ipb_auto'] = 0;
135 if( in_array( 'userblocks', $this->options
) ) {
136 $conds['ipb_user'] = 0;
138 if( in_array( 'tempblocks', $this->options
) ) {
139 $conds['ipb_expiry'] = 'infinity';
141 if( in_array( 'addressblocks', $this->options
) ) {
142 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
144 if( in_array( 'rangeblocks', $this->options
) ) {
145 $conds[] = "ipb_range_end = ipb_range_start";
148 # Check for other blocks, i.e. global/tor blocks
149 $otherBlockLink = array();
150 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockLink, $this->target
) );
152 $out = $this->getOutput();
154 # Show additional header for the local block only when other blocks exists.
155 # Not necessary in a standard installation without such extensions enabled
156 if( count( $otherBlockLink ) ) {
158 Html
::rawElement( 'h2', array(), wfMsg( 'ipblocklist-localblock' ) ) . "\n"
162 $pager = new BlockListPager( $this, $conds );
163 if ( $pager->getNumRows() ) {
165 $pager->getNavigationBar() .
167 $pager->getNavigationBar()
170 } elseif ( $this->target
) {
171 $out->addWikiMsg( 'ipblocklist-no-results' );
174 $out->addWikiMsg( 'ipblocklist-empty' );
177 if( count( $otherBlockLink ) ) {
183 'ipblocklist-otherblocks',
185 count( $otherBlockLink )
190 foreach( $otherBlockLink as $link ) {
191 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
193 $out->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-ipblocklist-otherblocks' ), $list ) . "\n" );
198 class BlockListPager
extends TablePager
{
202 function __construct( $page, $conds ) {
204 $this->conds
= $conds;
205 $this->mDefaultDirection
= true;
206 parent
::__construct( $page->getContext() );
209 function getFieldNames() {
210 static $headers = null;
212 if ( $headers == array() ) {
214 'ipb_timestamp' => 'blocklist-timestamp',
215 'ipb_target' => 'blocklist-target',
216 'ipb_expiry' => 'blocklist-expiry',
217 'ipb_by' => 'blocklist-by',
218 'ipb_params' => 'blocklist-params',
219 'ipb_reason' => 'blocklist-reason',
221 $headers = array_map( 'wfMsg', $headers );
227 function formatValue( $name, $value ) {
229 if ( $msg === null ) {
232 'createaccountblock',
235 'blocklist-nousertalk',
240 $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) );
243 $row = $this->mCurrentRow
;
247 case 'ipb_timestamp':
248 $formatted = $this->getLang()->timeanddate( $value );
252 if( $row->ipb_auto
){
253 $formatted = wfMessage( 'autoblockid', $row->ipb_id
)->parse();
255 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
257 case Block
::TYPE_USER
:
259 $formatted = Linker
::userLink( $target->getId(), $target );
260 $formatted .= Linker
::userToolLinks(
264 Linker
::TOOL_LINKS_NOBLOCK
267 case Block
::TYPE_RANGE
:
268 $formatted = htmlspecialchars( $target );
274 $formatted = $this->getLang()->formatExpiry( $value );
275 if( $this->getUser()->isAllowed( 'block' ) ){
276 if( $row->ipb_auto
){
277 $links[] = Linker
::linkKnown(
278 SpecialPage
::getTitleFor( 'Unblock' ),
281 array( 'wpTarget' => "#{$row->ipb_id}" )
284 $links[] = Linker
::linkKnown(
285 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
288 $links[] = Linker
::linkKnown(
289 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
290 $msg['change-blocklink']
293 $formatted .= ' ' . Html
::rawElement(
295 array( 'class' => 'mw-blocklist-actions' ),
296 wfMsg( 'parentheses', $this->getLang()->pipeList( $links ) )
302 $user = User
::newFromId( $value );
303 if( $user instanceof User
){
304 $formatted = Linker
::userLink( $user->getId(), $user->getName() );
305 $formatted .= Linker
::userToolLinks( $user->getId(), $user->getName() );
310 $formatted = Linker
::commentBlock( $value );
314 $properties = array();
315 if ( $row->ipb_anon_only
) {
316 $properties[] = $msg['anononlyblock'];
318 if ( $row->ipb_create_account
) {
319 $properties[] = $msg['createaccountblock'];
321 if ( !$row->ipb_enable_autoblock
) {
322 $properties[] = $msg['noautoblockblock'];
325 if ( $row->ipb_block_email
) {
326 $properties[] = $msg['emailblock'];
329 if ( !$row->ipb_allow_usertalk
) {
330 $properties[] = $msg['blocklist-nousertalk'];
333 $formatted = $this->getLang()->commaList( $properties );
337 $formatted = "Unable to format $name";
344 function getQueryInfo() {
346 'tables' => array( 'ipblocks' ),
355 'ipb_create_account',
356 'ipb_enable_autoblock',
362 'ipb_allow_usertalk',
364 'conds' => $this->conds
,
367 # Is the user allowed to see hidden blocks?
368 if ( !$this->getUser()->isAllowed( 'hideuser' ) ){
369 $conds['ipb_deleted'] = 0;
375 public function getTableClass(){
376 return 'TablePager mw-blocklist';
379 function getIndexField() {
380 return 'ipb_timestamp';
383 function getDefaultSort() {
384 return 'ipb_timestamp';
387 function isFieldSortable( $name ) {