MediaWiki  1.30.0
SpecialNewimages.php
Go to the documentation of this file.
1 <?php
26  protected $opts;
27 
29  protected $mediaTypes;
30 
31  public function __construct() {
32  parent::__construct( 'Newimages' );
33  }
34 
35  public function execute( $par ) {
36  $context = new DerivativeContext( $this->getContext() );
37 
38  $this->setHeaders();
39  $this->outputHeader();
40  $mimeAnalyzer = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
41  $this->mediaTypes = $mimeAnalyzer->getMediaTypes();
42 
43  $out = $this->getOutput();
44  $this->addHelpLink( 'Help:New images' );
45 
46  $opts = new FormOptions();
47 
48  $opts->add( 'like', '' );
49  $opts->add( 'user', '' );
50  $opts->add( 'showbots', false );
51  $opts->add( 'newbies', false );
52  $opts->add( 'hidepatrolled', false );
53  $opts->add( 'mediatype', $this->mediaTypes );
54  $opts->add( 'limit', 50 );
55  $opts->add( 'offset', '' );
56  $opts->add( 'start', '' );
57  $opts->add( 'end', '' );
58 
60 
61  if ( $par !== null ) {
62  $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par );
63  }
64 
65  // If start date comes after end date chronologically, swap them.
66  // They are swapped in the interface by JS.
67  $start = $opts->getValue( 'start' );
68  $end = $opts->getValue( 'end' );
69  if ( $start !== '' && $end !== '' && $start > $end ) {
70  $temp = $end;
71  $end = $start;
72  $start = $temp;
73 
74  $opts->setValue( 'start', $start, true );
75  $opts->setValue( 'end', $end, true );
76 
77  // also swap values in request object, which is used by HTMLForm
78  // to pre-populate the fields with the previous input
79  $request = $context->getRequest();
80  $context->setRequest( new DerivativeRequest(
81  $request,
82  [ 'start' => $start, 'end' => $end ] + $request->getValues(),
83  $request->wasPosted()
84  ) );
85  }
86 
87  // if all media types have been selected, wipe out the array to prevent
88  // the pointless IN(...) query condition (which would have no effect
89  // because every possible type has been selected)
90  $missingMediaTypes = array_diff( $this->mediaTypes, $opts->getValue( 'mediatype' ) );
91  if ( empty( $missingMediaTypes ) ) {
92  $opts->setValue( 'mediatype', [] );
93  }
94 
95  $opts->validateIntBounds( 'limit', 0, 500 );
96 
97  $this->opts = $opts;
98 
99  if ( !$this->including() ) {
100  $this->setTopText();
101  $this->buildForm( $context );
102  }
103 
104  $pager = new NewFilesPager( $context, $opts );
105 
106  $out->addHTML( $pager->getBody() );
107  if ( !$this->including() ) {
108  $out->addHTML( $pager->getNavigationBar() );
109  }
110  }
111 
112  protected function buildForm( IContextSource $context ) {
113  $mediaTypesText = array_map( function ( $type ) {
114  // mediastatistics-header-unknown, mediastatistics-header-bitmap,
115  // mediastatistics-header-drawing, mediastatistics-header-audio,
116  // mediastatistics-header-video, mediastatistics-header-multimedia,
117  // mediastatistics-header-office, mediastatistics-header-text,
118  // mediastatistics-header-executable, mediastatistics-header-archive,
119  // mediastatistics-header-3d,
120  return $this->msg( 'mediastatistics-header-' . strtolower( $type ) )->text();
121  }, $this->mediaTypes );
122  $mediaTypesOptions = array_combine( $mediaTypesText, $this->mediaTypes );
123  ksort( $mediaTypesOptions );
124 
125  $formDescriptor = [
126  'like' => [
127  'type' => 'text',
128  'label-message' => 'newimages-label',
129  'name' => 'like',
130  ],
131 
132  'user' => [
133  'type' => 'text',
134  'label-message' => 'newimages-user',
135  'name' => 'user',
136  ],
137 
138  'newbies' => [
139  'type' => 'check',
140  'label-message' => 'newimages-newbies',
141  'name' => 'newbies',
142  ],
143 
144  'showbots' => [
145  'type' => 'check',
146  'label-message' => 'newimages-showbots',
147  'name' => 'showbots',
148  ],
149 
150  'hidepatrolled' => [
151  'type' => 'check',
152  'label-message' => 'newimages-hidepatrolled',
153  'name' => 'hidepatrolled',
154  ],
155 
156  'mediatype' => [
157  'type' => 'multiselect',
158  'flatlist' => true,
159  'name' => 'mediatype',
160  'label-message' => 'newimages-mediatype',
161  'options' => $mediaTypesOptions,
162  'default' => $this->mediaTypes,
163  ],
164 
165  'limit' => [
166  'type' => 'hidden',
167  'default' => $this->opts->getValue( 'limit' ),
168  'name' => 'limit',
169  ],
170 
171  'offset' => [
172  'type' => 'hidden',
173  'default' => $this->opts->getValue( 'offset' ),
174  'name' => 'offset',
175  ],
176 
177  'start' => [
178  'type' => 'date',
179  'label-message' => 'date-range-from',
180  'name' => 'start',
181  ],
182 
183  'end' => [
184  'type' => 'date',
185  'label-message' => 'date-range-to',
186  'name' => 'end',
187  ],
188  ];
189 
190  if ( $this->getConfig()->get( 'MiserMode' ) ) {
191  unset( $formDescriptor['like'] );
192  }
193 
194  if ( !$this->getUser()->useFilePatrol() ) {
195  unset( $formDescriptor['hidepatrolled'] );
196  }
197 
198  HTMLForm::factory( 'ooui', $formDescriptor, $context )
199  // For the 'multiselect' field values to be preserved on submit
200  ->setFormIdentifier( 'specialnewimages' )
201  ->setWrapperLegendMsg( 'newimages-legend' )
202  ->setSubmitTextMsg( 'ilsubmit' )
203  ->setMethod( 'get' )
204  ->prepareForm()
205  ->displayForm( false );
206  }
207 
208  protected function getGroupName() {
209  return 'changes';
210  }
211 
215  function setTopText() {
217 
218  $message = $this->msg( 'newimagestext' )->inContentLanguage();
219  if ( !$message->isDisabled() ) {
220  $this->getOutput()->addWikiText(
221  Html::rawElement( 'p',
222  [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
223  "\n" . $message->plain() . "\n"
224  ),
225  /* $lineStart */ false,
226  /* $interface */ false
227  );
228  }
229  }
230 }
SpecialNewFiles\buildForm
buildForm(IContextSource $context)
Definition: SpecialNewimages.php:112
DerivativeRequest
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Definition: DerivativeRequest.php:34
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2581
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:180
SpecialNewFiles\$mediaTypes
string[] $mediaTypes
Definition: SpecialNewimages.php:29
SpecialNewFiles
Definition: SpecialNewimages.php:24
IncludableSpecialPage
Shortcut to construct an includable special page.
Definition: IncludableSpecialPage.php:29
FormOptions\validateIntBounds
validateIntBounds( $name, $min, $max)
Definition: FormOptions.php:253
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:344
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
SpecialNewFiles\setTopText
setTopText()
Send the text to be displayed above the options.
Definition: SpecialNewimages.php:215
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:81
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:785
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:714
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:277
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:685
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:648
FormOptions\setValue
setValue( $name, $value, $force=false)
Use to set the value of an option.
Definition: FormOptions.php:163
SpecialNewFiles\$opts
FormOptions $opts
Definition: SpecialNewimages.php:26
$request
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2581
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:99
captcha-old.opts
opts
Definition: captcha-old.py:227
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:665
SpecialNewFiles\__construct
__construct()
Definition: SpecialNewimages.php:31
SpecialNewFiles\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialNewimages.php:208
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialNewFiles\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialNewimages.php:35
NewFilesPager
Definition: NewFilesPager.php:27
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:583
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:226
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:781
$type
$type
Definition: testCompression.php:48