Followup r104353, updating Special:ProtectedTitles
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedtitles.php
1 <?php
2 /**
3 * Implements Special:Protectedtitles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that list protected titles from creation
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialProtectedtitles extends SpecialPage {
30
31 public function __construct() {
32 parent::__construct( 'Protectedtitles' );
33 }
34
35 function execute( $par ) {
36 $this->setHeaders();
37 $this->outputHeader();
38
39 // Purge expired entries on one in every 10 queries
40 if ( !mt_rand( 0, 10 ) ) {
41 Title::purgeExpiredRestrictions();
42 }
43
44 $pager = new ProtectedTitlesPager( $this );
45 $this->getOutput()->addHTML( $pager->buildHTMLForm() );
46
47 if ( $pager->getNumRows() ) {
48 $s = $pager->getNavigationBar();
49 $s .= "<ul>" .
50 $pager->getBody() .
51 "</ul>";
52 $s .= $pager->getNavigationBar();
53 } else {
54 $s = '<p>' . wfMsgHtml( 'protectedtitlesempty' ) . '</p>';
55 }
56 $this->getOutput()->addHTML( $s );
57 }
58
59 /**
60 * Callback function to output a restriction
61 *
62 * @param $row
63 * @return string
64 */
65 function formatRow( $row ) {
66 wfProfileIn( __METHOD__ );
67
68 static $infinity = null;
69
70 if( is_null( $infinity ) ){
71 $infinity = wfGetDB( DB_SLAVE )->getInfinity();
72 }
73
74 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
75 $link = Linker::link( $title );
76
77 $description_items = array ();
78
79 $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm );
80
81 $description_items[] = $protType;
82
83 $lang = $this->getLanguage();
84 $expiry = strlen( $row->pt_expiry ) ? $lang->formatExpiry( $row->pt_expiry, TS_MW ) : $infinity;
85 if( $expiry != $infinity ) {
86 $expiry_description = wfMsg(
87 'protect-expiring-local',
88 $lang->timeanddate( $expiry, true ),
89 $lang->date( $expiry, true ),
90 $lang->time( $expiry, true )
91 );
92
93 $description_items[] = htmlspecialchars($expiry_description);
94 }
95
96 wfProfileOut( __METHOD__ );
97
98 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
99 }
100 }
101
102 /**
103 * @todo document
104 * @ingroup Pager
105 */
106 class ProtectedTitlesPager extends AlphabeticPager {
107 /**
108 * @var SpecialProtectedtitles
109 */
110 public $mForm;
111
112 /**
113 * @var array
114 */
115 public $mConds;
116
117 /**
118 * @param $form SpecialProtectedtitles
119 * @param $conds array
120 */
121 function __construct( $form, $conds = array() ) {
122 $this->mForm = $form;
123 $this->mConds = $conds;
124 parent::__construct( $form->getContext() );
125 }
126
127 function getStartBody() {
128 wfProfileIn( __METHOD__ );
129 # Do a link batch query
130 $this->mResult->seek( 0 );
131 $lb = new LinkBatch;
132
133 foreach ( $this->mResult as $row ) {
134 $lb->add( $row->pt_namespace, $row->pt_title );
135 }
136
137 $lb->execute();
138 wfProfileOut( __METHOD__ );
139 return '';
140 }
141
142 /**
143 * @return Title
144 */
145 function getTitle() {
146 return SpecialPage::getTitleFor( 'Protectedtitles' );
147 }
148
149 function formatRow( $row ) {
150 return $this->mForm->formatRow( $row );
151 }
152
153 /**
154 * @return array
155 */
156 function getQueryInfo() {
157 $conds = $this->mConds;
158 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
159
160 if ( $this->mHTMLForm->getVal( 'Level' ) ) {
161 $conds['pt_create_perm'] = $this->mHTMLForm->getVal( 'Level' );
162 }
163 if ( $this->mHTMLForm->getVal( 'Namespace' ) !== '' ) {
164 $conds['pt_namespace'] = $this->mHTMLForm->getVal( 'Namespace' );
165 }
166
167 return array(
168 'tables' => 'protected_titles',
169 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
170 'conds' => $conds
171 );
172 }
173
174 function getIndexField() {
175 return 'pt_timestamp';
176 }
177
178 protected function getHTMLFormFields() {
179 return array(
180 'Namespace' => array(
181 'type' => 'namespaces',
182 'label-message' => 'namespace',
183 ),
184 'Level' => array(
185 'type' => 'restrictionlevels',
186 'label-message' => 'restriction-level',
187 ),
188 );
189 }
190
191 protected function getHTMLFormSubmit() {
192 return 'allpagessubmit';
193 }
194
195 protected function getHTMLFormLegend() {
196 return 'protectedtitles';
197 }
198
199
200 }
201