00001 <?php
00002
00003 function wfSpecialListUserRestrictions() {
00004 global $wgOut, $wgRequest;
00005
00006 $wgOut->addWikiMsg( 'listuserrestrictions-intro' );
00007 $f = new SpecialListUserRestrictionsForm();
00008 $wgOut->addHTML( $f->getHTML() );
00009
00010 if( !mt_rand( 0, 10 ) )
00011 UserRestriction::purgeExpired();
00012 $pager = new UserRestrictionsPager( $f->getConds() );
00013 if( $pager->getNumRows() )
00014 $wgOut->addHTML( $pager->getNavigationBar() .
00015 Xml::tags( 'ul', null, $pager->getBody() ) .
00016 $pager->getNavigationBar()
00017 );
00018 elseif( $f->getConds() )
00019 $wgOut->addWikiMsg( 'listuserrestrictions-notfound' );
00020 else
00021 $wgOut->addWikiMsg( 'listuserrestrictions-empty' );
00022 }
00023
00024 class SpecialListUserRestrictionsForm {
00025 public function getHTML() {
00026 global $wgRequest, $wgScript, $wgTitle;
00027 $action = htmlspecialchars( $wgScript );
00028 $s = '';
00029 $s .= Xml::fieldset( wfMsg( 'listuserrestrictions-legend' ) );
00030 $s .= "<form action=\"{$action}\">";
00031 $s .= Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() );
00032 $s .= Xml::label( wfMsgHtml( 'listuserrestrictions-type' ), 'type' ) . ' ' .
00033 self::typeSelector( 'type', $wgRequest->getVal( 'type' ), 'type' );
00034 $s .= ' ';
00035 $s .= Xml::inputLabel( wfMsgHtml( 'listuserrestrictions-user' ), 'user', 'user',
00036 false, $wgRequest->getVal( 'user' ) );
00037 $s .= '<p>';
00038 $s .= Xml::label( wfMsgHtml( 'listuserrestrictions-namespace' ), 'namespace' ) . ' ' .
00039 Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ), '', 'namespace' );
00040 $s .= ' ';
00041 $s .= Xml::inputLabel( wfMsgHtml( 'listuserrestrictions-page' ), 'page', 'page',
00042 false, $wgRequest->getVal( 'page' ) );
00043 $s .= Xml::submitButton( wfMsg( 'listuserrestrictions-submit' ) );
00044 $s .= "</p></form></fieldset>";
00045 return $s;
00046 }
00047
00048 public static function typeSelector( $name = 'type', $value = '', $id = false ) {
00049 $s = new XmlSelect( $name, $id, $value );
00050 $s->addOption( wfMsg( 'userrestrictiontype-none' ), '' );
00051 $s->addOption( wfMsg( 'userrestrictiontype-page' ), UserRestriction::PAGE );
00052 $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE );
00053 return $s->getHTML();
00054 }
00055
00056 public function getConds() {
00057 global $wgRequest;
00058 $conds = array();
00059
00060 $type = $wgRequest->getVal( 'type' );
00061 if( in_array( $type, array( UserRestriction::PAGE, UserRestriction::NAMESPACE ) ) )
00062 $conds['ur_type'] = $type;
00063
00064 $user = $wgRequest->getVal( 'user' );
00065 if( $user )
00066 $conds['ur_user_text'] = $user;
00067
00068 $namespace = $wgRequest->getVal( 'namespace' );
00069 if( $namespace || $namespace === '0' )
00070 $conds['ur_namespace'] = $namespace;
00071
00072 $page = $wgRequest->getVal( 'page' );
00073 $title = Title::newFromText( $page );
00074 if( $title ) {
00075 $conds['ur_page_namespace'] = $title->getNamespace();
00076 $conds['ur_page_title'] = $title->getDBKey();
00077 }
00078
00079 return $conds;
00080 }
00081 }
00082
00083 class UserRestrictionsPager extends ReverseChronologicalPager {
00084 public $mConds;
00085
00086 public function __construct( $conds = array() ) {
00087 $this->mConds = $conds;
00088 parent::__construct();
00089 }
00090
00091 public function getStartBody() {
00092 # Copied from Special:Ipblocklist
00093 wfProfileIn( __METHOD__ );
00094 # Do a link batch query
00095 $this->mResult->seek( 0 );
00096 $lb = new LinkBatch;
00097
00098 # Faster way
00099 # Usernames and titles are in fact related by a simple substitution of space -> underscore
00100 # The last few lines of Title::secureAndSplit() tell the story.
00101 foreach( $this->mResult as $row ) {
00102 $name = str_replace( ' ', '_', $row->ur_by_text );
00103 $lb->add( NS_USER, $name );
00104 $lb->add( NS_USER_TALK, $name );
00105 $name = str_replace( ' ', '_', $row->ur_user_text );
00106 $lb->add( NS_USER, $name );
00107 $lb->add( NS_USER_TALK, $name );
00108 if( $row->ur_type == UserRestriction::PAGE )
00109 $lb->add( $row->ur_page_namespace, $row->ur_page_title );
00110 }
00111 $lb->execute();
00112 wfProfileOut( __METHOD__ );
00113 return '';
00114 }
00115
00116 public function getQueryInfo() {
00117 return array(
00118 'tables' => 'user_restrictions',
00119 'fields' => '*',
00120 'conds' => $this->mConds,
00121 );
00122 }
00123
00124 public function formatRow( $row ) {
00125 return self::formatRestriction( UserRestriction::newFromRow( $row ) );
00126 }
00127
00128
00129 public static function formatRestriction( $r ) {
00130 global $wgUser, $wgLang;
00131 $sk = $wgUser->getSkin();
00132 $timestamp = $wgLang->timeanddate( $r->getTimestamp(), true );
00133 $blockerlink = $sk->userLink( $r->getBlockerId(), $r->getBlockerText() ) .
00134 $sk->userToolLinks( $r->getBlockerId(), $r->getBlockerText() );
00135 $subjlink = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
00136 $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
00137 $expiry = is_numeric( $r->getExpiry() ) ?
00138 wfMsg( 'listuserrestrictions-row-expiry', $wgLang->timeanddate( $r->getExpiry() ) ) :
00139 wfMsg( 'ipbinfinite' );
00140 $msg = '';
00141 if( $r->isNamespace() ) {
00142 $msg = wfMsgHtml( 'listuserrestrictions-row-ns', $subjlink,
00143 $wgLang->getDisplayNsText( $r->getNamespace() ), $expiry );
00144 }
00145 if( $r->isPage() ) {
00146 $pagelink = $sk->link( $r->getPage() );
00147 $msg = wfMsgHtml( 'listuserrestrictions-row-page', $subjlink,
00148 $pagelink, $expiry );
00149 }
00150 $reason = $sk->commentBlock( $r->getReason() );
00151 $removelink = '';
00152 if( $wgUser->isAllowed( 'restrict' ) ) {
00153 $removelink = '(' . $sk->link( SpecialPage::getTitleFor( 'RemoveRestrictions' ),
00154 wfMsgHtml( 'listuserrestrictions-remove' ), array(), array( 'id' => $r->getId() ) ) . ')';
00155 }
00156 return "<li>{$timestamp}, {$blockerlink} {$msg} {$reason} {$removelink}</li>\n";
00157 }
00158
00159 public function getIndexField() {
00160 return 'ur_timestamp';
00161 }
00162 }