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 );
83 $form->setTitle( $this->getTitle() );
84 $form->setMethod( 'get' );
85 $form->setWrapperLegend( wfMsg( 'ipblocklist-legend' ) );
86 $form->setSubmitText( wfMsg( 'ipblocklist-submit' ) );
89 $form->displayForm( '' );
94 global $wgOut, $wgUser;
96 # Purge expired entries on one in every 10 queries
97 if ( !mt_rand( 0, 10 ) ) {
98 Block
::purgeExpired();
102 # Is the user allowed to see hidden blocks?
103 if ( !$wgUser->isAllowed( 'hideuser' ) ){
104 $conds['ipb_deleted'] = 0;
107 if ( $this->target
!== '' ){
108 list( $target, $type ) = Block
::parseTarget( $this->target
);
112 $conds['ipb_id'] = $target;
116 case Block
::TYPE_RANGE
:
117 list( $start, $end ) = IP
::parseRange( $target );
118 $dbr = wfGetDB( DB_SLAVE
);
119 $conds[] = $dbr->makeList(
121 'ipb_address' => $target,
122 Block
::getRangeCond( $start, $end )
126 $conds['ipb_auto'] = 0;
129 case Block
::TYPE_USER
:
130 $conds['ipb_address'] = (string)$this->target
;
131 $conds['ipb_auto'] = 0;
137 if( in_array( 'userblocks', $this->options
) ) {
138 $conds['ipb_user'] = 0;
140 if( in_array( 'tempblocks', $this->options
) ) {
141 $conds['ipb_expiry'] = 'infinity';
143 if( in_array( 'addressblocks', $this->options
) ) {
144 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
147 # Check for other blocks, i.e. global/tor blocks
148 $otherBlockLink = array();
149 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockLink, $this->target
) );
151 # Show additional header for the local block only when other blocks exists.
152 # Not necessary in a standard installation without such extensions enabled
153 if( count( $otherBlockLink ) ) {
155 Html
::rawElement( 'h2', array(), wfMsg( 'ipblocklist-localblock' ) ) . "\n"
159 $pager = new BlockListPager( $this, $conds );
160 if ( $pager->getNumRows() ) {
162 $pager->getNavigationBar() .
164 $pager->getNavigationBar()
167 } elseif ( $this->target
) {
168 $wgOut->addWikiMsg( 'ipblocklist-no-results' );
171 $wgOut->addWikiMsg( 'ipblocklist-empty' );
174 if( count( $otherBlockLink ) ) {
180 'ipblocklist-otherblocks',
182 count( $otherBlockLink )
187 foreach( $otherBlockLink as $link ) {
188 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
190 $wgOut->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-ipblocklist-otherblocks' ), $list ) . "\n" );
195 class BlockListPager
extends TablePager
{
199 function __construct( $page, $conds ) {
201 $this->conds
= $conds;
202 $this->mDefaultDirection
= true;
203 parent
::__construct();
206 function getFieldNames() {
207 static $headers = null;
209 if ( $headers == array() ) {
211 'ipb_timestamp' => 'blocklist-timestamp',
212 'ipb_target' => 'blocklist-target',
213 'ipb_expiry' => 'blocklist-expiry',
214 'ipb_by' => 'blocklist-by',
215 'ipb_params' => 'blocklist-params',
216 'ipb_reason' => 'blocklist-reason',
218 $headers = array_map( 'wfMsg', $headers );
224 function formatValue( $name, $value ) {
225 global $wgLang, $wgUser;
228 if ( empty( $sk ) ) {
229 $sk = $wgUser->getSkin();
232 'createaccountblock',
235 'blocklist-nousertalk',
240 $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) );
243 $row = $this->mCurrentRow
;
247 case 'ipb_timestamp':
248 $formatted = $wgLang->timeanddate( $value );
252 if( $row->ipb_auto
){
253 $formatted = wfMessage( 'autoblockid', $row->ipb_id
);
255 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
257 case Block
::TYPE_USER
:
259 $formatted = $sk->userLink( $target->getId(), $target );
260 $formatted .= $sk->userToolLinks(
264 Linker
::TOOL_LINKS_NOBLOCK
267 case Block
::TYPE_RANGE
:
268 $formatted = htmlspecialchars( $target );
274 $formatted = $wgLang->formatExpiry( $value );
275 if( $wgUser->isAllowed( 'block' ) ){
276 if( $row->ipb_auto
){
277 $links[] = $sk->linkKnown(
278 SpecialPage
::getTitleFor( 'Unblock' ),
281 array( 'wpTarget' => "#{$row->ipb_id}" )
284 $links[] = $sk->linkKnown(
285 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
288 $links[] = $sk->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', $wgLang->pipeList( $links ) )
302 $user = User
::newFromId( $value );
303 if( $user instanceof User
){
304 $formatted = $sk->userLink( $user->getId(), $user->getName() );
305 $formatted .= $sk->userToolLinks( $user->getId(), $user->getName() );
310 $formatted = $sk->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 = $wgLang->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
,
368 # Is the user allowed to see hidden blocks?
369 if ( !$wgUser->isAllowed( 'hideuser' ) ){
370 $conds['ipb_deleted'] = 0;
376 public function getTableClass(){
377 return 'TablePager mw-blocklist';
380 function getIndexField() {
381 return 'ipb_timestamp';
384 function getDefaultSort() {
385 return 'ipb_timestamp';
388 function isFieldSortable( $name ) {
392 function getTitle() {
393 return $this->page
->getTitle();