X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialIpblocklist.php;h=ad76832cecd706b58e362151f355e60aa6b666b3;hb=40745cfef875263d13f29cea01b501655d218f16;hp=5b16cb16156e1e1e40c6568a72feedaa1ddcc803;hpb=fe5ff59ad6b4c8b7b5350e3335875d297f820773;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialIpblocklist.php b/includes/SpecialIpblocklist.php index 5b16cb1615..ad76832cec 100644 --- a/includes/SpecialIpblocklist.php +++ b/includes/SpecialIpblocklist.php @@ -1,7 +1,14 @@ getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) ); @@ -11,10 +18,11 @@ function wfSpecialIpblocklist() $ipu = new IPUnblockForm( $ip, $reason ); if ( "success" == $action ) { - $msg = wfMsg( "ipusuccess", $ip ); + $msg = wfMsg( "ipusuccess", htmlspecialchars( $ip ) ); $ipu->showList( $msg ); - } else if ( "submit" == $action && $wgRequest->wasPosted() ) { - if ( ! $wgUser->isSysop() ) { + } else if ( "submit" == $action && $wgRequest->wasPosted() && + $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { + if ( ! $wgUser->isAllowed('block') ) { $wgOut->sysopRequired(); return; } @@ -26,6 +34,11 @@ function wfSpecialIpblocklist() } } +/** + * + * @package MediaWiki + * @subpackage SpecialPage + */ class IPUnblockForm { var $ip, $reason; @@ -36,21 +49,22 @@ class IPUnblockForm { function showForm( $err ) { - global $wgOut, $wgUser, $wgLang; + global $wgOut, $wgUser, $wgLang, $wgSysopUserBans; - $wgOut->setPagetitle( wfMsg( "unblockip" ) ); - $wgOut->addWikiText( wfMsg( "unblockiptext" ) ); + $wgOut->setPagetitle( wfMsg( 'unblockip' ) ); + $wgOut->addWikiText( wfMsg( 'unblockiptext' ) ); - $ipa = wfMsg( "ipaddress" ); - $ipr = wfMsg( "ipbreason" ); - $ipus = htmlspecialchars( wfMsg( "ipusubmit" ) ); + $ipa = wfMsgHtml( $wgSysopUserBans ? 'ipadressorusername' : 'ipaddress' ); + $ipr = wfMsgHtml( 'ipbreason' ); + $ipus = wfMsgHtml( 'ipusubmit' ); $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" ); $action = $titleObj->escapeLocalURL( "action=submit" ); if ( "" != $err ) { $wgOut->setSubtitle( wfMsg( "formerror" ) ); - $wgOut->addHTML( "

{$err}

\n" ); + $wgOut->addWikitext( "{$err}\n" ); } + $token = htmlspecialchars( $wgUser->editToken() ); $wgOut->addHTML( "
@@ -74,12 +88,12 @@ class IPUnblockForm { +
\n" ); } - function doSubmit() - { + function doSubmit() { global $wgOut, $wgUser, $wgLang; $block = new Block(); @@ -90,15 +104,14 @@ class IPUnblockForm { } else { $block->mAddress = $this->ip; } - + # Delete block (if it exists) # We should probably check for errors rather than just declaring success $block->delete(); # Make log entry - $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) ); - $action = wfMsg( "unblocklogentry", $this->ip ); - $log->addEntry( $action, $this->reason ); + $log = new LogPage( 'block' ); + $log->addEntry( 'unblock', Title::makeTitle( NS_USER, $this->ip ), $this->reason ); # Report to the user $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" ); @@ -106,63 +119,131 @@ class IPUnblockForm { $wgOut->redirect( $success ); } - function showList( $msg ) - { + function showList( $msg ) { global $wgOut; $wgOut->setPagetitle( wfMsg( "ipblocklist" ) ); if ( "" != $msg ) { $wgOut->setSubtitle( $msg ); } + global $wgRequest; + list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset(); + $this->counter = 0; + + $paging = '

' . wfViewPrevNext( $this->offset, $this->limit, + Title::makeTitle( NS_SPECIAL, 'Ipblocklist' ), + 'ip=' . urlencode( $this->ip ) ) . "

\n"; + $wgOut->addHTML( $paging ); + + $search = $this->searchForm(); + $wgOut->addHTML( $search ); + $wgOut->addHTML( "\n" ); + $wgOut->addHTML( $paging ); } -} - -# Callback function to output a block -function wfAddRow( $block, $tag ) { - global $wgOut, $wgUser, $wgLang; - - $sk = $wgUser->getSkin(); - - # Hide addresses blocked by User::spreadBlocks, for privacy - $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress; - - $name = User::whoIs( $block->mBy ); - $ulink = $sk->makeKnownLink( $wgLang->getNsText( Namespace::getUser() ). ":{$name}", $name ); - $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true ); - if ( $block->mExpiry === "" ) { - $formattedExpiry = "indefinite"; - } else { - $formattedExpiry = $wgLang->timeanddate( $block->mExpiry, true ); + function searchForm() { + global $wgTitle; + return + wfElement( 'form', array( + 'action' => $wgTitle->getLocalUrl() ), + null ) . + wfElement( 'input', array( + 'type' => 'hidden', + 'name' => 'action', + 'value' => 'search' ) ). + wfElement( 'input', array( + 'type' => 'hidden', + 'name' => 'limit', + 'value' => $this->limit ) ). + wfElement( 'input', array( + 'name' => 'ip', + 'value' => $this->ip ) ) . + wfElement( 'input', array( + 'type' => 'submit', + 'value' => wfMsg( 'search' ) ) ) . + ''; } + + /** + * Callback function to output a block + */ + function addRow( $block, $tag ) { + global $wgOut, $wgUser, $wgLang, $wgContLang; + + if( $this->ip != '' ) { + if( $block->mAuto ) { + if( stristr( $block->mId, $this->ip ) == false ) { + return; + } + } else { + if( stristr( $block->mAddress, $this->ip ) == false ) { + return; + } + } + } + + // Loading blocks is fast; displaying them is slow. + // Quick hack for paging. + $this->counter++; + if( $this->counter <= $this->offset ) { + return; + } + if( $this->counter - $this->offset > $this->limit ) { + return; + } + + $fname = 'IPUnblockForm-addRow'; + wfProfileIn( $fname ); + + static $sk=null, $msg=null; + + if( is_null( $sk ) ) + $sk = $wgUser->getSkin(); + if( is_null( $msg ) ) { + $msg = array(); + foreach( array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink' ) as $key ) { + $msg[$key] = wfMsgHtml( $key ); + } + $msg['blocklistline'] = wfMsg( 'blocklistline' ); + } - $line = wfMsg( "blocklistline", $formattedTime, $ulink, $addr, $formattedExpiry ); + # Hide addresses blocked by User::spreadBlocks, for privacy + $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress; - $wgOut->addHTML( "
  • {$line}" ); - - if ( !$block->mAuto ) { - $titleObj = Title::makeTitle( NS_SPECIAL, "Contributions" ); - $clink = "escapeLocalURL( "target={$block->mAddress}" ) . "\">" . - wfMsg( "contribslink" ) . ""; - $wgOut->addHTML( " ({$clink})" ); - } - - if ( $wgUser->isSysop() ) { - $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" ); - $ublink = "escapeLocalURL( "action=unblock&ip=" . urlencode( $addr ) ) . "\">" . - wfMsg( "unblocklink" ) . ""; - $wgOut->addHTML( " ({$ublink})" ); - } - if ( "" != $block->mReason ) { - $wgOut->addHTML( " (" . wfEscapeHTML( $block->mReason ) . - ")" ); + $name = $block->getByName(); + $ulink = $sk->makeKnownLinkObj( Title::makeTitle( NS_USER, $name ), $name ); + $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true ); + + if ( $block->mExpiry === "" ) { + $formattedExpiry = $msg['infiniteblock']; + } else { + $formattedExpiry = wfMsgReplaceArgs( $msg['expiringblock'], + array( $wgLang->timeanddate( $block->mExpiry, true ) ) ); + } + + $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $ulink, $addr, $formattedExpiry ) ); + + $wgOut->addHTML( "
  • {$line}" ); + + if ( !$block->mAuto ) { + $titleObj = Title::makeTitle( NS_SPECIAL, "Contributions" ); + $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['contribslink'], "target={$block->mAddress}") . ')' ); + } + + if ( $wgUser->isAllowed('block') ) { + $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" ); + $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&ip=' . urlencode( $addr ) ) . ')' ); + } + $wgOut->addHTML( $sk->commentBlock( $block->mReason ) ); + $wgOut->addHTML( "
  • \n" ); + wfProfileOut( $fname ); } - $wgOut->addHTML( "\n" ); } - ?>