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 public function __construct() {
32 parent
::__construct( 'Protectedtitles' );
35 function execute( $par ) {
37 $this->outputHeader();
39 // Purge expired entries on one in every 10 queries
40 if ( !mt_rand( 0, 10 ) ) {
41 Title
::purgeExpiredRestrictions();
44 $pager = new ProtectedTitlesPager( $this );
45 $this->getOutput()->addHTML( $pager->buildHTMLForm() );
47 if ( $pager->getNumRows() ) {
48 $s = $pager->getNavigationBar();
52 $s .= $pager->getNavigationBar();
54 $s = '<p>' . wfMsgHtml( 'protectedtitlesempty' ) . '</p>';
56 $this->getOutput()->addHTML( $s );
60 * Callback function to output a restriction
65 function formatRow( $row ) {
66 wfProfileIn( __METHOD__
);
68 static $infinity = null;
70 if( is_null( $infinity ) ){
71 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
74 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
75 $link = Linker
::link( $title );
77 $description_items = array ();
79 $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm
);
81 $description_items[] = $protType;
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 )
93 $description_items[] = htmlspecialchars($expiry_description);
96 wfProfileOut( __METHOD__
);
98 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
106 class ProtectedTitlesPager
extends AlphabeticPager
{
108 * @var SpecialProtectedtitles
118 * @param $form SpecialProtectedtitles
119 * @param $conds array
121 function __construct( $form, $conds = array() ) {
122 $this->mForm
= $form;
123 $this->mConds
= $conds;
124 parent
::__construct( $form->getContext() );
127 function getStartBody() {
128 wfProfileIn( __METHOD__
);
129 # Do a link batch query
130 $this->mResult
->seek( 0 );
133 foreach ( $this->mResult
as $row ) {
134 $lb->add( $row->pt_namespace
, $row->pt_title
);
138 wfProfileOut( __METHOD__
);
145 function getTitle() {
146 return SpecialPage
::getTitleFor( 'Protectedtitles' );
149 function formatRow( $row ) {
150 return $this->mForm
->formatRow( $row );
156 function getQueryInfo() {
157 $conds = $this->mConds
;
158 $conds[] = 'pt_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
160 if ( $this->mHTMLForm
->getVal( 'Level' ) ) {
161 $conds['pt_create_perm'] = $this->mHTMLForm
->getVal( 'Level' );
163 if ( $this->mHTMLForm
->getVal( 'Namespace' ) !== '' ) {
164 $conds['pt_namespace'] = $this->mHTMLForm
->getVal( 'Namespace' );
168 'tables' => 'protected_titles',
169 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
174 function getIndexField() {
175 return 'pt_timestamp';
178 protected function getHTMLFormFields() {
180 'Namespace' => array(
181 'type' => 'namespaces',
182 'label-message' => 'namespace',
185 'type' => 'restrictionlevels',
186 'label-message' => 'restriction-level',
191 protected function getHTMLFormSubmit() {
192 return 'allpagessubmit';
195 protected function getHTMLFormLegend() {
196 return 'protectedtitles';