r53162 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53161‎ | r53162 | r53163 >
Date:10:36, 13 July 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
Didn't mean to commit this, but the lovely svn automatically added it for me
Modified paths:
  • /trunk/phase3/includes/specials/SpecialListUserRestrictions.php (deleted) (history)

Diff [purge]

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

Status & tagging log