MediaWiki REL1_37
SpecialNewFiles.php
Go to the documentation of this file.
1<?php
27
30 protected $opts;
31
33 protected $mediaTypes;
34
37
40
43
50 public function __construct(
51 MimeAnalyzer $mimeAnalyzer,
55 ) {
56 parent::__construct( 'Newimages' );
57 $this->groupPermissionsLookup = $groupPermissionsLookup;
58 $this->loadBalancer = $loadBalancer;
59 $this->mediaTypes = $mimeAnalyzer->getMediaTypes();
60 $this->linkBatchFactory = $linkBatchFactory;
61 }
62
63 public function execute( $par ) {
64 $context = new DerivativeContext( $this->getContext() );
65
66 $this->setHeaders();
67 $this->outputHeader();
68
69 $out = $this->getOutput();
70 $this->addHelpLink( 'Help:New images' );
71
72 $opts = new FormOptions();
73
74 $opts->add( 'like', '' );
75 $opts->add( 'user', '' );
76 $opts->add( 'showbots', false );
77 $opts->add( 'hidepatrolled', false );
78 $opts->add( 'mediatype', $this->mediaTypes );
79 $opts->add( 'limit', 50 );
80 $opts->add( 'offset', '' );
81 $opts->add( 'start', '' );
82 $opts->add( 'end', '' );
83
85
86 if ( $par !== null ) {
87 $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par );
88 }
89
90 // If start date comes after end date chronologically, swap them.
91 // They are swapped in the interface by JS.
92 $start = $opts->getValue( 'start' );
93 $end = $opts->getValue( 'end' );
94 if ( $start !== '' && $end !== '' && $start > $end ) {
95 $temp = $end;
96 $end = $start;
97 $start = $temp;
98
99 $opts->setValue( 'start', $start, true );
100 $opts->setValue( 'end', $end, true );
101
102 // also swap values in request object, which is used by HTMLForm
103 // to pre-populate the fields with the previous input
104 $request = $context->getRequest();
105 $context->setRequest( new DerivativeRequest(
106 $request,
107 [ 'start' => $start, 'end' => $end ] + $request->getValues(),
108 $request->wasPosted()
109 ) );
110 }
111
112 // if all media types have been selected, wipe out the array to prevent
113 // the pointless IN(...) query condition (which would have no effect
114 // because every possible type has been selected)
115 $missingMediaTypes = array_diff( $this->mediaTypes, $opts->getValue( 'mediatype' ) );
116 if ( empty( $missingMediaTypes ) ) {
117 $opts->setValue( 'mediatype', [] );
118 }
119
120 $opts->validateIntBounds( 'limit', 0, 500 );
121
122 $this->opts = $opts;
123
124 if ( !$this->including() ) {
125 $this->setTopText();
126 $this->buildForm( $context );
127 }
128
129 $pager = new NewFilesPager(
130 $context,
131 $opts,
132 $this->getLinkRenderer(),
133 $this->groupPermissionsLookup,
134 $this->loadBalancer,
135 $this->linkBatchFactory
136 );
137
138 $out->addHTML( $pager->getBody() );
139 if ( !$this->including() ) {
140 $out->addHTML( $pager->getNavigationBar() );
141 }
142 }
143
144 protected function buildForm( IContextSource $context ) {
145 $mediaTypesText = array_map( function ( $type ) {
146 // mediastatistics-header-unknown, mediastatistics-header-bitmap,
147 // mediastatistics-header-drawing, mediastatistics-header-audio,
148 // mediastatistics-header-video, mediastatistics-header-multimedia,
149 // mediastatistics-header-office, mediastatistics-header-text,
150 // mediastatistics-header-executable, mediastatistics-header-archive,
151 // mediastatistics-header-3d,
152 return $this->msg( 'mediastatistics-header-' . strtolower( $type ) )->escaped();
154 $mediaTypesOptions = array_combine( $mediaTypesText, $this->mediaTypes );
155 ksort( $mediaTypesOptions );
156
157 $formDescriptor = [
158 'like' => [
159 'type' => 'text',
160 'label-message' => 'newimages-label',
161 'name' => 'like',
162 ],
163
164 'user' => [
165 'class' => HTMLUserTextField::class,
166 'label-message' => 'newimages-user',
167 'name' => 'user',
168 ],
169
170 'showbots' => [
171 'type' => 'check',
172 'label-message' => 'newimages-showbots',
173 'name' => 'showbots',
174 ],
175
176 'hidepatrolled' => [
177 'type' => 'check',
178 'label-message' => 'newimages-hidepatrolled',
179 'name' => 'hidepatrolled',
180 ],
181
182 'mediatype' => [
183 'type' => 'multiselect',
184 'flatlist' => true,
185 'name' => 'mediatype',
186 'label-message' => 'newimages-mediatype',
187 'options' => $mediaTypesOptions,
188 'default' => $this->mediaTypes,
189 ],
190
191 'limit' => [
192 'type' => 'hidden',
193 'default' => $this->opts->getValue( 'limit' ),
194 'name' => 'limit',
195 ],
196
197 'offset' => [
198 'type' => 'hidden',
199 'default' => $this->opts->getValue( 'offset' ),
200 'name' => 'offset',
201 ],
202
203 'start' => [
204 'type' => 'date',
205 'label-message' => 'date-range-from',
206 'name' => 'start',
207 ],
208
209 'end' => [
210 'type' => 'date',
211 'label-message' => 'date-range-to',
212 'name' => 'end',
213 ],
214 ];
215
216 if ( $this->getConfig()->get( 'MiserMode' ) ) {
217 unset( $formDescriptor['like'] );
218 }
219
220 if ( !$this->getUser()->useFilePatrol() ) {
221 unset( $formDescriptor['hidepatrolled'] );
222 }
223
224 HTMLForm::factory( 'ooui', $formDescriptor, $context )
225 // For the 'multiselect' field values to be preserved on submit
226 ->setFormIdentifier( 'specialnewimages' )
227 ->setWrapperLegendMsg( 'newimages-legend' )
228 ->setSubmitTextMsg( 'ilsubmit' )
229 ->setMethod( 'get' )
230 ->prepareForm()
231 ->displayForm( false );
232 }
233
234 protected function getGroupName() {
235 return 'changes';
236 }
237
241 public function setTopText() {
242 $message = $this->msg( 'newimagestext' )->inContentLanguage();
243 if ( !$message->isDisabled() ) {
244 $contLang = $this->getContentLanguage();
245 $this->getOutput()->addWikiTextAsContent(
246 Html::rawElement( 'div',
247 [
248 'lang' => $contLang->getHtmlCode(),
249 'dir' => $contLang->getDir()
250 ],
251 "\n" . $message->plain() . "\n"
252 )
253 );
254 }
255 }
256}
An IContextSource implementation which will inherit context from another source but allow individual ...
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Helper class to keep track of options when mixing links and form elements.
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
setValue( $name, $value, $force=false)
Use to set the value of an option.
fetchValuesFromRequest(WebRequest $r, $optionKeys=null)
Fetch values for all options (or selected options) from the given WebRequest, making them available f...
validateIntBounds( $name, $min, $max)
getValue( $name)
Get the value for the given option name.
Shortcut to construct an includable special page.
buildForm(IContextSource $context)
execute( $par)
Default execute method Checks user permissions.
ILoadBalancer $loadBalancer
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
GroupPermissionsLookup $groupPermissionsLookup
__construct(MimeAnalyzer $mimeAnalyzer, GroupPermissionsLookup $groupPermissionsLookup, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
setTopText()
Send the text to be displayed above the options.
LinkBatchFactory $linkBatchFactory
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getContentLanguage()
Shortcut to get content language.
including( $x=null)
Whether the special page is being evaluated via transclusion.
Interface for objects which can provide a MediaWiki context on request.
Database cluster connection, tracking, load balancing, and transaction manager interface.