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 $request = $this->getRequest();
42 $type = $request->getVal( $this->IdType
);
43 $level = $request->getVal( $this->IdLevel
);
44 $sizetype = $request->getVal( 'sizetype' );
45 $size = $request->getIntOrNull( 'size' );
46 $NS = $request->getIntOrNull( 'namespace' );
48 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
50 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
52 if ( $pager->getNumRows() ) {
53 $this->getOutput()->addHTML(
54 $pager->getNavigationBar() .
55 '<ul>' . $pager->getBody() . '</ul>' .
56 $pager->getNavigationBar()
59 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
64 * Callback function to output a restriction
66 * @param object $row Database row
69 function formatRow( $row ) {
71 static $infinity = null;
73 if ( is_null( $infinity ) ) {
74 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
77 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
80 return Html
::rawElement(
85 array( 'class' => 'mw-invalidtitle' ),
86 Linker
::getInvalidTitleDescription(
95 $link = Linker
::link( $title );
96 $description_items = array();
97 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
98 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm
)->escaped();
99 $description_items[] = $protType;
100 $lang = $this->getLanguage();
101 $expiry = strlen( $row->pt_expiry
) ?
102 $lang->formatExpiry( $row->pt_expiry
, TS_MW
) :
105 if ( $expiry != $infinity ) {
106 $user = $this->getUser();
107 $description_items[] = $this->msg(
108 'protect-expiring-local',
109 $lang->userTimeAndDate( $expiry, $user ),
110 $lang->userDate( $expiry, $user ),
111 $lang->userTime( $expiry, $user )
115 // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
116 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
120 * @param int $namespace
121 * @param string $type
122 * @param string $level
126 function showOptions( $namespace, $type = 'edit', $level ) {
127 $action = htmlspecialchars( wfScript() );
128 $title = $this->getPageTitle();
129 $special = htmlspecialchars( $title->getPrefixedDBkey() );
131 return "<form action=\"$action\" method=\"get\">\n" .
133 Xml
::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
134 Html
::hidden( 'title', $special ) . " \n" .
135 $this->getNamespaceMenu( $namespace ) . " \n" .
136 $this->getLevelMenu( $level ) . " \n" .
137 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
138 "</fieldset></form>";
142 * Prepare the namespace filter drop-down; standard namespace
143 * selector, sans the MediaWiki namespace
145 * @param string|null $namespace Pre-select namespace
148 function getNamespaceMenu( $namespace = null ) {
149 return Html
::namespaceSelector(
151 'selected' => $namespace,
153 'label' => $this->msg( 'namespace' )->text()
155 'name' => 'namespace',
157 'class' => 'namespaceselector',
163 * @param string $pr_level Determines which option is selected as default
164 * @return string Formatted HTML
167 function getLevelMenu( $pr_level ) {
169 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
172 // First pass to load the log names
173 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
174 if ( $type != '' && $type != '*' ) {
175 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
176 $text = $this->msg( "restriction-level-$type" )->text();
181 // Is there only one level (aside from "all")?
182 if ( count( $m ) <= 2 ) {
185 // Third pass generates sorted XHTML content
186 foreach ( $m as $text => $type ) {
187 $selected = ( $type == $pr_level );
188 $options[] = Xml
::option( $text, $type, $selected );
191 return Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
193 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
194 implode( "\n", $options ) );
197 protected function getGroupName() {
198 return 'maintenance';
206 class ProtectedTitlesPager
extends AlphabeticPager
{
207 public $mForm, $mConds;
209 function __construct( $form, $conds = array(), $type, $level, $namespace,
210 $sizetype = '', $size = 0
212 $this->mForm
= $form;
213 $this->mConds
= $conds;
214 $this->level
= $level;
215 $this->namespace = $namespace;
216 $this->size
= intval( $size );
217 parent
::__construct( $form->getContext() );
220 function getStartBody() {
221 # Do a link batch query
222 $this->mResult
->seek( 0 );
225 foreach ( $this->mResult
as $row ) {
226 $lb->add( $row->pt_namespace
, $row->pt_title
);
237 function getTitle() {
238 return $this->mForm
->getTitle();
241 function formatRow( $row ) {
242 return $this->mForm
->formatRow( $row );
248 function getQueryInfo() {
249 $conds = $this->mConds
;
250 $conds[] = 'pt_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
251 ' OR pt_expiry IS NULL';
252 if ( $this->level
) {
253 $conds['pt_create_perm'] = $this->level
;
256 if ( !is_null( $this->namespace ) ) {
257 $conds[] = 'pt_namespace=' . $this->mDb
->addQuotes( $this->namespace );
261 'tables' => 'protected_titles',
262 'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
263 'pt_expiry', 'pt_timestamp' ),
268 function getIndexField() {
269 return 'pt_timestamp';