Merge "Add some common functions to BaseTemplate"
[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 /** @var FormOptions */
26 protected $opts;
27
28 public function __construct() {
29 parent::__construct( 'Newimages' );
30 }
31
32 public function execute( $par ) {
33 $this->setHeaders();
34 $this->outputHeader();
35
36 $out = $this->getOutput();
37 $this->addHelpLink( 'Help:New images' );
38
39 $opts = new FormOptions();
40
41 $opts->add( 'like', '' );
42 $opts->add( 'user', '' );
43 $opts->add( 'showbots', false );
44 $opts->add( 'hidepatrolled', false );
45 $opts->add( 'limit', 50 );
46 $opts->add( 'offset', '' );
47
48 $opts->fetchValuesFromRequest( $this->getRequest() );
49
50 if ( $par !== null ) {
51 $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par );
52 }
53
54 $opts->validateIntBounds( 'limit', 0, 500 );
55
56 $this->opts = $opts;
57
58 if ( !$this->including() ) {
59 $this->setTopText();
60 $this->buildForm();
61 }
62
63 $pager = new NewFilesPager( $this->getContext(), $opts );
64
65 $out->addHTML( $pager->getBody() );
66 if ( !$this->including() ) {
67 $out->addHTML( $pager->getNavigationBar() );
68 }
69 }
70
71 protected function buildForm() {
72 $formDescriptor = [
73 'like' => [
74 'type' => 'text',
75 'label-message' => 'newimages-label',
76 'name' => 'like',
77 ],
78
79 'user' => [
80 'type' => 'text',
81 'label-message' => 'newimages-user',
82 'name' => 'user',
83 ],
84
85 'showbots' => [
86 'type' => 'check',
87 'label-message' => 'newimages-showbots',
88 'name' => 'showbots',
89 ],
90
91 'hidepatrolled' => [
92 'type' => 'check',
93 'label-message' => 'newimages-hidepatrolled',
94 'name' => 'hidepatrolled',
95 ],
96
97 'limit' => [
98 'type' => 'hidden',
99 'default' => $this->opts->getValue( 'limit' ),
100 'name' => 'limit',
101 ],
102
103 'offset' => [
104 'type' => 'hidden',
105 'default' => $this->opts->getValue( 'offset' ),
106 'name' => 'offset',
107 ],
108 ];
109
110 if ( $this->getConfig()->get( 'MiserMode' ) ) {
111 unset( $formDescriptor['like'] );
112 }
113
114 if ( !$this->getUser()->useFilePatrol() ) {
115 unset( $formDescriptor['hidepatrolled'] );
116 }
117
118 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
119 ->setWrapperLegendMsg( 'newimages-legend' )
120 ->setSubmitTextMsg( 'ilsubmit' )
121 ->setMethod( 'get' )
122 ->prepareForm()
123 ->displayForm( false );
124 }
125
126 protected function getGroupName() {
127 return 'changes';
128 }
129
130 /**
131 * Send the text to be displayed above the options
132 */
133 function setTopText() {
134 global $wgContLang;
135
136 $message = $this->msg( 'newimagestext' )->inContentLanguage();
137 if ( !$message->isDisabled() ) {
138 $this->getOutput()->addWikiText(
139 Html::rawElement( 'p',
140 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
141 "\n" . $message->plain() . "\n"
142 ),
143 /* $lineStart */ false,
144 /* $interface */ false
145 );
146 }
147 }
148 }