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