MediaWiki  1.34.0
SpecialProtectedtitles.php
Go to the documentation of this file.
1 <?php
30  protected $IdLevel = 'level';
31  protected $IdType = 'type';
32 
33  public function __construct() {
34  parent::__construct( 'Protectedtitles' );
35  }
36 
37  function execute( $par ) {
38  $this->setHeaders();
39  $this->outputHeader();
40  $this->addHelpLink( 'Help:Protected_pages' );
41 
42  $request = $this->getRequest();
43  $type = $request->getVal( $this->IdType );
44  $level = $request->getVal( $this->IdLevel );
45  $sizetype = $request->getVal( 'sizetype' );
46  $size = $request->getIntOrNull( 'size' );
47  $NS = $request->getIntOrNull( 'namespace' );
48 
49  $pager = new ProtectedTitlesPager( $this, [], $type, $level, $NS, $sizetype, $size );
50 
51  $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
52 
53  if ( $pager->getNumRows() ) {
54  $this->getOutput()->addHTML(
55  $pager->getNavigationBar() .
56  '<ul>' . $pager->getBody() . '</ul>' .
57  $pager->getNavigationBar()
58  );
59  } else {
60  $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
61  }
62  }
63 
70  function formatRow( $row ) {
71  $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
72  if ( !$title ) {
73  return Html::rawElement(
74  'li',
75  [],
76  Html::element(
77  'span',
78  [ 'class' => 'mw-invalidtitle' ],
80  $this->getContext(),
81  $row->pt_namespace,
82  $row->pt_title
83  )
84  )
85  ) . "\n";
86  }
87 
88  $link = $this->getLinkRenderer()->makeLink( $title );
89  // Messages: restriction-level-sysop, restriction-level-autoconfirmed
90  $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
91  $lang = $this->getLanguage();
92  $expiry = strlen( $row->pt_expiry ) ?
93  $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
94  'infinity';
95 
96  if ( $expiry !== 'infinity' ) {
97  $user = $this->getUser();
98  $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
99  'protect-expiring-local',
100  $lang->userTimeAndDate( $expiry, $user ),
101  $lang->userDate( $expiry, $user ),
102  $lang->userTime( $expiry, $user )
103  )->escaped();
104  }
105 
106  return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
107  }
108 
116  function showOptions( $namespace, $type, $level ) {
117  $formDescriptor = [
118  'namespace' => [
119  'class' => 'HTMLSelectNamespace',
120  'name' => 'namespace',
121  'id' => 'namespace',
122  'cssclass' => 'namespaceselector',
123  'all' => '',
124  'label' => $this->msg( 'namespace' )->text()
125  ],
126  'levelmenu' => $this->getLevelMenu( $level )
127  ];
128 
129  $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
130  $htmlForm
131  ->setMethod( 'get' )
132  ->setWrapperLegendMsg( 'protectedtitles' )
133  ->setSubmitText( $this->msg( 'protectedtitles-submit' )->text() );
134 
135  return $htmlForm->prepareForm()->getHTML( false );
136  }
137 
143  function getLevelMenu( $pr_level ) {
144  // Temporary array
145  $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
146  $options = [];
147 
148  // First pass to load the log names
149  foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
150  if ( $type != '' && $type != '*' ) {
151  // Messages: restriction-level-sysop, restriction-level-autoconfirmed
152  $text = $this->msg( "restriction-level-$type" )->text();
153  $m[$text] = $type;
154  }
155  }
156 
157  // Is there only one level (aside from "all")?
158  if ( count( $m ) <= 2 ) {
159  return '';
160  }
161  // Third pass generates sorted XHTML content
162  foreach ( $m as $text => $type ) {
163  $options[ $text ] = $type;
164  }
165 
166  return [
167  'type' => 'select',
168  'options' => $options,
169  'label' => $this->msg( 'restriction-level' )->text(),
170  'name' => $this->IdLevel,
171  'id' => $this->IdLevel
172  ];
173  }
174 
175  protected function getGroupName() {
176  return 'maintenance';
177  }
178 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:792
SpecialProtectedtitles\$IdLevel
$IdLevel
Definition: SpecialProtectedtitles.php:30
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:719
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
SpecialProtectedtitles\__construct
__construct()
Definition: SpecialProtectedtitles.php:33
SpecialProtectedtitles
A special page that list protected titles from creation.
Definition: SpecialProtectedtitles.php:29
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:749
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:187
SpecialProtectedtitles\formatRow
formatRow( $row)
Callback function to output a restriction.
Definition: SpecialProtectedtitles.php:70
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:828
SpecialProtectedtitles\$IdType
$IdType
Definition: SpecialProtectedtitles.php:31
SpecialProtectedtitles\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialProtectedtitles.php:175
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:758
SpecialProtectedtitles\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialProtectedtitles.php:37
$title
$title
Definition: testCompression.php:34
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:537
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:729
SpecialProtectedtitles\showOptions
showOptions( $namespace, $type, $level)
Definition: SpecialProtectedtitles.php:116
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:692
SpecialProtectedtitles\getLevelMenu
getLevelMenu( $pr_level)
Definition: SpecialProtectedtitles.php:143
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:613
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:37
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:709
ProtectedTitlesPager
Definition: ProtectedTitlesPager.php:25
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:904
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:303
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:639
$type
$type
Definition: testCompression.php:48