SpecialAllMessages.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Implements Special:Allmessages
  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. use MediaWiki\MediaWikiServices;
  24. /**
  25. * Use this special page to get a list of the MediaWiki system messages.
  26. *
  27. * @file
  28. * @ingroup SpecialPage
  29. */
  30. class SpecialAllMessages extends SpecialPage {
  31. public function __construct() {
  32. parent::__construct( 'Allmessages' );
  33. }
  34. /**
  35. * @param string|null $par Parameter passed to the page or null
  36. */
  37. public function execute( $par ) {
  38. $out = $this->getOutput();
  39. $this->setHeaders();
  40. if ( !$this->getConfig()->get( 'UseDatabaseMessages' ) ) {
  41. $out->addWikiMsg( 'allmessages-not-supported-database' );
  42. return;
  43. }
  44. $out->addModuleStyles( 'mediawiki.special' );
  45. $this->addHelpLink( 'Help:System message' );
  46. $contLang = MediaWikiServices::getInstance()->getContentLanguage()->getCode();
  47. $lang = $this->getLanguage();
  48. $opts = new FormOptions();
  49. $opts->add( 'prefix', '' );
  50. $opts->add( 'filter', 'all' );
  51. $opts->add( 'lang', $contLang );
  52. $opts->add( 'limit', 50 );
  53. $opts->fetchValuesFromRequest( $this->getRequest() );
  54. $opts->validateIntBounds( 'limit', 0, 5000 );
  55. $pager = new AllMessagesTablePager( $this->getContext(), $opts, $this->getLinkRenderer() );
  56. $formDescriptor = [
  57. 'prefix' => [
  58. 'type' => 'text',
  59. 'name' => 'prefix',
  60. 'label-message' => 'allmessages-prefix',
  61. ],
  62. 'filter' => [
  63. 'type' => 'radio',
  64. 'name' => 'filter',
  65. 'label-message' => 'allmessages-filter',
  66. 'options-messages' => [
  67. 'allmessages-filter-unmodified' => 'unmodified',
  68. 'allmessages-filter-all' => 'all',
  69. 'allmessages-filter-modified' => 'modified',
  70. ],
  71. 'default' => 'all',
  72. 'flatlist' => true,
  73. ],
  74. 'lang' => [
  75. 'type' => 'language',
  76. 'name' => 'lang',
  77. 'label-message' => 'allmessages-language',
  78. 'default' => $opts->getValue( 'lang' ),
  79. ],
  80. 'limit' => [
  81. 'type' => 'limitselect',
  82. 'name' => 'limit',
  83. 'label-message' => 'table_pager_limit_label',
  84. 'options' => [
  85. $lang->formatNum( 20 ) => 20,
  86. $lang->formatNum( 50 ) => 50,
  87. $lang->formatNum( 100 ) => 100,
  88. $lang->formatNum( 250 ) => 250,
  89. $lang->formatNum( 500 ) => 500,
  90. $lang->formatNum( 5000 ) => 5000,
  91. ],
  92. 'default' => $opts->getValue( 'limit' ),
  93. ],
  94. ];
  95. $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
  96. $htmlForm
  97. ->setMethod( 'get' )
  98. ->setIntro( $this->msg( 'allmessagestext' ) )
  99. ->setWrapperLegendMsg( 'allmessages' )
  100. ->setSubmitTextMsg( 'allmessages-filter-submit' )
  101. ->prepareForm()
  102. ->displayForm( false );
  103. $out->addParserOutputContent( $pager->getFullOutput() );
  104. }
  105. protected function getGroupName() {
  106. return 'wiki';
  107. }
  108. }