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