f5a07642bf2aadcdfd4f6492e69b951c435e5af5
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( $this->msg( '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',
71 'default' => $this->target
,
74 'type' => 'multiselect',
76 wfMsg( 'blocklist-userblocks' ) => 'userblocks',
77 wfMsg( 'blocklist-tempblocks' ) => 'tempblocks',
78 wfMsg( 'blocklist-addressblocks' ) => 'addressblocks',
79 wfMsg( 'blocklist-rangeblocks' ) => 'rangeblocks',
84 $form = new HTMLForm( $fields, $this->getContext() );
85 $form->setMethod( 'get' );
86 $form->setWrapperLegend( wfMsg( 'ipblocklist-legend' ) );
87 $form->setSubmitText( wfMsg( 'ipblocklist-submit' ) );
90 $form->displayForm( '' );
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 ( !$this->getUser()->isAllowed( 'hideuser' ) ){
103 $conds['ipb_deleted'] = 0;
106 if ( $this->target
!== '' ){
107 list( $target, $type ) = Block
::parseTarget( $this->target
);
111 case Block
::TYPE_AUTO
:
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 $out = $this->getOutput();
156 # Show additional header for the local block only when other blocks exists.
157 # Not necessary in a standard installation without such extensions enabled
158 if( count( $otherBlockLink ) ) {
160 Html
::rawElement( 'h2', array(), wfMsg( 'ipblocklist-localblock' ) ) . "\n"
164 $pager = new BlockListPager( $this, $conds );
165 if ( $pager->getNumRows() ) {
167 $pager->getNavigationBar() .
169 $pager->getNavigationBar()
172 } elseif ( $this->target
) {
173 $out->addWikiMsg( 'ipblocklist-no-results' );
176 $out->addWikiMsg( 'ipblocklist-empty' );
179 if( count( $otherBlockLink ) ) {
185 'ipblocklist-otherblocks',
187 count( $otherBlockLink )
192 foreach( $otherBlockLink as $link ) {
193 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
195 $out->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-ipblocklist-otherblocks' ), $list ) . "\n" );
200 class BlockListPager
extends TablePager
{
205 * @param $page SpecialPage
206 * @param $conds Array
208 function __construct( $page, $conds ) {
210 $this->conds
= $conds;
211 $this->mDefaultDirection
= true;
212 parent
::__construct( $page->getContext() );
215 function getFieldNames() {
216 static $headers = null;
218 if ( $headers == array() ) {
220 'ipb_timestamp' => 'blocklist-timestamp',
221 'ipb_target' => 'blocklist-target',
222 'ipb_expiry' => 'blocklist-expiry',
223 'ipb_by' => 'blocklist-by',
224 'ipb_params' => 'blocklist-params',
225 'ipb_reason' => 'blocklist-reason',
227 $headers = array_map( 'wfMsg', $headers );
233 function formatValue( $name, $value ) {
235 if ( $msg === null ) {
238 'createaccountblock',
241 'blocklist-nousertalk',
246 $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) );
249 /** @var $row object */
250 $row = $this->mCurrentRow
;
255 case 'ipb_timestamp':
256 $formatted = $this->getLanguage()->timeanddate( $value, /* User preference timezone */ true );
260 if( $row->ipb_auto
){
261 $formatted = wfMessage( 'autoblockid', $row->ipb_id
)->parse();
263 list( $target, $type ) = Block
::parseTarget( $row->ipb_address
);
265 case Block
::TYPE_USER
:
267 $formatted = Linker
::userLink( $target->getId(), $target );
268 $formatted .= Linker
::userToolLinks(
272 Linker
::TOOL_LINKS_NOBLOCK
275 case Block
::TYPE_RANGE
:
276 $formatted = htmlspecialchars( $target );
282 $formatted = $this->getLanguage()->formatExpiry( $value, /* User preference timezone */ true );
283 if( $this->getUser()->isAllowed( 'block' ) ){
284 if( $row->ipb_auto
){
285 $links[] = Linker
::linkKnown(
286 SpecialPage
::getTitleFor( 'Unblock' ),
289 array( 'wpTarget' => "#{$row->ipb_id}" )
292 $links[] = Linker
::linkKnown(
293 SpecialPage
::getTitleFor( 'Unblock', $row->ipb_address
),
296 $links[] = Linker
::linkKnown(
297 SpecialPage
::getTitleFor( 'Block', $row->ipb_address
),
298 $msg['change-blocklink']
301 $formatted .= ' ' . Html
::rawElement(
303 array( 'class' => 'mw-blocklist-actions' ),
304 wfMsg( 'parentheses', $this->getLanguage()->pipeList( $links ) )
310 if ( isset( $row->by_user_name
) ) {
311 $formatted = Linker
::userLink( $value, $row->by_user_name
);
312 $formatted .= Linker
::userToolLinks( $value, $row->by_user_name
);
314 $formatted = htmlspecialchars( $row->ipb_by_text
); // foreign user?
319 $formatted = Linker
::commentBlock( $value );
323 $properties = array();
324 if ( $row->ipb_anon_only
) {
325 $properties[] = $msg['anononlyblock'];
327 if ( $row->ipb_create_account
) {
328 $properties[] = $msg['createaccountblock'];
330 if ( $row->ipb_user
&& !$row->ipb_enable_autoblock
) {
331 $properties[] = $msg['noautoblockblock'];
334 if ( $row->ipb_block_email
) {
335 $properties[] = $msg['emailblock'];
338 if ( !$row->ipb_allow_usertalk
) {
339 $properties[] = $msg['blocklist-nousertalk'];
342 $formatted = $this->getLanguage()->commaList( $properties );
346 $formatted = "Unable to format $name";
353 function getQueryInfo() {
355 'tables' => array( 'ipblocks', 'user' ),
362 'user_name AS by_user_name',
367 'ipb_create_account',
368 'ipb_enable_autoblock',
374 'ipb_allow_usertalk',
376 'conds' => $this->conds
,
377 'join_conds' => array( 'user' => array( 'LEFT JOIN', 'user_id = ipb_by' ) )
380 # Is the user allowed to see hidden blocks?
381 if ( !$this->getUser()->isAllowed( 'hideuser' ) ){
382 $info['conds']['ipb_deleted'] = 0;
388 public function getTableClass(){
389 return 'TablePager mw-blocklist';
392 function getIndexField() {
393 return 'ipb_timestamp';
396 function getDefaultSort() {
397 return 'ipb_timestamp';
400 function isFieldSortable( $name ) {
405 * Do a LinkBatch query to minimise database load when generating all these links
408 function preprocessResults( $result ){
409 wfProfileIn( __METHOD__
);
410 # Do a link batch query
412 $lb->setCaller( __METHOD__
);
416 foreach ( $result as $row ) {
417 $userids[] = $row->ipb_by
;
419 # Usernames and titles are in fact related by a simple substitution of space -> underscore
420 # The last few lines of Title::secureAndSplit() tell the story.
421 $name = str_replace( ' ', '_', $row->ipb_address
);
422 $lb->add( NS_USER
, $name );
423 $lb->add( NS_USER_TALK
, $name );
426 $ua = UserArray
::newFromIDs( $userids );
427 foreach( $ua as $user ){
428 $name = str_replace( ' ', '_', $user->getName() );
429 $lb->add( NS_USER
, $name );
430 $lb->add( NS_USER_TALK
, $name );
434 wfProfileOut( __METHOD__
);