Merge "Set flush mode in DatabasePostgres::reportQueryError()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 15 Jun 2017 18:14:02 +0000 (18:14 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 15 Jun 2017 18:14:02 +0000 (18:14 +0000)
12 files changed:
includes/DefaultSettings.php
includes/gallery/ImageGalleryBase.php
includes/gallery/TraditionalImageGallery.php
includes/libs/mime/MimeAnalyzer.php
includes/parser/Parser.php
includes/specials/SpecialMIMEsearch.php
includes/specials/SpecialNewimages.php
includes/specials/SpecialUpload.php
includes/specials/pagers/NewFilesPager.php
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/mocks/filebackend/MockFSFile.php

index 48414b7..00e26d9 100644 (file)
@@ -1455,6 +1455,8 @@ $wgGalleryOptions = [
        'captionLength' => true,
        // Show the filesize in bytes in categories
        'showBytes' => true,
+       // Show the dimensions (width x height) in categories
+       'showDimensions' => true,
        'mode' => 'traditional',
 ];
 
index 6884f65..eeb8a8f 100644 (file)
@@ -38,6 +38,11 @@ abstract class ImageGalleryBase extends ContextSource {
         */
        protected $mShowBytes;
 
+       /**
+        * @var bool Whether to show the dimensions in categories
+        */
+       protected $mShowDimensions;
+
        /**
         * @var bool Whether to show the filename. Default: true
         */
@@ -136,6 +141,7 @@ abstract class ImageGalleryBase extends ContextSource {
                $galleryOptions = $this->getConfig()->get( 'GalleryOptions' );
                $this->mImages = [];
                $this->mShowBytes = $galleryOptions['showBytes'];
+               $this->mShowDimensions = $galleryOptions['showDimensions'];
                $this->mShowFilename = true;
                $this->mParser = false;
                $this->mHideBadImages = false;
@@ -283,6 +289,16 @@ abstract class ImageGalleryBase extends ContextSource {
                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.
index 1fd7b0a..a0059ce 100644 (file)
@@ -174,15 +174,20 @@ class TraditionalImageGallery extends ImageGalleryBase {
                        // ":{$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 ?
@@ -201,7 +206,7 @@ class TraditionalImageGallery extends ImageGalleryBase {
                                ) . "\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
index 565c157..c361fdf 100644 (file)
@@ -1144,6 +1144,15 @@ EOT;
                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.
index 34f6232..d8722ba 100644 (file)
@@ -4974,6 +4974,7 @@ class Parser {
 
                $ig->setContextTitle( $this->mTitle );
                $ig->setShowBytes( false );
+               $ig->setShowDimensions( false );
                $ig->setShowFilename( false );
                $ig->setParser( $this );
                $ig->setHideBadImages();
index 52cb30a..7087cff 100644 (file)
@@ -74,6 +74,7 @@ class MIMEsearchPage extends QueryPage {
                                '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,
index 5fa0a73..8528ce2 100644 (file)
@@ -25,6 +25,9 @@ class SpecialNewFiles extends IncludableSpecialPage {
        /** @var FormOptions */
        protected $opts;
 
+       /** @var string[] */
+       protected $mediaTypes;
+
        public function __construct() {
                parent::__construct( 'Newimages' );
        }
@@ -32,6 +35,8 @@ class SpecialNewFiles extends IncludableSpecialPage {
        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' );
@@ -41,7 +46,9 @@ 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', '' );
@@ -66,6 +73,14 @@ class SpecialNewFiles extends IncludableSpecialPage {
                        $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;
@@ -84,6 +99,17 @@ class SpecialNewFiles extends IncludableSpecialPage {
        }
 
        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',
@@ -97,6 +123,12 @@ class SpecialNewFiles extends IncludableSpecialPage {
                                'name' => 'user',
                        ],
 
+                       'newbies' => [
+                               'type' => 'check',
+                               'label-message' => 'newimages-newbies',
+                               'name' => 'newbies',
+                       ],
+
                        'showbots' => [
                                'type' => 'check',
                                'label-message' => 'newimages-showbots',
@@ -109,6 +141,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' ),
@@ -143,6 +185,8 @@ class SpecialNewFiles extends IncludableSpecialPage {
                }
 
                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' )
index f4a4818..def639d 100644 (file)
@@ -821,6 +821,7 @@ class SpecialUpload extends SpecialPage {
 
                $gallery = ImageGalleryBase::factory( false, $this->getContext() );
                $gallery->setShowBytes( false );
+               $gallery->setShowDimensions( false );
                foreach ( $dupes as $file ) {
                        $gallery->add( $file->getTitle() );
                }
index cce0323..001c296 100644 (file)
@@ -74,6 +74,20 @@ class NewFilesPager extends RangeChronologicalPager {
                        }
                }
 
+               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' );
 
@@ -112,6 +126,10 @@ class NewFilesPager extends RangeChronologicalPager {
                        $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 );
index bcb9f2d..a3c310c 100644 (file)
        "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\":",
index 0569267..c843a6d 100644 (file)
        "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}}",
index 8ee45a8..047c03a 100644 (file)
@@ -22,8 +22,8 @@
  */
 
 /**
- * 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