]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialListUserRestrictions.php
MediaWiki 1.15.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListUserRestrictions.php
1 <?php
2
3 function wfSpecialListUserRestrictions() {
4         global $wgOut, $wgRequest;
5         
6         $wgOut->addWikiMsg( 'listuserrestrictions-intro' );
7         $f = new SpecialListUserRestrictionsForm();
8         $wgOut->addHTML( $f->getHTML() );
9
10         if( !mt_rand( 0, 10 ) )
11                 UserRestriction::purgeExpired();
12         $pager = new UserRestrictionsPager( $f->getConds() );
13         if( $pager->getNumRows() ) 
14                 $wgOut->addHTML( $pager->getNavigationBar() .
15                         Xml::tags( 'ul', null, $pager->getBody() ) .
16                         $pager->getNavigationBar()
17                 );
18         elseif( $f->getConds() )
19                 $wgOut->addWikiMsg( 'listuserrestrictions-notfound' );
20         else 
21                 $wgOut->addWikiMsg( 'listuserrestrictions-empty' );
22 }
23
24 class SpecialListUserRestrictionsForm {
25         public function getHTML() {
26                 global $wgRequest, $wgScript, $wgTitle;
27                 $action = htmlspecialchars( $wgScript );
28                 $s = '';
29                 $s .= Xml::fieldset( wfMsg( 'listuserrestrictions-legend' ) );
30                 $s .= "<form action=\"{$action}\">";
31                 $s .= Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() );
32                 $s .= Xml::label( wfMsgHtml( 'listuserrestrictions-type' ), 'type' ) . '&nbsp;' .
33                         self::typeSelector( 'type', $wgRequest->getVal( 'type' ), 'type' );
34                 $s .= '&nbsp;';
35                 $s .= Xml::inputLabel( wfMsgHtml( 'listuserrestrictions-user' ), 'user', 'user',
36                         false, $wgRequest->getVal( 'user' ) );
37                 $s .= '<p>';
38                 $s .= Xml::label( wfMsgHtml( 'listuserrestrictions-namespace' ), 'namespace' ) . '&nbsp;' .
39                         Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ), '', 'namespace' );
40                 $s .= '&nbsp;';
41                 $s .= Xml::inputLabel( wfMsgHtml( 'listuserrestrictions-page' ), 'page', 'page',
42                         false, $wgRequest->getVal( 'page' ) );
43                 $s .= Xml::submitButton( wfMsg( 'listuserrestrictions-submit' ) );
44                 $s .= "</p></form></fieldset>";
45                 return $s;
46         }
47
48         public static function typeSelector( $name = 'type', $value = '', $id = false ) {
49                 $s = new XmlSelect( $name, $id, $value );
50                 $s->addOption( wfMsg( 'userrestrictiontype-none' ), '' );
51                 $s->addOption( wfMsg( 'userrestrictiontype-page' ), UserRestriction::PAGE );
52                 $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE );
53                 return $s->getHTML();
54         }
55
56         public function getConds() {
57                 global $wgRequest;
58                 $conds = array();
59
60                 $type = $wgRequest->getVal( 'type' );
61                 if( in_array( $type, array( UserRestriction::PAGE, UserRestriction::NAMESPACE ) ) )
62                         $conds['ur_type'] = $type;
63
64                 $user = $wgRequest->getVal( 'user' );
65                 if( $user )
66                         $conds['ur_user_text'] = $user;
67
68                 $namespace = $wgRequest->getVal( 'namespace' );
69                 if( $namespace || $namespace === '0' )
70                         $conds['ur_namespace'] = $namespace;
71
72                 $page = $wgRequest->getVal( 'page' );
73                 $title = Title::newFromText( $page );
74                 if( $title ) {
75                         $conds['ur_page_namespace'] = $title->getNamespace();
76                         $conds['ur_page_title'] = $title->getDBKey();
77                 }
78
79                 return $conds;
80         }
81 }
82
83 class UserRestrictionsPager extends ReverseChronologicalPager {
84         public $mConds;
85
86         public function __construct( $conds = array() ) {
87                 $this->mConds = $conds;
88                 parent::__construct();
89         }
90
91         public function getStartBody() {
92                 # Copied from Special:Ipblocklist
93                 wfProfileIn( __METHOD__ );
94                 # Do a link batch query
95                 $this->mResult->seek( 0 );
96                 $lb = new LinkBatch;
97
98                 # Faster way
99                 # Usernames and titles are in fact related by a simple substitution of space -> underscore
100                 # The last few lines of Title::secureAndSplit() tell the story.
101                 foreach( $this->mResult as $row ) {
102                         $name = str_replace( ' ', '_', $row->ur_by_text );
103                         $lb->add( NS_USER, $name );
104                         $lb->add( NS_USER_TALK, $name );
105                         $name = str_replace( ' ', '_', $row->ur_user_text );
106                         $lb->add( NS_USER, $name );
107                         $lb->add( NS_USER_TALK, $name );
108                         if( $row->ur_type == UserRestriction::PAGE )
109                                 $lb->add( $row->ur_page_namespace, $row->ur_page_title );
110                 }
111                 $lb->execute();
112                 wfProfileOut( __METHOD__ );
113                 return '';
114         }
115
116         public function getQueryInfo() {
117                 return array(
118                         'tables' => 'user_restrictions',
119                         'fields' => '*',
120                         'conds' => $this->mConds,
121                 );
122         }
123
124         public function formatRow( $row ) {
125                 return self::formatRestriction( UserRestriction::newFromRow( $row )  );
126         }
127
128         // Split off for use on Special:RestrictUser
129         public static function formatRestriction( $r ) {
130                 global $wgUser, $wgLang;
131                 $sk = $wgUser->getSkin();
132                 $timestamp = $wgLang->timeanddate( $r->getTimestamp(), true );
133                 $blockerlink = $sk->userLink( $r->getBlockerId(), $r->getBlockerText() ) .
134                         $sk->userToolLinks( $r->getBlockerId(), $r->getBlockerText() );
135                 $subjlink = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
136                         $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
137                 $expiry = is_numeric( $r->getExpiry() ) ?
138                         wfMsg( 'listuserrestrictions-row-expiry', $wgLang->timeanddate( $r->getExpiry() ) ) :
139                         wfMsg( 'ipbinfinite' );
140                 $msg = '';
141                 if( $r->isNamespace() ) {
142                         $msg = wfMsgHtml( 'listuserrestrictions-row-ns', $subjlink,
143                                 $wgLang->getDisplayNsText( $r->getNamespace() ), $expiry );
144                 }
145                 if( $r->isPage() ) {
146                         $pagelink = $sk->link( $r->getPage() );
147                         $msg = wfMsgHtml( 'listuserrestrictions-row-page', $subjlink,
148                                 $pagelink, $expiry );
149                 }
150                 $reason = $sk->commentBlock( $r->getReason() );
151                 $removelink = '';
152                 if( $wgUser->isAllowed( 'restrict' ) ) {
153                         $removelink = '(' . $sk->link( SpecialPage::getTitleFor( 'RemoveRestrictions' ),
154                                 wfMsgHtml( 'listuserrestrictions-remove' ), array(), array( 'id' => $r->getId() ) ) . ')';
155                 }
156                 return "<li>{$timestamp}, {$blockerlink} {$msg} {$reason} {$removelink}</li>\n";
157         }
158
159         public function getIndexField() {
160                 return 'ur_timestamp';
161         }
162 }