r56160 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56159‎ | r56160 | r56161 >
Date:00:09, 11 September 2009
Author:aaron
Status:resolved
Tags:
Comment:
Refactored block notice code
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -364,7 +364,6 @@
365365 wfRestoreWarnings();
366366
367367 $logs = SpecialPage::getTitleFor( 'Log' );
368 - $blocklist = SpecialPage::getTitleFor( 'Ipblocklist' );
369368 $s = '<div id="checkuserresults"><ul>';
370369 foreach( $ips_edits as $ip => $edits ) {
371370 $s .= '<li>';
@@ -397,25 +396,7 @@
398397 }
399398
400399 # If this IP is blocked, give a link to the block log
401 - $block = new Block();
402 - $block->fromMaster( false ); // use slaves
403 - if( $block->load( $ip, 0 ) ) {
404 - if( IP::isIPAddress($block->mAddress) && strpos($block->mAddress,'/') ) {
405 - $userpage = Title::makeTitle( NS_USER, $block->mAddress );
406 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
407 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
408 - $s .= ' <strong>(' . $blocklog . ' - ' . $block->mAddress . ')</strong>';
409 - } else if( $block->mAuto ) {
410 - $blocklog = $this->sk->makeKnownLinkObj( $blocklist, wfMsgHtml('checkuser-blocked'),
411 - 'ip=' . urlencode( "#$block->mId" ) );
412 - $s .= ' <strong>(' . $blocklog . ')</strong>';
413 - } else {
414 - $userpage = Title::makeTitle( NS_USER, $ip );
415 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
416 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
417 - $s .= ' <strong>(' . $blocklog . ')</strong>';
418 - }
419 - }
 400+ $s.= $this->getIPBlockInfo( $ip );
420401 $s .= "<div style='margin-left:5%'>";
421402 $s .= "<small>" . wfMsgExt('checkuser-toollinks',array('parseinline'),urlencode($ip)) . "</small>";
422403 $s .= "</div>";
@@ -426,6 +407,31 @@
427408 $wgOut->addHTML( $s );
428409 $dbr->freeResult( $ret );
429410 }
 411+
 412+ protected function getIPBlockInfo( $ip ) {
 413+ static $blocklist;
 414+ $blocklist = SpecialPage::getTitleFor( 'Ipblocklist' );
 415+ $block = new Block();
 416+ $block->fromMaster( false ); // use slaves
 417+ if( $block->load( $ip, 0 ) ) {
 418+ if( IP::isIPAddress($block->mAddress) && strpos($block->mAddress,'/') ) {
 419+ $userpage = Title::makeTitle( NS_USER, $block->mAddress );
 420+ $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
 421+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 422+ return ' <strong>(' . $blocklog . ' - ' . $block->mAddress . ')</strong>';
 423+ } else if( $block->mAuto ) {
 424+ $blocklog = $this->sk->makeKnownLinkObj( $blocklist, wfMsgHtml('checkuser-blocked'),
 425+ 'ip=' . urlencode( "#$block->mId" ) );
 426+ return ' <strong>(' . $blocklog . ')</strong>';
 427+ } else {
 428+ $userpage = Title::makeTitle( NS_USER, $ip );
 429+ $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
 430+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 431+ return ' <strong>(' . $blocklog . ')</strong>';
 432+ }
 433+ }
 434+ return '';
 435+ }
430436
431437 /**
432438 * @param string $ip
@@ -824,9 +830,6 @@
825831 }
826832 $dbr->freeResult( $ret );
827833
828 - $logs = SpecialPage::getTitleFor( 'Log' );
829 - $blocklist = SpecialPage::getTitleFor( 'Ipblocklist' );
830 -
831834 $action = $this->getTitle()->escapeLocalUrl( 'action=block' );
832835 $s = "<form name='checkuserblock' id='checkuserblock' action=\"$action\" method='post'>";
833836 $s .= '<div id="checkuserresults"><ul>';
@@ -850,37 +853,8 @@
851854 # Total edit count
852855 $s .= ' [<strong>' . $count . '</strong>]<br />';
853856 # Check if this user or IP is blocked. If so, give a link to the block log...
854 - $block = new Block();
855 - $block->fromMaster( false ); // use slaves
856857 $ip = IP::isIPAddress( $name ) ? $name : '';
857 - $flags = array();
858 - if( $block->load( $ip, $users_ids[$name] ) ) {
859 - // Range blocked?
860 - if( IP::isIPAddress($block->mAddress) && strpos($block->mAddress,'/') ) {
861 - $userpage = Title::makeTitle( NS_USER, $block->mAddress );
862 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
863 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
864 - $flags[] = '<strong>(' . $blocklog . ' - ' . $block->mAddress . ')</strong>';
865 - // Auto blocked?
866 - } else if( $block->mAuto ) {
867 - $blocklog = $this->sk->makeKnownLinkObj( $blocklist,
868 - wfMsgHtml('checkuser-blocked'), 'ip=' . urlencode( "#{$block->mId}" ) );
869 - $flags[] = '<strong>(' . $blocklog . ')</strong>';
870 - } else {
871 - $userpage = Title::makeTitle( NS_USER, $name );
872 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
873 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
874 - $flags[] = '<strong>(' . $blocklog . ')</strong>';
875 - }
876 - // IP that is blocked on all wikis?
877 - } else if( $ip === $name && $user->isBlockedGlobally( $ip ) ) {
878 - $flags[] = '<strong>(' . wfMsgHtml('checkuser-gblocked') . ')</strong>';
879 - } else if( self::userWasBlocked( $name ) ) {
880 - $userpage = Title::makeTitle( NS_USER, $name );
881 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-wasblocked'),
882 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
883 - $flags[] = '<strong>(' . $blocklog . ')</strong>';
884 - }
 858+ $flags = $this->userBlockFlags( $ip, $users_ids[$name], $name );
885859 # Show if account is local only
886860 $authUser = $wgAuth->getUserInstance( $user );
887861 if( $user->getId() && $authUser->getId() === 0 ) {
@@ -963,9 +937,47 @@
964938
965939 $wgOut->addHTML( $s );
966940 }
 941+
 942+ protected function userBlockFlags( $ip, $userId, $name ) {
 943+ static $logs, $blocklist;
 944+ $logs = SpecialPage::getTitleFor( 'Log' );
 945+ $blocklist = SpecialPage::getTitleFor( 'Ipblocklist' );
 946+ $block = new Block();
 947+ $block->fromMaster( false ); // use slaves
 948+ $flags = array();
 949+ if( $block->load( $ip, $userId ) ) {
 950+ // Range blocked?
 951+ if( IP::isIPAddress($block->mAddress) && strpos($block->mAddress,'/') ) {
 952+ $userpage = Title::makeTitle( NS_USER, $block->mAddress );
 953+ $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
 954+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 955+ $flags[] = '<strong>(' . $blocklog . ' - ' . $block->mAddress . ')</strong>';
 956+ // Auto blocked?
 957+ } else if( $block->mAuto ) {
 958+ $blocklog = $this->sk->makeKnownLinkObj( $blocklist,
 959+ wfMsgHtml('checkuser-blocked'), 'ip=' . urlencode( "#{$block->mId}" ) );
 960+ $flags[] = '<strong>(' . $blocklog . ')</strong>';
 961+ } else {
 962+ $userpage = Title::makeTitle( NS_USER, $name );
 963+ $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-blocked'),
 964+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 965+ $flags[] = '<strong>(' . $blocklog . ')</strong>';
 966+ }
 967+ // IP that is blocked on all wikis?
 968+ } else if( $ip === $name && $user->isBlockedGlobally( $ip ) ) {
 969+ $flags[] = '<strong>(' . wfMsgHtml('checkuser-gblocked') . ')</strong>';
 970+ } else if( self::userWasBlocked( $name ) ) {
 971+ $userpage = Title::makeTitle( NS_USER, $name );
 972+ $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml('checkuser-wasblocked'),
 973+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 974+ $flags[] = '<strong>(' . $blocklog . ')</strong>';
 975+ }
 976+ return $flags;
 977+ }
967978
968979 /**
969 - * @param $row
 980+ * @param Row $row
 981+ * @param string $reason
970982 * @return a streamlined recent changes line with IP data
971983 */
972984 protected function CUChangesLine( $row, $reason ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r56183Fix breakage from r56160. $user object was needed.aaron15:43, 11 September 2009

Status & tagging log