'captionLength' => true,
// Show the filesize in bytes in categories
'showBytes' => true,
+ // Show the dimensions (width x height) in categories
+ 'showDimensions' => true,
'mode' => 'traditional',
];
*/
protected $mShowBytes;
+ /**
+ * @var bool Whether to show the dimensions in categories
+ */
+ protected $mShowDimensions;
+
/**
* @var bool Whether to show the filename. Default: true
*/
$galleryOptions = $this->getConfig()->get( 'GalleryOptions' );
$this->mImages = [];
$this->mShowBytes = $galleryOptions['showBytes'];
+ $this->mShowDimensions = $galleryOptions['showDimensions'];
$this->mShowFilename = true;
$this->mParser = false;
$this->mHideBadImages = false;
return empty( $this->mImages );
}
+ /**
+ * Enable/Disable showing of the dimensions of an image in the gallery.
+ * Enabled by default.
+ *
+ * @param bool $f Set to false to disable
+ */
+ function setShowDimensions( $f ) {
+ $this->mShowDimensions = (bool)$f;
+ }
+
/**
* Enable/Disable showing of the file size of an image in the gallery.
* Enabled by default.
// ":{$ut}" );
// $ul = Linker::link( $linkTarget, $ut );
- if ( $this->mShowBytes ) {
- if ( $img ) {
- $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
- } else {
- $fileSize = $this->msg( 'filemissing' )->escaped();
+ $meta = [];
+ if ( $img ) {
+ if ( $this->mShowDimensions ) {
+ $meta[] = $img->getDimensionsString();
}
- $fileSize = "$fileSize<br />\n";
- } else {
- $fileSize = '';
+ if ( $this->mShowBytes ) {
+ $meta[] = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
+ }
+ } elseif ( $this->mShowDimensions || $this->mShowBytes ) {
+ $meta[] = $this->msg( 'filemissing' )->escaped();
+ }
+ $meta = $lang->semicolonList( $meta );
+ if ( $meta ) {
+ $meta .= "<br />\n";
}
$textlink = $this->mShowFilename ?
) . "\n" :
'';
- $galleryText = $textlink . $text . $fileSize;
+ $galleryText = $textlink . $text . $meta;
$galleryText = $this->wrapGalleryText( $galleryText, $thumb );
# Weird double wrapping (the extra div inside the li) needed due to FF2 bug
return MEDIATYPE_UNKNOWN;
}
+ /**
+ * Returns an array of media types (MEDIATYPE_xxx constants)
+ *
+ * @return array
+ */
+ public function getMediaTypes() {
+ return array_keys( $this->mediaTypes );
+ }
+
/**
* Get the MIME types that various versions of Internet Explorer would
* detect from a chunk of the content.
$ig->setContextTitle( $this->mTitle );
$ig->setShowBytes( false );
+ $ig->setShowDimensions( false );
$ig->setShowFilename( false );
$ig->setParser( $this );
$ig->setHideBadImages();
'img_major_mime' => $this->major,
// This is in order to trigger using
// the img_media_mime index in "range" mode.
+ // @todo how is order defined? use MimeAnalyzer::getMediaTypes?
'img_media_type' => [
MEDIATYPE_BITMAP,
MEDIATYPE_DRAWING,
/** @var FormOptions */
protected $opts;
+ /** @var string[] */
+ protected $mediaTypes;
+
public function __construct() {
parent::__construct( 'Newimages' );
}
public function execute( $par ) {
$this->setHeaders();
$this->outputHeader();
+ $mimeAnalyzer = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
+ $this->mediaTypes = $mimeAnalyzer->getMediaTypes();
$out = $this->getOutput();
$this->addHelpLink( 'Help:New images' );
$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->setValue( 'end', $end, true );
}
+ // 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;
}
protected function buildForm() {
+ $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,
+ return $this->msg( 'mediastatistics-header-' . strtolower( $type ) )->text();
+ }, $this->mediaTypes );
+ $mediaTypesOptions = array_combine( $mediaTypesText, $this->mediaTypes );
+ ksort( $mediaTypesOptions );
+
$formDescriptor = [
'like' => [
'type' => 'text',
'name' => 'user',
],
+ 'newbies' => [
+ 'type' => 'check',
+ 'label-message' => 'newimages-newbies',
+ 'name' => 'newbies',
+ ],
+
'showbots' => [
'type' => 'check',
'label-message' => 'newimages-showbots',
'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' ),
}
HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
+ // For the 'multiselect' field values to be preserved on submit
+ ->setFormIdentifier( 'specialnewimages' )
->setWrapperLegendMsg( 'newimages-legend' )
->setSubmitTextMsg( 'ilsubmit' )
->setMethod( 'get' )
$gallery = ImageGalleryBase::factory( false, $this->getContext() );
$gallery->setShowBytes( false );
+ $gallery->setShowDimensions( false );
foreach ( $dupes as $file ) {
$gallery->add( $file->getTitle() );
}
}
}
+ if ( $opts->getValue( 'newbies' ) ) {
+ // newbie = most recent 1% of users
+ $dbr = wfGetDB( DB_REPLICA );
+ $max = $dbr->selectField( 'user', 'max(user_id)', false, __METHOD__ );
+ $conds[] = 'img_user >' . (int)( $max - $max / 100 );
+
+ // there's no point in looking for new user activity in a far past;
+ // beyond a certain point, we'd just end up scanning the rest of the
+ // table even though the users we're looking for didn't yet exist...
+ // see T140537, (for ContribsPages, but similar to this)
+ $conds[] = 'img_timestamp > ' .
+ $dbr->addQuotes( $dbr->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
+ }
+
if ( !$opts->getValue( 'showbots' ) ) {
$groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
$options[] = 'STRAIGHT_JOIN';
}
+ if ( $opts->getValue( 'mediatype' ) ) {
+ $conds['img_media_type'] = $opts->getValue( 'mediatype' );
+ }
+
$likeVal = $opts->getValue( 'like' );
if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
$dbr = wfGetDB( DB_REPLICA );
"newimages-legend": "Filter",
"newimages-label": "Filename (or a part of it):",
"newimages-user": "IP address or username",
+ "newimages-newbies": "Show contributions of new accounts only",
"newimages-showbots": "Show uploads by bots",
"newimages-hidepatrolled": "Hide patrolled uploads",
+ "newimages-mediatype": "Media type:",
"noimages": "Nothing to see.",
"gallery-slideshow-toggle": "Toggle thumbnails",
"ilsubmit": "Search",
"tags-create-reason": "Reason:",
"tags-create-submit": "Create",
"tags-create-no-name": "You must specify a tag name.",
- "tags-create-invalid-chars": "Tag names must not contain commas (<code>,</code>) or forward slashes (<code>/</code>).",
+ "tags-create-invalid-chars": "Tag names must not contain commas (<code>,</code>), pipes (<code>|</code>), or forward slashes (<code>/</code>).",
"tags-create-invalid-title-chars": "Tag names must not contain characters that cannot be used in page titles.",
"tags-create-already-exists": "The tag \"$1\" already exists.",
"tags-create-warnings-above": "The following {{PLURAL:$2|warning was|warnings were}} encountered when attempting to create the tag \"$1\":",
"newimages-legend": "Caption of the fieldset for the filter on [[Special:NewImages]]\n\n{{Identical|Filter}}",
"newimages-label": "Caption of the filter editbox on [[Special:NewImages]]",
"newimages-user": "Caption of the username/IP address editbox on [[Special:NewImages]]",
+ "newimages-newbies": "Used as label for a checkbox. When checked, [[Special:NewImages]] will only display uploads by new users.",
"newimages-showbots": "Used as label for a checkbox. When checked, [[Special:NewImages]] will also display uploads by users in the bots group.",
"newimages-hidepatrolled": "Used as label for a checkbox. When checked, [[Special:NewImages]] will not display patrolled uploads.\n\nCf. {{msg-mw|tog-hidepatrolled}} and {{msg-mw|apihelp-feedrecentchanges-param-hidepatrolled}}.",
+ "newimages-mediatype": "Used as label for a multiselect where users can select the media types to display.",
"noimages": "This is shown on the special page [[Special:NewImages]], when there aren't any recently uploaded files.",
"gallery-slideshow-toggle": "Tooltip for the icon that toggles thumbnails on a slideshow gallery.",
"ilsubmit": "Search button in [[Special:MIMESearch]].\n\nStrings on the page:\n* {{msg-mw|Mimesearch|page title, legend of input form, link in special pages}}\n* {{msg-mw|Mimesearch-summary|page summary}}\n* {{msg-mw|Mimetype|label for input box}}\n* {{msg-mw|Ilsubmit|search button}}\n\nCheck [[mw:Manual:MIME_type_detection]] for MIME types.\n\n{{Identical|Search}}",
*/
/**
- * Class representing an in memory fake file.
- * This is intended for unit testing / developement when you do not want
+ * Class representing an in-memory fake file.
+ * This is intended for unit testing / development when you do not want
* to hit the filesystem.
*
* It reimplements abstract methods with some hardcoded values. Might