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
{
31 protected $IdLevel = 'level';
32 protected $IdType = 'type';
34 public function __construct() {
35 parent
::__construct( 'Protectedtitles' );
38 function execute( $par ) {
40 $this->outputHeader();
42 // Purge expired entries on one in every 10 queries
43 if ( !mt_rand( 0, 10 ) ) {
44 Title
::purgeExpiredRestrictions();
47 $request = $this->getRequest();
48 $type = $request->getVal( $this->IdType
);
49 $level = $request->getVal( $this->IdLevel
);
50 $sizetype = $request->getVal( 'sizetype' );
51 $size = $request->getIntOrNull( 'size' );
52 $NS = $request->getIntOrNull( 'namespace' );
54 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
56 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
58 if ( $pager->getNumRows() ) {
59 $this->getOutput()->addHTML(
60 $pager->getNavigationBar() .
61 '<ul>' . $pager->getBody() . '</ul>' .
62 $pager->getNavigationBar()
65 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
70 * Callback function to output a restriction
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
);
84 $link = Linker
::link( $title );
86 $description_items = array ();
88 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm
)->escaped();
90 $description_items[] = $protType;
92 $lang = $this->getLanguage();
93 $expiry = strlen( $row->pt_expiry
) ?
$lang->formatExpiry( $row->pt_expiry
, TS_MW
) : $infinity;
94 if( $expiry != $infinity ) {
95 $user = $this->getUser();
96 $description_items[] = $this->msg(
97 'protect-expiring-local',
98 $lang->userTimeAndDate( $expiry, $user ),
99 $lang->userDate( $expiry, $user ),
100 $lang->userTime( $expiry, $user )
104 wfProfileOut( __METHOD__
);
106 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
110 * @param $namespace Integer:
111 * @param $type string
112 * @param $level string
116 function showOptions( $namespace, $type='edit', $level ) {
118 $action = htmlspecialchars( $wgScript );
119 $title = $this->getTitle();
120 $special = htmlspecialchars( $title->getPrefixedDBkey() );
121 return "<form action=\"$action\" method=\"get\">\n" .
123 Xml
::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
124 Html
::hidden( 'title', $special ) . " \n" .
125 $this->getNamespaceMenu( $namespace ) . " \n" .
126 $this->getLevelMenu( $level ) . " \n" .
127 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
128 "</fieldset></form>";
132 * Prepare the namespace filter drop-down; standard namespace
133 * selector, sans the MediaWiki namespace
135 * @param $namespace Mixed: pre-select namespace
138 function getNamespaceMenu( $namespace = null ) {
139 return Html
::namespaceSelector(
141 'selected' => $namespace,
143 'label' => $this->msg( 'namespace' )->text()
145 'name' => 'namespace',
147 'class' => 'namespaceselector',
153 * @return string Formatted HTML
156 function getLevelMenu( $pr_level ) {
157 global $wgRestrictionLevels;
159 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array
162 // First pass to load the log names
163 foreach( $wgRestrictionLevels as $type ) {
164 if ( $type !='' && $type !='*') {
165 $text = $this->msg( "restriction-level-$type" )->text();
169 // Is there only one level (aside from "all")?
170 if( count($m) <= 2 ) {
173 // Third pass generates sorted XHTML content
174 foreach( $m as $text => $type ) {
175 $selected = ($type == $pr_level );
176 $options[] = Xml
::option( $text, $type, $selected );
180 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
182 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
183 implode( "\n", $options ) );
191 class ProtectedTitlesPager
extends AlphabeticPager
{
192 public $mForm, $mConds;
194 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
195 $this->mForm
= $form;
196 $this->mConds
= $conds;
197 $this->level
= $level;
198 $this->namespace = $namespace;
199 $this->size
= intval($size);
200 parent
::__construct( $form->getContext() );
203 function getStartBody() {
204 wfProfileIn( __METHOD__
);
205 # Do a link batch query
206 $this->mResult
->seek( 0 );
209 foreach ( $this->mResult
as $row ) {
210 $lb->add( $row->pt_namespace
, $row->pt_title
);
214 wfProfileOut( __METHOD__
);
221 function getTitle() {
222 return $this->mForm
->getTitle();
225 function formatRow( $row ) {
226 return $this->mForm
->formatRow( $row );
232 function getQueryInfo() {
233 $conds = $this->mConds
;
234 $conds[] = 'pt_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
236 $conds['pt_create_perm'] = $this->level
;
237 if( !is_null($this->namespace) )
238 $conds[] = 'pt_namespace=' . $this->mDb
->addQuotes( $this->namespace );
240 'tables' => 'protected_titles',
241 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
246 function getIndexField() {
247 return 'pt_timestamp';