X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fspecials%2FSpecialNewimages.php;h=0a653e73704fd64802db5f4f54ef76e11d155504;hp=12dae8b8db78deb8eb56dcc5b56e17d3355f84ad;hb=dcae3733c98cff011e3170bb4eb8748a31f70496;hpb=d42d6bd868fd5b579080639995e6a7e23851fcf3 diff --git a/includes/specials/SpecialNewimages.php b/includes/specials/SpecialNewimages.php index 12dae8b8db..0a653e7370 100644 --- a/includes/specials/SpecialNewimages.php +++ b/includes/specials/SpecialNewimages.php @@ -25,13 +25,20 @@ class SpecialNewFiles extends IncludableSpecialPage { /** @var FormOptions */ protected $opts; + /** @var string[] */ + protected $mediaTypes; + public function __construct() { parent::__construct( 'Newimages' ); } public function execute( $par ) { + $context = new DerivativeContext( $this->getContext() ); + $this->setHeaders(); $this->outputHeader(); + $mimeAnalyzer = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); + $this->mediaTypes = $mimeAnalyzer->getMediaTypes(); $out = $this->getOutput(); $this->addHelpLink( 'Help:New images' ); @@ -41,9 +48,13 @@ class SpecialNewFiles extends IncludableSpecialPage { $opts->add( 'like', '' ); $opts->add( 'user', '' ); $opts->add( 'showbots', false ); + $opts->add( 'newbies', false ); $opts->add( 'hidepatrolled', false ); + $opts->add( 'mediatype', $this->mediaTypes ); $opts->add( 'limit', 50 ); $opts->add( 'offset', '' ); + $opts->add( 'start', '' ); + $opts->add( 'end', '' ); $opts->fetchValuesFromRequest( $this->getRequest() ); @@ -51,16 +62,46 @@ class SpecialNewFiles extends IncludableSpecialPage { $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par ); } + // If start date comes after end date chronologically, swap them. + // They are swapped in the interface by JS. + $start = $opts->getValue( 'start' ); + $end = $opts->getValue( 'end' ); + if ( $start !== '' && $end !== '' && $start > $end ) { + $temp = $end; + $end = $start; + $start = $temp; + + $opts->setValue( 'start', $start, true ); + $opts->setValue( 'end', $end, true ); + + // also swap values in request object, which is used by HTMLForm + // to pre-populate the fields with the previous input + $request = $context->getRequest(); + $context->setRequest( new DerivativeRequest( + $request, + [ 'start' => $start, 'end' => $end ] + $request->getValues(), + $request->wasPosted() + ) ); + } + + // if all media types have been selected, wipe out the array to prevent + // the pointless IN(...) query condition (which would have no effect + // because every possible type has been selected) + $missingMediaTypes = array_diff( $this->mediaTypes, $opts->getValue( 'mediatype' ) ); + if ( empty( $missingMediaTypes ) ) { + $opts->setValue( 'mediatype', [] ); + } + $opts->validateIntBounds( 'limit', 0, 500 ); $this->opts = $opts; if ( !$this->including() ) { $this->setTopText(); - $this->buildForm(); + $this->buildForm( $context ); } - $pager = new NewFilesPager( $this->getContext(), $opts ); + $pager = new NewFilesPager( $context, $opts ); $out->addHTML( $pager->getBody() ); if ( !$this->including() ) { @@ -68,7 +109,19 @@ class SpecialNewFiles extends IncludableSpecialPage { } } - protected function buildForm() { + protected function buildForm( IContextSource $context ) { + $mediaTypesText = array_map( function ( $type ) { + // mediastatistics-header-unknown, mediastatistics-header-bitmap, + // mediastatistics-header-drawing, mediastatistics-header-audio, + // mediastatistics-header-video, mediastatistics-header-multimedia, + // mediastatistics-header-office, mediastatistics-header-text, + // mediastatistics-header-executable, mediastatistics-header-archive, + // mediastatistics-header-3d, + return $this->msg( 'mediastatistics-header-' . strtolower( $type ) )->text(); + }, $this->mediaTypes ); + $mediaTypesOptions = array_combine( $mediaTypesText, $this->mediaTypes ); + ksort( $mediaTypesOptions ); + $formDescriptor = [ 'like' => [ 'type' => 'text', @@ -82,6 +135,12 @@ class SpecialNewFiles extends IncludableSpecialPage { 'name' => 'user', ], + 'newbies' => [ + 'type' => 'check', + 'label-message' => 'newimages-newbies', + 'name' => 'newbies', + ], + 'showbots' => [ 'type' => 'check', 'label-message' => 'newimages-showbots', @@ -94,6 +153,16 @@ class SpecialNewFiles extends IncludableSpecialPage { 'name' => 'hidepatrolled', ], + 'mediatype' => [ + 'type' => 'multiselect', + 'dropdown' => true, + 'flatlist' => true, + 'name' => 'mediatype', + 'label-message' => 'newimages-mediatype', + 'options' => $mediaTypesOptions, + 'default' => $this->mediaTypes, + ], + 'limit' => [ 'type' => 'hidden', 'default' => $this->opts->getValue( 'limit' ), @@ -105,6 +174,18 @@ class SpecialNewFiles extends IncludableSpecialPage { 'default' => $this->opts->getValue( 'offset' ), 'name' => 'offset', ], + + 'start' => [ + 'type' => 'date', + 'label-message' => 'date-range-from', + 'name' => 'start', + ], + + 'end' => [ + 'type' => 'date', + 'label-message' => 'date-range-to', + 'name' => 'end', + ], ]; if ( $this->getConfig()->get( 'MiserMode' ) ) { @@ -115,7 +196,9 @@ class SpecialNewFiles extends IncludableSpecialPage { unset( $formDescriptor['hidepatrolled'] ); } - HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) + HTMLForm::factory( 'ooui', $formDescriptor, $context ) + // For the 'multiselect' field values to be preserved on submit + ->setFormIdentifier( 'specialnewimages' ) ->setWrapperLegendMsg( 'newimages-legend' ) ->setSubmitTextMsg( 'ilsubmit' ) ->setMethod( 'get' )