Page MenuHomePhabricator

Add tag filter to Special:ListFiles
Open, Needs TriagePublic

Event Timeline

Restricted Application added a project: Multimedia. · View Herald TranscriptApr 15 2018, 4:45 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Wilfredor updated the task description. (Show Details)Apr 15 2018, 4:48 PM
Reedy renamed this task from Add tag filter to Special:ListFiles on Wikimedia Commons to Add tag filter to Special:ListFiles.Apr 15 2018, 6:11 PM
Nirmos added a subscriber: Nirmos.Apr 16 2018, 3:23 PM

If I understand your problem correctly, then resolving this task will not solve your problem because:

  1. As far as I know, there is not (yet) any infrastructure for filtering out edits with a certain tag. The inverse (only showing edits with a certain tag) does exist, but that's not what we want to do here.
  2. As far as I know, tags aren't applied retroactively.

In lieu of support from MediaWiki to do this, we can use JavaScript and CSS. You can add

$( function() {
	'use strict';
	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Listfiles' ) {
		$( '#mw-content-text' ).prepend( '<button type="button" id="gadget-toggleflickr2commons" title="Toggle visibility of images uploaded using Flickr2Commons.">Toggle Flickr2Commons</button>' );
		$( '#gadget-toggleflickr2commons' ).click( function() {
			$( '.TablePager_col_img_description' ).each( function( i, e ) {
				if ( $( e ).text() === 'Transferred from Flickr via Flickr2Commons' ) {
					$( e ).closest( 'tr' ).toggleClass( 'gadget-toggleflickr2commons' );
				}
			} );
		} );
	}
} );

to Special:MyPage/common.js. This adds a button at the top of Special:ListFiles. When you click it, it will add the HTML class "gadget-toggleflickr2commons" to all rows where the description is "Transferred from Flickr via Flickr2Commons".

You can then hide elements with this class, as well as optionally style the button however you want, by adding

#gadget-toggleflickr2commons {
	float: right;
}

.gadget-toggleflickr2commons {
	display: none;
}

to Special:MyPage/common.css

There is one caveat with doing this, of course. Because you're only toggling the visibility of what's currently on the page, this simple script does no kind of "backfilling" or whatever you wanna call it. That is, if you're viewing 50 images, and all 50 of these have the description "Transferred from Flickr via Flickr2Commons", you will see 0 images when pressing the button. This may or may not be what you want.

Thanks Nirmos, however, it is something that should be done on server side.

In this moment I have 20 pages when 500 images that i need press next page to find the first Image with the tag uploadwizard and it makes ridiculously difficult to find my images to categorize them, for example.

Wilfredor added a comment.EditedApr 18 2018, 11:34 AM

I created this script based on your script

/*
 Transform "Upload log" page in a Gallery
 "Upload log" page: https://commons.wikimedia.org/w/index.php?title=Special:Log/upload&user={{YOUR USERNAME}}
*/
$(function() {
    'use strict';

    const uploadLogPage = 'Log';
    const uploadListContainer = ".mw-logline-upload";
    const resultContent = "#mw-content-text";
    const groupSize = 5;
	
	function _getPageName() {
		return mw.config.get('wgCanonicalSpecialPageName');
	}
    function _getImageName(aElement) {
        var imageName = null;

        const imageNode = $(aElement).find("a").last().attr('href').split(":");

        if (imageNode.length > 0) {
            if (imageNode[1].indexOf(".") !== -1) {
                imageName = imageNode[1];
            }
        }

        return imageName;
    }
    function _getMultiple(valor, multiple)
    {
        var resto = valor % multiple;
        return (resto===0);
    }
        
    function _arrayListToGroup(arrayList)
    {
    	var groupList = [];
    	var tempImageList = [];
    	var iSize = 0;
	    jQuery.each( arrayList, function( i, val ) {
		  tempImageList.push(val);
		  iSize++;
		  if (iSize==50) {
		  	groupList.push(tempImageList);
		  	tempImageList = [];
		  
			iSize =0;
		  }
		});
		
		if (tempImageList.length>0) groupList.push(tempImageList);

		return groupList;
    }
    function _getImageList() {
        var imageList = [];
		var imageName = null;

        $(uploadListContainer).each(function() {
			
            imageName = _getImageName(this);
			
			if (imageName !== null) {
				imageList.push(imageName);
			}

            $(this).remove();
        });

        return imageList;
    }

    function _addGallery(htmlText) {
        $(resultContent).find("ul").append(htmlText);
    }

    function _wikiToHTML() {
		const imageGroupList = _arrayListToGroup(_getImageList());

		var wikiHTML = [];
		
		jQuery.each( imageGroupList, function( i, imageList ) {
			
			wikiHTML.push(jQuery.getJSON(
				mw.util.wikiScript('api'), {
					'format': 'json',
					'action': 'parse',
					'contentmodel': 'wikitext',
					'text': _imageListToWikiText(imageList)
				},
				function(data) {
					//_addGallery(data.parse.text["*"]);
					return (data.parse.text["*"]);
				}
			));
			
		});
		
		$.when.apply($, wikiHTML).done(function(){
			var wikiText = [];
			
			for(var i = 0; i < arguments.length; i++){
				console.log(arguments[i]);
				if (typeof arguments.parse !== 'undefined')
				{
					wikiText.push(arguments.parse.text["*"]);
				} 
				else if ((typeof arguments[i] !== 'undefined')&&(typeof arguments[i].parse !== 'undefined'))
				{
					wikiText.push(arguments[i].parse.text["*"]);
				} 
				else if ((typeof arguments[i][0] !== 'undefined')&&(typeof arguments[i][0].parse !== 'undefined'))
				{
					wikiText.push(arguments[i][0].parse.text["*"]);
				}
			}
			
			var newUnique = [];
			
			$.each(wikiText , function (i, el) {
			    
			    if ($.inArray(el, newUnique ) === -1) {
			        newUnique.push(el);
			    } 
			    
			    else {
			        var index = newUnique.indexOf(el);
			        if(index > -1){
			           newUnique.splice(index, 1);
			        }
			    }
			});
			
			_addGallery(newUnique.join(""));
			
		});
		
        
    }
    
    function _imageListToWikiText(imageList) {
    	 return "<gallery>\nFile:" + imageList.join("\nFile:") + "\n</gallery>";
    }

    if (uploadLogPage === _getPageName()) {
		
        _wikiToHTML();
    }
});