MediaWiki  master
SpecialProtectedtitles.php
Go to the documentation of this file.
1 <?php
26 
33  protected $IdLevel = 'level';
34  protected $IdType = 'type';
35 
38 
40  private $loadBalancer;
41 
46  public function __construct(
49  ) {
50  parent::__construct( 'Protectedtitles' );
51  $this->linkBatchFactory = $linkBatchFactory;
52  $this->loadBalancer = $loadBalancer;
53  }
54 
55  public function execute( $par ) {
56  $this->setHeaders();
57  $this->outputHeader();
58  $this->addHelpLink( 'Help:Protected_pages' );
59 
60  $request = $this->getRequest();
61  $type = $request->getVal( $this->IdType );
62  $level = $request->getVal( $this->IdLevel );
63  $sizetype = $request->getVal( 'sizetype' );
64  $size = $request->getIntOrNull( 'size' );
65  $NS = $request->getIntOrNull( 'namespace' );
66 
67  $pager = new ProtectedTitlesPager(
68  $this,
69  [],
70  $type,
71  $level,
72  $NS,
73  $sizetype,
74  $size,
75  $this->linkBatchFactory,
76  $this->loadBalancer
77  );
78 
79  $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
80 
81  if ( $pager->getNumRows() ) {
82  $this->getOutput()->addHTML(
83  $pager->getNavigationBar() .
84  '<ul>' . $pager->getBody() . '</ul>' .
85  $pager->getNavigationBar()
86  );
87  } else {
88  $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
89  }
90  }
91 
98  public function formatRow( $row ) {
99  $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
100  if ( !$title ) {
101  return Html::rawElement(
102  'li',
103  [],
105  'span',
106  [ 'class' => 'mw-invalidtitle' ],
108  $this->getContext(),
109  $row->pt_namespace,
110  $row->pt_title
111  )
112  )
113  ) . "\n";
114  }
115 
116  $link = $this->getLinkRenderer()->makeLink( $title );
117  // Messages: restriction-level-sysop, restriction-level-autoconfirmed
118  $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
119  $lang = $this->getLanguage();
120  $expiry = strlen( $row->pt_expiry ) ?
121  $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
122  'infinity';
123 
124  if ( $expiry !== 'infinity' ) {
125  $user = $this->getUser();
126  $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
127  'protect-expiring-local',
128  $lang->userTimeAndDate( $expiry, $user ),
129  $lang->userDate( $expiry, $user ),
130  $lang->userTime( $expiry, $user )
131  )->escaped();
132  }
133 
134  return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
135  }
136 
144  private function showOptions( $namespace, $type, $level ) {
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( $level )
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 
170  private function getLevelMenu( $pr_level ) {
171  // Temporary array
172  $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
173  $options = [];
174 
175  // First pass to load the log names
176  foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
177  if ( $type != '' && $type != '*' ) {
178  // Messages: restriction-level-sysop, restriction-level-autoconfirmed
179  $text = $this->msg( "restriction-level-$type" )->text();
180  $m[$text] = $type;
181  }
182  }
183 
184  // Is there only one level (aside from "all")?
185  if ( count( $m ) <= 2 ) {
186  return '';
187  }
188  // Third pass generates sorted XHTML content
189  foreach ( $m as $text => $type ) {
190  $options[ $text ] = $type;
191  }
192 
193  return [
194  'type' => 'select',
195  'options' => $options,
196  'label' => $this->msg( 'restriction-level' )->text(),
197  'name' => $this->IdLevel,
198  'id' => $this->IdLevel
199  ];
200  }
201 
202  protected function getGroupName() {
203  return 'maintenance';
204  }
205 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
SpecialProtectedtitles\$IdLevel
$IdLevel
Definition: SpecialProtectedtitles.php:33
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
SpecialProtectedtitles
A special page that list protected titles from creation.
Definition: SpecialProtectedtitles.php:32
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:185
SpecialProtectedtitles\__construct
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer)
Definition: SpecialProtectedtitles.php:46
SpecialProtectedtitles\formatRow
formatRow( $row)
Callback function to output a restriction.
Definition: SpecialProtectedtitles.php:98
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:948
SpecialProtectedtitles\$IdType
$IdType
Definition: SpecialProtectedtitles.php:34
SpecialProtectedtitles\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialProtectedtitles.php:202
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:878
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialProtectedtitles\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialProtectedtitles.php:55
$title
$title
Definition: testCompression.php:38
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:618
SpecialProtectedtitles\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialProtectedtitles.php:37
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:800
SpecialProtectedtitles\showOptions
showOptions( $namespace, $type, $level)
Definition: SpecialProtectedtitles.php:144
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
SpecialProtectedtitles\getLevelMenu
getLevelMenu( $pr_level)
Definition: SpecialProtectedtitles.php:170
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:677
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:43
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:780
ProtectedTitlesPager
Definition: ProtectedTitlesPager.php:28
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
SpecialProtectedtitles\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialProtectedtitles.php:40
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:326
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:709
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
$type
$type
Definition: testCompression.php:52