MediaWiki  master
SpecialNewFiles.php
Go to the documentation of this file.
1 <?php
27 
30  protected $opts;
31 
33  protected $mediaTypes;
34 
37 
39  private $loadBalancer;
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();
153  }, $this->mediaTypes );
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 }
SpecialNewFiles\buildForm
buildForm(IContextSource $context)
Definition: SpecialNewFiles.php:144
DerivativeRequest
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Definition: DerivativeRequest.php:36
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
MediaWiki\Permissions\GroupPermissionsLookup
Definition: GroupPermissionsLookup.php:30
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:182
MimeAnalyzer
Implements functions related to MIME types such as detection and mapping to file extension.
Definition: MimeAnalyzer.php:33
SpecialNewFiles\$mediaTypes
string[] $mediaTypes
Definition: SpecialNewFiles.php:33
SpecialNewFiles\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialNewFiles.php:42
SpecialNewFiles
Definition: SpecialNewFiles.php:28
IncludableSpecialPage
Shortcut to construct an includable special page.
Definition: IncludableSpecialPage.php:29
FormOptions\validateIntBounds
validateIntBounds( $name, $min, $max)
Definition: FormOptions.php:255
FormOptions\fetchValuesFromRequest
fetchValuesFromRequest(WebRequest $r, $optionKeys=null)
Fetch values for all options (or selected options) from the given WebRequest, making them available f...
Definition: FormOptions.php:346
SpecialNewFiles\setTopText
setTopText()
Send the text to be displayed above the options.
Definition: SpecialNewFiles.php:241
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:83
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:948
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:32
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:878
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:618
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:800
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
FormOptions\setValue
setValue( $name, $value, $force=false)
Use to set the value of an option.
Definition: FormOptions.php:165
SpecialNewFiles\$opts
FormOptions $opts
Definition: SpecialNewFiles.php:30
SpecialNewFiles\$groupPermissionsLookup
GroupPermissionsLookup $groupPermissionsLookup
Definition: SpecialNewFiles.php:36
MimeAnalyzer\getMediaTypes
getMediaTypes()
Returns an array of media types (MEDIATYPE_xxx constants)
Definition: MimeAnalyzer.php:1121
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:780
SpecialNewFiles\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialNewFiles.php:234
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialPage\getContentLanguage
getContentLanguage()
Shortcut to get content language.
Definition: SpecialPage.php:840
SpecialNewFiles\__construct
__construct(MimeAnalyzer $mimeAnalyzer, GroupPermissionsLookup $groupPermissionsLookup, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
Definition: SpecialNewFiles.php:50
SpecialNewFiles\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialNewFiles.php:63
SpecialNewFiles\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialNewFiles.php:39
NewFilesPager
Definition: NewFilesPager.php:30
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:326
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:709
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:266
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
$type
$type
Definition: testCompression.php:52