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 ) {
76 static $infinity = null;
78 if ( is_null( $infinity ) ) {
79 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
82 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
85 return Html
::rawElement(
90 array( 'class' => 'mw-invalidtitle' ),
91 Linker
::getInvalidTitleDescription(
100 $link = Linker
::link( $title );
101 $description_items = array();
102 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
103 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm
)->escaped();
104 $description_items[] = $protType;
105 $lang = $this->getLanguage();
106 $expiry = strlen( $row->pt_expiry
) ?
107 $lang->formatExpiry( $row->pt_expiry
, TS_MW
) :
110 if ( $expiry != $infinity ) {
111 $user = $this->getUser();
112 $description_items[] = $this->msg(
113 'protect-expiring-local',
114 $lang->userTimeAndDate( $expiry, $user ),
115 $lang->userDate( $expiry, $user ),
116 $lang->userTime( $expiry, $user )
121 // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
122 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
126 * @param int $namespace
127 * @param string $type
128 * @param string $level
132 function showOptions( $namespace, $type = 'edit', $level ) {
133 $action = htmlspecialchars( wfScript() );
134 $title = $this->getPageTitle();
135 $special = htmlspecialchars( $title->getPrefixedDBkey() );
137 return "<form action=\"$action\" method=\"get\">\n" .
139 Xml
::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
140 Html
::hidden( 'title', $special ) . " \n" .
141 $this->getNamespaceMenu( $namespace ) . " \n" .
142 $this->getLevelMenu( $level ) . " \n" .
143 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
144 "</fieldset></form>";
148 * Prepare the namespace filter drop-down; standard namespace
149 * selector, sans the MediaWiki namespace
151 * @param string|null $namespace Pre-select namespace
154 function getNamespaceMenu( $namespace = null ) {
155 return Html
::namespaceSelector(
157 'selected' => $namespace,
159 'label' => $this->msg( 'namespace' )->text()
161 'name' => 'namespace',
163 'class' => 'namespaceselector',
169 * @param string $pr_level Determines which option is selected as default
170 * @return string Formatted HTML
173 function getLevelMenu( $pr_level ) {
175 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
178 // First pass to load the log names
179 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
180 if ( $type != '' && $type != '*' ) {
181 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
182 $text = $this->msg( "restriction-level-$type" )->text();
187 // Is there only one level (aside from "all")?
188 if ( count( $m ) <= 2 ) {
191 // Third pass generates sorted XHTML content
192 foreach ( $m as $text => $type ) {
193 $selected = ( $type == $pr_level );
194 $options[] = Xml
::option( $text, $type, $selected );
197 return Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
199 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
200 implode( "\n", $options ) );
203 protected function getGroupName() {
204 return 'maintenance';
212 class ProtectedTitlesPager
extends AlphabeticPager
{
213 public $mForm, $mConds;
215 function __construct( $form, $conds = array(), $type, $level, $namespace,
216 $sizetype = '', $size = 0
218 $this->mForm
= $form;
219 $this->mConds
= $conds;
220 $this->level
= $level;
221 $this->namespace = $namespace;
222 $this->size
= intval( $size );
223 parent
::__construct( $form->getContext() );
226 function getStartBody() {
227 # Do a link batch query
228 $this->mResult
->seek( 0 );
231 foreach ( $this->mResult
as $row ) {
232 $lb->add( $row->pt_namespace
, $row->pt_title
);
243 function getTitle() {
244 return $this->mForm
->getTitle();
247 function formatRow( $row ) {
248 return $this->mForm
->formatRow( $row );
254 function getQueryInfo() {
255 $conds = $this->mConds
;
256 $conds[] = 'pt_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
257 if ( $this->level
) {
258 $conds['pt_create_perm'] = $this->level
;
261 if ( !is_null( $this->namespace ) ) {
262 $conds[] = 'pt_namespace=' . $this->mDb
->addQuotes( $this->namespace );
266 'tables' => 'protected_titles',
267 'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
268 'pt_expiry', 'pt_timestamp' ),
273 function getIndexField() {
274 return 'pt_timestamp';