SpecialProtectedpages.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * Implements Special:Protectedpages
  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 lists protected pages
  25. *
  26. * @ingroup SpecialPage
  27. */
  28. class SpecialProtectedpages extends SpecialPage {
  29. protected $IdLevel = 'level';
  30. protected $IdType = 'type';
  31. public function __construct() {
  32. parent::__construct( 'Protectedpages' );
  33. }
  34. public function execute( $par ) {
  35. $this->setHeaders();
  36. $this->outputHeader();
  37. $this->getOutput()->addModuleStyles( 'mediawiki.special' );
  38. $this->addHelpLink( 'Help:Protected_pages' );
  39. $request = $this->getRequest();
  40. $type = $request->getVal( $this->IdType );
  41. $level = $request->getVal( $this->IdLevel );
  42. $sizetype = $request->getVal( 'size-mode' );
  43. $size = $request->getIntOrNull( 'size' );
  44. $ns = $request->getIntOrNull( 'namespace' );
  45. $filters = $request->getArray( 'wpfilters', [] );
  46. $indefOnly = in_array( 'indefonly', $filters );
  47. $cascadeOnly = in_array( 'cascadeonly', $filters );
  48. $noRedirect = in_array( 'noredirect', $filters );
  49. $pager = new ProtectedPagesPager(
  50. $this,
  51. [],
  52. $type,
  53. $level,
  54. $ns,
  55. $sizetype,
  56. $size,
  57. $indefOnly,
  58. $cascadeOnly,
  59. $noRedirect,
  60. $this->getLinkRenderer()
  61. );
  62. $this->getOutput()->addHTML( $this->showOptions(
  63. $ns,
  64. $type,
  65. $level,
  66. $sizetype,
  67. $size,
  68. $filters
  69. ) );
  70. if ( $pager->getNumRows() ) {
  71. $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
  72. } else {
  73. $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
  74. }
  75. }
  76. /**
  77. * @param int $namespace
  78. * @param string $type Restriction type
  79. * @param string $level Restriction level
  80. * @param string $sizetype "min" or "max"
  81. * @param int $size
  82. * @param array $filters Filters set for the pager: indefOnly,
  83. * cascadeOnly, noRedirect
  84. * @return string Input form
  85. */
  86. protected function showOptions( $namespace, $type, $level, $sizetype,
  87. $size, $filters
  88. ) {
  89. $formDescriptor = [
  90. 'namespace' => [
  91. 'class' => HTMLSelectNamespace::class,
  92. 'name' => 'namespace',
  93. 'id' => 'namespace',
  94. 'cssclass' => 'namespaceselector',
  95. 'all' => '',
  96. 'label' => $this->msg( 'namespace' )->text(),
  97. ],
  98. 'typemenu' => $this->getTypeMenu( $type ),
  99. 'levelmenu' => $this->getLevelMenu( $level ),
  100. 'filters' => [
  101. 'class' => 'HTMLMultiSelectField',
  102. 'label' => $this->msg( 'protectedpages-filters' )->text(),
  103. 'flatlist' => true,
  104. 'options-messages' => [
  105. 'protectedpages-indef' => 'indefonly',
  106. 'protectedpages-cascade' => 'cascadeonly',
  107. 'protectedpages-noredirect' => 'noredirect',
  108. ],
  109. 'default' => $filters,
  110. ],
  111. 'sizelimit' => [
  112. 'class' => HTMLSizeFilterField::class,
  113. 'name' => 'size',
  114. ]
  115. ];
  116. $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
  117. $htmlForm
  118. ->setMethod( 'get' )
  119. ->setWrapperLegendMsg( 'protectedpages' )
  120. ->setSubmitText( $this->msg( 'protectedpages-submit' )->text() );
  121. return $htmlForm->prepareForm()->getHTML( false );
  122. }
  123. /**
  124. * Creates the input label of the restriction type
  125. * @param string $pr_type Protection type
  126. * @return array
  127. */
  128. protected function getTypeMenu( $pr_type ) {
  129. $m = []; // Temporary array
  130. $options = [];
  131. // First pass to load the log names
  132. foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
  133. // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
  134. $text = $this->msg( "restriction-$type" )->text();
  135. $m[$text] = $type;
  136. }
  137. // Third pass generates sorted XHTML content
  138. foreach ( $m as $text => $type ) {
  139. $options[$text] = $type;
  140. }
  141. return [
  142. 'type' => 'select',
  143. 'options' => $options,
  144. 'label' => $this->msg( 'restriction-type' )->text(),
  145. 'name' => $this->IdType,
  146. 'id' => $this->IdType,
  147. ];
  148. }
  149. /**
  150. * Creates the input label of the restriction level
  151. * @param string $pr_level Protection level
  152. * @return array
  153. */
  154. protected function getLevelMenu( $pr_level ) {
  155. // Temporary array
  156. $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
  157. $options = [];
  158. // First pass to load the log names
  159. foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
  160. // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
  161. if ( $type != '' && $type != '*' ) {
  162. $text = $this->msg( "restriction-level-$type" )->text();
  163. $m[$text] = $type;
  164. }
  165. }
  166. // Third pass generates sorted XHTML content
  167. foreach ( $m as $text => $type ) {
  168. $options[$text] = $type;
  169. }
  170. return [
  171. 'type' => 'select',
  172. 'options' => $options,
  173. 'label' => $this->msg( 'restriction-level' )->text(),
  174. 'name' => $this->IdLevel,
  175. 'id' => $this->IdLevel
  176. ];
  177. }
  178. protected function getGroupName() {
  179. return 'maintenance';
  180. }
  181. }