SpecialProtectedtitles.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Implements Special:Protectedtitles
  4. *
  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.
  9. *
  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.
  14. *
  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
  19. *
  20. * @file
  21. * @ingroup SpecialPage
  22. */
  23. /**
  24. * A special page that list protected titles from creation
  25. *
  26. * @ingroup SpecialPage
  27. */
  28. class SpecialProtectedtitles extends SpecialPage {
  29. protected $IdLevel = 'level';
  30. protected $IdType = 'type';
  31. public function __construct() {
  32. parent::__construct( 'Protectedtitles' );
  33. }
  34. function execute( $par ) {
  35. $this->setHeaders();
  36. $this->outputHeader();
  37. $this->addHelpLink( 'Help:Protected_pages' );
  38. $request = $this->getRequest();
  39. $type = $request->getVal( $this->IdType );
  40. $level = $request->getVal( $this->IdLevel );
  41. $sizetype = $request->getVal( 'sizetype' );
  42. $size = $request->getIntOrNull( 'size' );
  43. $NS = $request->getIntOrNull( 'namespace' );
  44. $pager = new ProtectedTitlesPager( $this, [], $type, $level, $NS, $sizetype, $size );
  45. $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
  46. if ( $pager->getNumRows() ) {
  47. $this->getOutput()->addHTML(
  48. $pager->getNavigationBar() .
  49. '<ul>' . $pager->getBody() . '</ul>' .
  50. $pager->getNavigationBar()
  51. );
  52. } else {
  53. $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
  54. }
  55. }
  56. /**
  57. * Callback function to output a restriction
  58. *
  59. * @param object $row Database row
  60. * @return string
  61. */
  62. function formatRow( $row ) {
  63. $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
  64. if ( !$title ) {
  65. return Html::rawElement(
  66. 'li',
  67. [],
  68. Html::element(
  69. 'span',
  70. [ 'class' => 'mw-invalidtitle' ],
  71. Linker::getInvalidTitleDescription(
  72. $this->getContext(),
  73. $row->pt_namespace,
  74. $row->pt_title
  75. )
  76. )
  77. ) . "\n";
  78. }
  79. $link = $this->getLinkRenderer()->makeLink( $title );
  80. // Messages: restriction-level-sysop, restriction-level-autoconfirmed
  81. $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
  82. $lang = $this->getLanguage();
  83. $expiry = strlen( $row->pt_expiry ) ?
  84. $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
  85. 'infinity';
  86. if ( $expiry !== 'infinity' ) {
  87. $user = $this->getUser();
  88. $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
  89. 'protect-expiring-local',
  90. $lang->userTimeAndDate( $expiry, $user ),
  91. $lang->userDate( $expiry, $user ),
  92. $lang->userTime( $expiry, $user )
  93. )->escaped();
  94. }
  95. return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
  96. }
  97. /**
  98. * @param int $namespace
  99. * @param string $type
  100. * @param string $level
  101. * @return string
  102. * @private
  103. */
  104. function showOptions( $namespace, $type, $level ) {
  105. $formDescriptor = [
  106. 'namespace' => [
  107. 'class' => 'HTMLSelectNamespace',
  108. 'name' => 'namespace',
  109. 'id' => 'namespace',
  110. 'cssclass' => 'namespaceselector',
  111. 'all' => '',
  112. 'label' => $this->msg( 'namespace' )->text()
  113. ],
  114. 'levelmenu' => $this->getLevelMenu( $level )
  115. ];
  116. $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
  117. $htmlForm
  118. ->setMethod( 'get' )
  119. ->setWrapperLegendMsg( 'protectedtitles' )
  120. ->setSubmitText( $this->msg( 'protectedtitles-submit' )->text() );
  121. return $htmlForm->prepareForm()->getHTML( false );
  122. }
  123. /**
  124. * @param string $pr_level Determines which option is selected as default
  125. * @return string|array
  126. * @private
  127. */
  128. function getLevelMenu( $pr_level ) {
  129. // Temporary array
  130. $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
  131. $options = [];
  132. // First pass to load the log names
  133. foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
  134. if ( $type != '' && $type != '*' ) {
  135. // Messages: restriction-level-sysop, restriction-level-autoconfirmed
  136. $text = $this->msg( "restriction-level-$type" )->text();
  137. $m[$text] = $type;
  138. }
  139. }
  140. // Is there only one level (aside from "all")?
  141. if ( count( $m ) <= 2 ) {
  142. return '';
  143. }
  144. // Third pass generates sorted XHTML content
  145. foreach ( $m as $text => $type ) {
  146. $options[ $text ] = $type;
  147. }
  148. return [
  149. 'type' => 'select',
  150. 'options' => $options,
  151. 'label' => $this->msg( 'restriction-level' )->text(),
  152. 'name' => $this->IdLevel,
  153. 'id' => $this->IdLevel
  154. ];
  155. }
  156. protected function getGroupName() {
  157. return 'maintenance';
  158. }
  159. }