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 ) {
43 global $wgOut, $wgRequest;
46 $this->outputHeader();
47 $wgOut->setPageTitle( wfMsg( 'ipblocklist' ) );
48 $wgOut->addModuleStyles( 'mediawiki.special' );
50 $par = $wgRequest->getVal( 'ip', $par );
51 $this->target
= trim( $wgRequest->getVal( 'wpTarget', $par ) );
53 $this->options
= $wgRequest->getArray( 'wpOptions', array() );
55 $action = $wgRequest->getText( 'action' );
57 if( $action == 'unblock' ||
$action == 'submit' && $wgRequest->wasPosted() ) {
58 # B/C @since 1.18: Unblock interface is now at Special:Unblock
59 $title = SpecialPage
::getTitleFor( 'Unblock', $this->target
);
60 $wgOut->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',
82 $form = new HTMLForm( $fields, $this->getContext() );
83 $form->setMethod( 'get' );
84 $form->setWrapperLegend( wfMsg( 'ipblocklist-legend' ) );
85 $form->setSubmitText( wfMsg( 'ipblocklist-submit' ) );
88 $form->displayForm( '' );
93 global $wgOut, $wgUser;
95 # Purge expired entries on one in every 10 queries
96 if ( !mt_rand( 0, 10 ) ) {
97 Block
::purgeExpired();
101 # Is the user allowed to see hidden blocks?
102 if ( !$wgUser->isAllowed( 'hideuser' ) ){
103 $conds['ipb_deleted'] = 0;
106 if ( $this->target
!== '' ){
107 list( $target, $type ) = Block
::parseTarget( $this->target
);
111 $conds['ipb_id'] = $target;
115 case Block
::TYPE_RANGE
:
116 list( $start, $end ) = IP
::parseRange( $target );
117 $dbr = wfGetDB( DB_SLAVE
);
118 $conds[] = $dbr->makeList(
120 'ipb_address' => $target,
121 Block
::getRangeCond( $start, $end )
125 $conds['ipb_auto'] = 0;
128 case Block
::TYPE_USER
:
129 $conds['ipb_address'] = (string)$this->target
;
130 $conds['ipb_auto'] = 0;
136 if( in_array( 'userblocks', $this->options
) ) {
137 $conds['ipb_user'] = 0;
139 if( in_array( 'tempblocks', $this->options
) ) {
140 $conds['ipb_expiry'] = 'infinity';
142 if( in_array( 'addressblocks', $this->options
) ) {
143 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
146 # Check for other blocks, i.e. global/tor blocks
147 $otherBlockLink = array();
148 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockLink, $this->target
) );
150 # Show additional header for the local block only when other blocks exists.
151 # Not necessary in a standard installation without such extensions enabled
152 if( count( $otherBlockLink ) ) {
154 Html
::rawElement( 'h2', array(), wfMsg( 'ipblocklist-localblock' ) ) . "\n"
158 $pager = new BlockListPager( $this, $conds );
159 if ( $pager->getNumRows() ) {
161 $pager->getNavigationBar() .
163 $pager->getNavigationBar()
166 } elseif ( $this->target
) {
167 $wgOut->addWikiMsg( 'ipblocklist-no-results' );
170 $wgOut->addWikiMsg( 'ipblocklist-empty' );
173 if( count( $otherBlockLink ) ) {
179 'ipblocklist-otherblocks',
181 count( $otherBlockLink )
186 foreach( $otherBlockLink as $link ) {
187 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
189 $wgOut->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-ipblocklist-otherblocks' ), $list ) . "\n" );
194 class BlockListPager
extends TablePager
{
198 function __construct( $page, $conds ) {
200 $this->conds
= $conds;
201 $this->mDefaultDirection
= true;
202 parent
::__construct();
205 function getFieldNames() {
206 static $headers = null;
208 if ( $headers == array() ) {
210 'ipb_timestamp' => 'blocklist-timestamp',
211 'ipb_target' => 'blocklist-target',
212 'ipb_expiry' => 'blocklist-expiry',
213 'ipb_by' => 'blocklist-by',
214 'ipb_params' => 'blocklist-params',
215 'ipb_reason' => 'blocklist-reason',
217 $headers = array_map( 'wfMsg', $headers );
223 function formatValue( $name, $value ) {
224 global $wgLang, $wgUser;
227 if ( empty( $sk ) ) {
228 $sk = $wgUser->getSkin();
231 'createaccountblock',
234 'blocklist-nousertalk',
239 $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) );
242 $row = $this->mCurrentRow
;
246 case 'ipb_timestamp':
247 $formatted = $wgLang->timeanddate( $value );
251 if( $row->ipb_auto
){
252 $formatted = wfMessage( 'autoblockid', $row->ipb_id
);
254 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
256 case Block
::TYPE_USER
:
258 $formatted = $sk->userLink( $target->getId(), $target );
259 $formatted .= $sk->userToolLinks(
263 Linker
::TOOL_LINKS_NOBLOCK
266 case Block
::TYPE_RANGE
:
267 $formatted = htmlspecialchars( $target );
273 $formatted = $wgLang->formatExpiry( $value );
274 if( $wgUser->isAllowed( 'block' ) ){
275 if( $row->ipb_auto
){
276 $links[] = $sk->linkKnown(
277 SpecialPage
::getTitleFor( 'Unblock' ),
280 array( 'wpTarget' => "#{$row->ipb_id}" )
283 $links[] = $sk->linkKnown(
284 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
287 $links[] = $sk->linkKnown(
288 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
289 $msg['change-blocklink']
292 $formatted .= ' ' . Html
::rawElement(
294 array( 'class' => 'mw-blocklist-actions' ),
295 wfMsg( 'parentheses', $wgLang->pipeList( $links ) )
301 $user = User
::newFromId( $value );
302 if( $user instanceof User
){
303 $formatted = $sk->userLink( $user->getId(), $user->getName() );
304 $formatted .= $sk->userToolLinks( $user->getId(), $user->getName() );
309 $formatted = $sk->commentBlock( $value );
313 $properties = array();
314 if ( $row->ipb_anon_only
) {
315 $properties[] = $msg['anononlyblock'];
317 if ( $row->ipb_create_account
) {
318 $properties[] = $msg['createaccountblock'];
320 if ( !$row->ipb_enable_autoblock
) {
321 $properties[] = $msg['noautoblockblock'];
324 if ( $row->ipb_block_email
) {
325 $properties[] = $msg['emailblock'];
328 if ( !$row->ipb_allow_usertalk
) {
329 $properties[] = $msg['blocklist-nousertalk'];
332 $formatted = $wgLang->commaList( $properties );
336 $formatted = "Unable to format $name";
343 function getQueryInfo() {
345 'tables' => array( 'ipblocks' ),
354 'ipb_create_account',
355 'ipb_enable_autoblock',
361 'ipb_allow_usertalk',
363 'conds' => $this->conds
,
367 # Is the user allowed to see hidden blocks?
368 if ( !$wgUser->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 ) {
391 function getTitle() {
392 return $this->page
->getTitle();