3 * Implements Special:Protectedtitles
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.
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.
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
21 * @ingroup SpecialPage
25 * A special page that list protected titles from creation
27 * @ingroup SpecialPage
29 class SpecialProtectedtitles
extends SpecialPage
{
30 protected $IdLevel = 'level';
31 protected $IdType = 'type';
33 public function __construct() {
34 parent
::__construct( 'Protectedtitles' );
37 function execute( $par ) {
39 $this->outputHeader();
41 // Purge expired entries on one in every 10 queries
42 if ( !mt_rand( 0, 10 ) ) {
43 Title
::purgeExpiredRestrictions();
46 $request = $this->getRequest();
47 $type = $request->getVal( $this->IdType
);
48 $level = $request->getVal( $this->IdLevel
);
49 $sizetype = $request->getVal( 'sizetype' );
50 $size = $request->getIntOrNull( 'size' );
51 $NS = $request->getIntOrNull( 'namespace' );
53 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
55 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
57 if ( $pager->getNumRows() ) {
58 $this->getOutput()->addHTML(
59 $pager->getNavigationBar() .
60 '<ul>' . $pager->getBody() . '</ul>' .
61 $pager->getNavigationBar()
64 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
69 * Callback function to output a restriction
71 * @param object $row Database row
74 function formatRow( $row ) {
75 wfProfileIn( __METHOD__
);
77 static $infinity = null;
79 if ( is_null( $infinity ) ) {
80 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
83 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
85 wfProfileOut( __METHOD__
);
87 return Html
::rawElement(
92 array( 'class' => 'mw-invalidtitle' ),
93 Linker
::getInvalidTitleDescription(
102 $link = Linker
::link( $title );
103 $description_items = array();
104 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm
)->escaped();
105 $description_items[] = $protType;
106 $lang = $this->getLanguage();
107 $expiry = strlen( $row->pt_expiry
) ?
108 $lang->formatExpiry( $row->pt_expiry
, TS_MW
) :
111 if ( $expiry != $infinity ) {
112 $user = $this->getUser();
113 $description_items[] = $this->msg(
114 'protect-expiring-local',
115 $lang->userTimeAndDate( $expiry, $user ),
116 $lang->userDate( $expiry, $user ),
117 $lang->userTime( $expiry, $user )
121 wfProfileOut( __METHOD__
);
123 // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
124 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
128 * @param $namespace Integer:
129 * @param $type string
130 * @param $level string
134 function showOptions( $namespace, $type = 'edit', $level ) {
136 $action = htmlspecialchars( $wgScript );
137 $title = $this->getTitle();
138 $special = htmlspecialchars( $title->getPrefixedDBkey() );
140 return "<form action=\"$action\" method=\"get\">\n" .
142 Xml
::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
143 Html
::hidden( 'title', $special ) . " \n" .
144 $this->getNamespaceMenu( $namespace ) . " \n" .
145 $this->getLevelMenu( $level ) . " \n" .
146 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
147 "</fieldset></form>";
151 * Prepare the namespace filter drop-down; standard namespace
152 * selector, sans the MediaWiki namespace
154 * @param $namespace Mixed: pre-select namespace
157 function getNamespaceMenu( $namespace = null ) {
158 return Html
::namespaceSelector(
160 'selected' => $namespace,
162 'label' => $this->msg( 'namespace' )->text()
164 'name' => 'namespace',
166 'class' => 'namespaceselector',
172 * @param string $pr_level Determines which option is selected as default
173 * @return string Formatted HTML
176 function getLevelMenu( $pr_level ) {
177 global $wgRestrictionLevels;
180 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
183 // First pass to load the log names
184 foreach ( $wgRestrictionLevels as $type ) {
185 if ( $type != '' && $type != '*' ) {
186 $text = $this->msg( "restriction-level-$type" )->text();
191 // Is there only one level (aside from "all")?
192 if ( count( $m ) <= 2 ) {
195 // Third pass generates sorted XHTML content
196 foreach ( $m as $text => $type ) {
197 $selected = ( $type == $pr_level );
198 $options[] = Xml
::option( $text, $type, $selected );
201 return Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
203 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
204 implode( "\n", $options ) );
207 protected function getGroupName() {
208 return 'maintenance';
216 class ProtectedTitlesPager
extends AlphabeticPager
{
217 public $mForm, $mConds;
219 function __construct( $form, $conds = array(), $type, $level, $namespace,
220 $sizetype = '', $size = 0
222 $this->mForm
= $form;
223 $this->mConds
= $conds;
224 $this->level
= $level;
225 $this->namespace = $namespace;
226 $this->size
= intval( $size );
227 parent
::__construct( $form->getContext() );
230 function getStartBody() {
231 wfProfileIn( __METHOD__
);
232 # Do a link batch query
233 $this->mResult
->seek( 0 );
236 foreach ( $this->mResult
as $row ) {
237 $lb->add( $row->pt_namespace
, $row->pt_title
);
241 wfProfileOut( __METHOD__
);
249 function getTitle() {
250 return $this->mForm
->getTitle();
253 function formatRow( $row ) {
254 return $this->mForm
->formatRow( $row );
260 function getQueryInfo() {
261 $conds = $this->mConds
;
262 $conds[] = 'pt_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
263 if ( $this->level
) {
264 $conds['pt_create_perm'] = $this->level
;
267 if ( !is_null( $this->namespace ) ) {
268 $conds[] = 'pt_namespace=' . $this->mDb
->addQuotes( $this->namespace );
272 'tables' => 'protected_titles',
273 'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
274 'pt_expiry', 'pt_timestamp' ),
279 function getIndexField() {
280 return 'pt_timestamp';