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 case Block
::TYPE_AUTO
:
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";
145 if( in_array( 'rangeblocks', $this->options
) ) {
146 $conds[] = "ipb_range_end = ipb_range_start";
149 # Check for other blocks, i.e. global/tor blocks
150 $otherBlockLink = array();
151 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockLink, $this->target
) );
153 $out = $this->getOutput();
155 # Show additional header for the local block only when other blocks exists.
156 # Not necessary in a standard installation without such extensions enabled
157 if( count( $otherBlockLink ) ) {
159 Html
::rawElement( 'h2', array(), wfMsg( 'ipblocklist-localblock' ) ) . "\n"
163 $pager = new BlockListPager( $this, $conds );
164 if ( $pager->getNumRows() ) {
166 $pager->getNavigationBar() .
168 $pager->getNavigationBar()
171 } elseif ( $this->target
) {
172 $out->addWikiMsg( 'ipblocklist-no-results' );
175 $out->addWikiMsg( 'ipblocklist-empty' );
178 if( count( $otherBlockLink ) ) {
184 'ipblocklist-otherblocks',
186 count( $otherBlockLink )
191 foreach( $otherBlockLink as $link ) {
192 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
194 $out->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-ipblocklist-otherblocks' ), $list ) . "\n" );
199 class BlockListPager
extends TablePager
{
203 function __construct( $page, $conds ) {
205 $this->conds
= $conds;
206 $this->mDefaultDirection
= true;
207 parent
::__construct( $page->getContext() );
210 function getFieldNames() {
211 static $headers = null;
213 if ( $headers == array() ) {
215 'ipb_timestamp' => 'blocklist-timestamp',
216 'ipb_target' => 'blocklist-target',
217 'ipb_expiry' => 'blocklist-expiry',
218 'ipb_by' => 'blocklist-by',
219 'ipb_params' => 'blocklist-params',
220 'ipb_reason' => 'blocklist-reason',
222 $headers = array_map( 'wfMsg', $headers );
228 function formatValue( $name, $value ) {
230 if ( $msg === null ) {
233 'createaccountblock',
236 'blocklist-nousertalk',
241 $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) );
244 $row = $this->mCurrentRow
;
248 case 'ipb_timestamp':
249 $formatted = $this->getLang()->timeanddate( $value, /* User preference timezome */ true );
253 if( $row->ipb_auto
){
254 $formatted = wfMessage( 'autoblockid', $row->ipb_id
)->parse();
256 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
258 case Block
::TYPE_USER
:
260 $formatted = Linker
::userLink( $target->getId(), $target );
261 $formatted .= Linker
::userToolLinks(
265 Linker
::TOOL_LINKS_NOBLOCK
268 case Block
::TYPE_RANGE
:
269 $formatted = htmlspecialchars( $target );
275 $formatted = $this->getLang()->formatExpiry( $value, /* User preference timezome */ true );
276 if( $this->getUser()->isAllowed( 'block' ) ){
277 if( $row->ipb_auto
){
278 $links[] = Linker
::linkKnown(
279 SpecialPage
::getTitleFor( 'Unblock' ),
282 array( 'wpTarget' => "#{$row->ipb_id}" )
285 $links[] = Linker
::linkKnown(
286 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
289 $links[] = Linker
::linkKnown(
290 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
291 $msg['change-blocklink']
294 $formatted .= ' ' . Html
::rawElement(
296 array( 'class' => 'mw-blocklist-actions' ),
297 wfMsg( 'parentheses', $this->getLang()->pipeList( $links ) )
303 $user = User
::newFromId( $value );
304 if( $user instanceof User
){
305 $formatted = Linker
::userLink( $user->getId(), $user->getName() );
306 $formatted .= Linker
::userToolLinks( $user->getId(), $user->getName() );
311 $formatted = Linker
::commentBlock( $value );
315 $properties = array();
316 if ( $row->ipb_anon_only
) {
317 $properties[] = $msg['anononlyblock'];
319 if ( $row->ipb_create_account
) {
320 $properties[] = $msg['createaccountblock'];
322 if ( $row->ipb_user
&& !$row->ipb_enable_autoblock
) {
323 $properties[] = $msg['noautoblockblock'];
326 if ( $row->ipb_block_email
) {
327 $properties[] = $msg['emailblock'];
330 if ( !$row->ipb_allow_usertalk
) {
331 $properties[] = $msg['blocklist-nousertalk'];
334 $formatted = $this->getLang()->commaList( $properties );
338 $formatted = "Unable to format $name";
345 function getQueryInfo() {
347 'tables' => array( 'ipblocks' ),
357 'ipb_create_account',
358 'ipb_enable_autoblock',
364 'ipb_allow_usertalk',
366 'conds' => $this->conds
,
369 # Is the user allowed to see hidden blocks?
370 if ( !$this->getUser()->isAllowed( 'hideuser' ) ){
371 $info['conds']['ipb_deleted'] = 0;
377 public function getTableClass(){
378 return 'TablePager mw-blocklist';
381 function getIndexField() {
382 return 'ipb_timestamp';
385 function getDefaultSort() {
386 return 'ipb_timestamp';
389 function isFieldSortable( $name ) {