MediaWiki  master
SpecialProtectedtitles.php
Go to the documentation of this file.
1 <?php
30 
37  protected $IdLevel = 'level';
38  protected $IdType = 'type';
39 
41  private $linkBatchFactory;
42 
44  private $dbProvider;
45 
50  public function __construct(
51  LinkBatchFactory $linkBatchFactory,
52  IConnectionProvider $dbProvider
53  ) {
54  parent::__construct( 'Protectedtitles' );
55  $this->linkBatchFactory = $linkBatchFactory;
56  $this->dbProvider = $dbProvider;
57  }
58 
59  public function execute( $par ) {
60  $this->setHeaders();
61  $this->outputHeader();
62  $this->addHelpLink( 'Help:Protected_pages' );
63 
64  $request = $this->getRequest();
65  $type = $request->getVal( $this->IdType );
66  $level = $request->getVal( $this->IdLevel );
67  $sizetype = $request->getVal( 'sizetype' );
68  $size = $request->getIntOrNull( 'size' );
69  $NS = $request->getIntOrNull( 'namespace' );
70 
71  $pager = new ProtectedTitlesPager(
72  $this,
73  $this->linkBatchFactory,
74  $this->dbProvider,
75  [],
76  $type,
77  $level,
78  $NS,
79  $sizetype,
80  $size
81  );
82 
83  $this->getOutput()->addHTML( $this->showOptions() );
84 
85  if ( $pager->getNumRows() ) {
86  $this->getOutput()->addHTML(
87  $pager->getNavigationBar() .
88  '<ul>' . $pager->getBody() . '</ul>' .
89  $pager->getNavigationBar()
90  );
91  } else {
92  $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
93  }
94  }
95 
102  public function formatRow( $row ) {
103  $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
104  if ( !$title ) {
105  return Html::rawElement(
106  'li',
107  [],
108  Html::element(
109  'span',
110  [ 'class' => 'mw-invalidtitle' ],
111  Linker::getInvalidTitleDescription(
112  $this->getContext(),
113  $row->pt_namespace,
114  $row->pt_title
115  )
116  )
117  ) . "\n";
118  }
119 
120  $link = $this->getLinkRenderer()->makeLink( $title );
121  // Messages: restriction-level-sysop, restriction-level-autoconfirmed
122  $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
123  $lang = $this->getLanguage();
124  $expiry = strlen( $row->pt_expiry ) ?
125  $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
126  'infinity';
127 
128  if ( $expiry !== 'infinity' ) {
129  $user = $this->getUser();
130  $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
131  'protect-expiring-local',
132  $lang->userTimeAndDate( $expiry, $user ),
133  $lang->userDate( $expiry, $user ),
134  $lang->userTime( $expiry, $user )
135  )->escaped();
136  }
137 
138  return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
139  }
140 
144  private function showOptions() {
145  $formDescriptor = [
146  'namespace' => [
147  'class' => HTMLSelectNamespace::class,
148  'name' => 'namespace',
149  'id' => 'namespace',
150  'cssclass' => 'namespaceselector',
151  'all' => '',
152  'label' => $this->msg( 'namespace' )->text()
153  ],
154  'levelmenu' => $this->getLevelMenu()
155  ];
156 
157  $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
158  ->setMethod( 'get' )
159  ->setWrapperLegendMsg( 'protectedtitles' )
160  ->setSubmitTextMsg( 'protectedtitles-submit' );
161 
162  return $htmlForm->prepareForm()->getHTML( false );
163  }
164 
168  private function getLevelMenu() {
169  // Temporary array
170  $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
171  $options = [];
172 
173  // First pass to load the log names
174  foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
175  if ( $type != '' && $type != '*' ) {
176  // Messages: restriction-level-sysop, restriction-level-autoconfirmed
177  $text = $this->msg( "restriction-level-$type" )->text();
178  $m[$text] = $type;
179  }
180  }
181 
182  // Is there only one level (aside from "all")?
183  if ( count( $m ) <= 2 ) {
184  return '';
185  }
186  // Third pass generates sorted XHTML content
187  foreach ( $m as $text => $type ) {
188  $options[ $text ] = $type;
189  }
190 
191  return [
192  'type' => 'select',
193  'options' => $options,
194  'label' => $this->msg( 'restriction-level' )->text(),
195  'name' => $this->IdLevel,
196  'id' => $this->IdLevel
197  ];
198  }
199 
200  protected function getGroupName() {
201  return 'maintenance';
202  }
203 }
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:354
This class is a collection of static functions that serve two purposes:
Definition: Html.php:55
Some internal bits split of from Skin.php.
Definition: Linker.php:67
A class containing constants representing the names of configuration variables.
Represents a title within MediaWiki.
Definition: Title.php:82
Parent class for all special pages.
Definition: SpecialPage.php:45
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that list protected titles from creation.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
formatRow( $row)
Callback function to output a restriction.
__construct(LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider)
execute( $par)
Default execute method Checks user permissions.
Provide primary and replica IDatabase connections.
if(!isset( $args[0])) $lang