Merge "UserrightsPage::makeGroupNameListForLog() was removed"
[lhc/web/wiklou.git] / includes / specials / pagers / BlockListPager.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Pager
20 */
21
22 /**
23 * @ingroup Pager
24 */
25 class BlockListPager extends TablePager {
26
27 protected $conds;
28 protected $page;
29
30 /**
31 * @param SpecialPage $page
32 * @param array $conds
33 */
34 function __construct( $page, $conds ) {
35 $this->page = $page;
36 $this->conds = $conds;
37 $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
38 parent::__construct( $page->getContext() );
39 }
40
41 function getFieldNames() {
42 static $headers = null;
43
44 if ( $headers === null ) {
45 $headers = [
46 'ipb_timestamp' => 'blocklist-timestamp',
47 'ipb_target' => 'blocklist-target',
48 'ipb_expiry' => 'blocklist-expiry',
49 'ipb_by' => 'blocklist-by',
50 'ipb_params' => 'blocklist-params',
51 'ipb_reason' => 'blocklist-reason',
52 ];
53 foreach ( $headers as $key => $val ) {
54 $headers[$key] = $this->msg( $val )->text();
55 }
56 }
57
58 return $headers;
59 }
60
61 function formatValue( $name, $value ) {
62 static $msg = null;
63 if ( $msg === null ) {
64 $keys = [
65 'anononlyblock',
66 'createaccountblock',
67 'noautoblockblock',
68 'emailblock',
69 'blocklist-nousertalk',
70 'unblocklink',
71 'change-blocklink',
72 ];
73
74 foreach ( $keys as $key ) {
75 $msg[$key] = $this->msg( $key )->escaped();
76 }
77 }
78
79 /** @var $row object */
80 $row = $this->mCurrentRow;
81
82 $language = $this->getLanguage();
83
84 $formatted = '';
85
86 switch ( $name ) {
87 case 'ipb_timestamp':
88 $formatted = htmlspecialchars( $language->userTimeAndDate( $value, $this->getUser() ) );
89 break;
90
91 case 'ipb_target':
92 if ( $row->ipb_auto ) {
93 $formatted = $this->msg( 'autoblockid', $row->ipb_id )->parse();
94 } else {
95 list( $target, $type ) = Block::parseTarget( $row->ipb_address );
96 switch ( $type ) {
97 case Block::TYPE_USER:
98 case Block::TYPE_IP:
99 $formatted = Linker::userLink( $target->getId(), $target );
100 $formatted .= Linker::userToolLinks(
101 $target->getId(),
102 $target,
103 false,
104 Linker::TOOL_LINKS_NOBLOCK
105 );
106 break;
107 case Block::TYPE_RANGE:
108 $formatted = htmlspecialchars( $target );
109 }
110 }
111 break;
112
113 case 'ipb_expiry':
114 $formatted = htmlspecialchars( $language->formatExpiry(
115 $value,
116 /* User preference timezone */true
117 ) );
118 if ( $this->getUser()->isAllowed( 'block' ) ) {
119 if ( $row->ipb_auto ) {
120 $links[] = Linker::linkKnown(
121 SpecialPage::getTitleFor( 'Unblock' ),
122 $msg['unblocklink'],
123 [],
124 [ 'wpTarget' => "#{$row->ipb_id}" ]
125 );
126 } else {
127 $links[] = Linker::linkKnown(
128 SpecialPage::getTitleFor( 'Unblock', $row->ipb_address ),
129 $msg['unblocklink']
130 );
131 $links[] = Linker::linkKnown(
132 SpecialPage::getTitleFor( 'Block', $row->ipb_address ),
133 $msg['change-blocklink']
134 );
135 }
136 $formatted .= ' ' . Html::rawElement(
137 'span',
138 [ 'class' => 'mw-blocklist-actions' ],
139 $this->msg( 'parentheses' )->rawParams(
140 $language->pipeList( $links ) )->escaped()
141 );
142 }
143 break;
144
145 case 'ipb_by':
146 if ( isset( $row->by_user_name ) ) {
147 $formatted = Linker::userLink( $value, $row->by_user_name );
148 $formatted .= Linker::userToolLinks( $value, $row->by_user_name );
149 } else {
150 $formatted = htmlspecialchars( $row->ipb_by_text ); // foreign user?
151 }
152 break;
153
154 case 'ipb_reason':
155 $formatted = Linker::formatComment( $value );
156 break;
157
158 case 'ipb_params':
159 $properties = [];
160 if ( $row->ipb_anon_only ) {
161 $properties[] = $msg['anononlyblock'];
162 }
163 if ( $row->ipb_create_account ) {
164 $properties[] = $msg['createaccountblock'];
165 }
166 if ( $row->ipb_user && !$row->ipb_enable_autoblock ) {
167 $properties[] = $msg['noautoblockblock'];
168 }
169
170 if ( $row->ipb_block_email ) {
171 $properties[] = $msg['emailblock'];
172 }
173
174 if ( !$row->ipb_allow_usertalk ) {
175 $properties[] = $msg['blocklist-nousertalk'];
176 }
177
178 $formatted = $language->commaList( $properties );
179 break;
180
181 default:
182 $formatted = "Unable to format $name";
183 break;
184 }
185
186 return $formatted;
187 }
188
189 function getQueryInfo() {
190 $info = [
191 'tables' => [ 'ipblocks', 'user' ],
192 'fields' => [
193 'ipb_id',
194 'ipb_address',
195 'ipb_user',
196 'ipb_by',
197 'ipb_by_text',
198 'by_user_name' => 'user_name',
199 'ipb_reason',
200 'ipb_timestamp',
201 'ipb_auto',
202 'ipb_anon_only',
203 'ipb_create_account',
204 'ipb_enable_autoblock',
205 'ipb_expiry',
206 'ipb_range_start',
207 'ipb_range_end',
208 'ipb_deleted',
209 'ipb_block_email',
210 'ipb_allow_usertalk',
211 ],
212 'conds' => $this->conds,
213 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id = ipb_by' ] ]
214 ];
215
216 # Filter out any expired blocks
217 $db = $this->getDatabase();
218 $info['conds'][] = 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() );
219
220 # Is the user allowed to see hidden blocks?
221 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
222 $info['conds']['ipb_deleted'] = 0;
223 }
224
225 return $info;
226 }
227
228 public function getTableClass() {
229 return parent::getTableClass() . ' mw-blocklist';
230 }
231
232 function getIndexField() {
233 return 'ipb_timestamp';
234 }
235
236 function getDefaultSort() {
237 return 'ipb_timestamp';
238 }
239
240 function isFieldSortable( $name ) {
241 return false;
242 }
243
244 /**
245 * Do a LinkBatch query to minimise database load when generating all these links
246 * @param ResultWrapper $result
247 */
248 function preprocessResults( $result ) {
249 # Do a link batch query
250 $lb = new LinkBatch;
251 $lb->setCaller( __METHOD__ );
252
253 foreach ( $result as $row ) {
254 $lb->add( NS_USER, $row->ipb_address );
255 $lb->add( NS_USER_TALK, $row->ipb_address );
256
257 if ( isset( $row->by_user_name ) ) {
258 $lb->add( NS_USER, $row->by_user_name );
259 $lb->add( NS_USER_TALK, $row->by_user_name );
260 }
261 }
262
263 $lb->execute();
264 }
265
266 }