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',
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 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";
146 if( in_array( 'rangeblocks', $this->options
) ) {
147 $conds[] = "ipb_range_end = ipb_range_start";
150 # Check for other blocks, i.e. global/tor blocks
151 $otherBlockLink = array();
152 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockLink, $this->target
) );
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 $wgOut->addWikiMsg( 'ipblocklist-no-results' );
174 $wgOut->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 $wgOut->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();
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 ) {
228 global $wgLang, $wgUser;
231 if ( empty( $sk ) ) {
232 $sk = $this->getSkin();
235 'createaccountblock',
238 'blocklist-nousertalk',
243 $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) );
246 $row = $this->mCurrentRow
;
250 case 'ipb_timestamp':
251 $formatted = $wgLang->timeanddate( $value );
255 if( $row->ipb_auto
){
256 $formatted = wfMessage( 'autoblockid', $row->ipb_id
)->parse();
258 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
260 case Block
::TYPE_USER
:
262 $formatted = $sk->userLink( $target->getId(), $target );
263 $formatted .= $sk->userToolLinks(
267 Linker
::TOOL_LINKS_NOBLOCK
270 case Block
::TYPE_RANGE
:
271 $formatted = htmlspecialchars( $target );
277 $formatted = $wgLang->formatExpiry( $value );
278 if( $wgUser->isAllowed( 'block' ) ){
279 if( $row->ipb_auto
){
280 $links[] = $sk->linkKnown(
281 SpecialPage
::getTitleFor( 'Unblock' ),
284 array( 'wpTarget' => "#{$row->ipb_id}" )
287 $links[] = $sk->linkKnown(
288 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
291 $links[] = $sk->linkKnown(
292 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
293 $msg['change-blocklink']
296 $formatted .= ' ' . Html
::rawElement(
298 array( 'class' => 'mw-blocklist-actions' ),
299 wfMsg( 'parentheses', $wgLang->pipeList( $links ) )
305 $user = User
::newFromId( $value );
306 if( $user instanceof User
){
307 $formatted = $sk->userLink( $user->getId(), $user->getName() );
308 $formatted .= $sk->userToolLinks( $user->getId(), $user->getName() );
313 $formatted = $sk->commentBlock( $value );
317 $properties = array();
318 if ( $row->ipb_anon_only
) {
319 $properties[] = $msg['anononlyblock'];
321 if ( $row->ipb_create_account
) {
322 $properties[] = $msg['createaccountblock'];
324 if ( !$row->ipb_enable_autoblock
) {
325 $properties[] = $msg['noautoblockblock'];
328 if ( $row->ipb_block_email
) {
329 $properties[] = $msg['emailblock'];
332 if ( !$row->ipb_allow_usertalk
) {
333 $properties[] = $msg['blocklist-nousertalk'];
336 $formatted = $wgLang->commaList( $properties );
340 $formatted = "Unable to format $name";
347 function getQueryInfo() {
349 'tables' => array( 'ipblocks' ),
358 'ipb_create_account',
359 'ipb_enable_autoblock',
365 'ipb_allow_usertalk',
367 'conds' => $this->conds
,
371 # Is the user allowed to see hidden blocks?
372 if ( !$wgUser->isAllowed( 'hideuser' ) ){
373 $conds['ipb_deleted'] = 0;
379 public function getTableClass(){
380 return 'TablePager mw-blocklist';
383 function getIndexField() {
384 return 'ipb_timestamp';
387 function getDefaultSort() {
388 return 'ipb_timestamp';
391 function isFieldSortable( $name ) {
395 function getTitle() {
396 return $this->page
->getTitle();