Merge "Convert Special:NewFiles to use OOUI."
[lhc/web/wiklou.git] / includes / specials / SpecialNewimages.php
1 <?php
2 /**
3 * Implements Special:Newimages
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 class SpecialNewFiles extends IncludableSpecialPage {
25 public function __construct() {
26 parent::__construct( 'Newimages' );
27 }
28
29 public function execute( $par ) {
30 $this->setHeaders();
31 $this->outputHeader();
32
33 $out = $this->getOutput();
34 $this->addHelpLink( 'Help:New images' );
35
36 $opts = new FormOptions();
37
38 $opts->add( 'like', '' );
39 $opts->add( 'showbots', false );
40 $opts->add( 'hidepatrolled', false );
41 $opts->add( 'limit', 50 );
42 $opts->add( 'offset', 0 );
43
44 $opts->fetchValuesFromRequest( $this->getRequest() );
45
46 if ( $par !== null ) {
47 $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par );
48 }
49
50 $opts->validateIntBounds( 'limit', 0, 500 );
51
52 $this->opts = $opts;
53
54 if ( !$this->including() ) {
55 $this->buildForm();
56 }
57
58 $pager = new NewFilesPager( $this->getContext(), $opts );
59
60 $out->addHTML( $pager->getBody() );
61 if ( !$this->including() ) {
62 $out->addHTML( $pager->getNavigationBar() );
63 }
64 }
65
66 protected function buildForm() {
67 $formDescriptor = [
68 'like' => [
69 'type' => 'text',
70 'label-message' => 'newimages-label',
71 'name' => 'like',
72 ],
73
74 'showbots' => [
75 'type' => 'check',
76 'label-message' => 'newimages-showbots',
77 'name' => 'showbots',
78 ],
79
80 'hidepatrolled' => [
81 'type' => 'check',
82 'label-message' => 'newimages-hidepatrolled',
83 'name' => 'hidepatrolled',
84 ],
85 ];
86
87 if ( $this->getConfig()->get( 'MiserMode' ) ) {
88 unset( $formDescriptor['like'] );
89 }
90
91 if ( !$this->getUser()->useFilePatrol() ) {
92 unset( $formDescriptor['hidepatrolled'] );
93 }
94
95 $form = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
96 ->setWrapperLegendMsg( 'newimages-legend' )
97 ->setSubmitTextMsg( 'ilsubmit' )
98 ->setMethod( 'get' )
99 ->prepareForm()
100 ->displayForm( false );
101 }
102
103 protected function getGroupName() {
104 return 'changes';
105 }
106
107 /**
108 * Send the text to be displayed above the options
109 */
110 function setTopText() {
111 global $wgContLang;
112
113 $message = $this->msg( 'newimagestext' )->inContentLanguage();
114 if ( !$message->isDisabled() ) {
115 $this->getOutput()->addWikiText(
116 Html::rawElement( 'p',
117 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
118 "\n" . $message->plain() . "\n"
119 ),
120 /* $lineStart */ false,
121 /* $interface */ false
122 );
123 }
124 }
125 }