Gilles has uploaded a new change for review. https://gerrit.wikimedia.org/r/113937
Change subject: Reduce Wikidata author vcard to creator part ...................................................................... Reduce Wikidata author vcard to creator part And let the credit area overflow in case of massive author/source Change-Id: I3ee3f7c45a67da126565d58834d2100b2698cbb5 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/202 --- M resources/mmv/mmv.less M resources/mmv/ui/mmv.ui.metadataPanel.js M tests/qunit/mmv.ui.metadataPanel.test.js 3 files changed, 104 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer refs/changes/37/113937/1 diff --git a/resources/mmv/mmv.less b/resources/mmv/mmv.less index d2e098e..c78faa5 100644 --- a/resources/mmv/mmv.less +++ b/resources/mmv/mmv.less @@ -245,7 +245,7 @@ .mw-mlb-title-credit { width: 100%; - height: @title-height; + min-height: @title-height; } .mw-mlb-license { diff --git a/resources/mmv/ui/mmv.ui.metadataPanel.js b/resources/mmv/ui/mmv.ui.metadataPanel.js index b9a41f2..d4c67c1 100644 --- a/resources/mmv/ui/mmv.ui.metadataPanel.js +++ b/resources/mmv/ui/mmv.ui.metadataPanel.js @@ -450,7 +450,18 @@ * @param {string} author Warning - unsafe HTML sometimes goes here */ MPP.setAuthor = function ( author ) { - this.whitelistHtml( this.$author.empty().append( $.parseHTML( author ) ) ); + var $creator; + + this.$author.empty().append( $.parseHTML( author ) ); + + // Author can be a Wikidata vcard, which requires extra cleaning + $creator = this.$author.find( 'div.vcard span#creator'); + + if ( $creator.length ) { + this.$author.html( $creator.html() ); + } + + this.whitelistHtml( this.$author ); this.$credit.removeClass( 'empty' ); }; diff --git a/tests/qunit/mmv.ui.metadataPanel.test.js b/tests/qunit/mmv.ui.metadataPanel.test.js index cbd5aec..d31503c 100644 --- a/tests/qunit/mmv.ui.metadataPanel.test.js +++ b/tests/qunit/mmv.ui.metadataPanel.test.js @@ -38,7 +38,7 @@ assert.strictEqual( panel.$dragIcon.hasClass( 'pointing-down' ), false, 'We successfully reset the chevron' ); } ); - QUnit.test( 'Setting repository information in the UI works as expected', 3, function ( assert ) { + QUnit.test( 'Repository information in the UI', 3, function ( assert ) { var $qf = $( '#qunit-fixture' ), panel = new mw.mmv.ui.MetadataPanel( $qf, $( '<div>' ).appendTo( $qf ) ); @@ -52,7 +52,7 @@ assert.strictEqual( panel.$repo.prop( 'href' ), 'https://commons.wikimedia.org/wiki/File:Foobar.jpg', 'The file link was set successfully.' ); } ); - QUnit.test( 'Setting location information works as expected', 6, function ( assert ) { + QUnit.test( 'Location information', 6, function ( assert ) { var $qf = $( '#qunit-fixture' ), panel = new mw.mmv.ui.MetadataPanel( $qf, $( '<div>' ).appendTo( $qf ) ), fileName = 'Foobar.jpg', @@ -116,7 +116,7 @@ ); } ); - QUnit.test( 'Setting image information works as expected', 15, function ( assert ) { + QUnit.test( 'Image information', 15, function ( assert ) { var gender, $qf = $( '#qunit-fixture' ), panel = new mw.mmv.ui.MetadataPanel( $qf, $( '<div>' ).appendTo( $qf ) ), @@ -185,4 +185,92 @@ assert.strictEqual( result, date1, 'Invalid date is correctly ignored' ); } ); + + QUnit.test( 'Wikidata vcard author', 1, function ( assert ) { + var $qf = $( '#qunit-fixture' ), + panel = new mw.mmv.ui.MetadataPanel( $qf, $( '<div>' ).appendTo( $qf ) ), + author = '<div class="vcard">\n<table class="toccolours collapsible collapsed" ' + + 'cellpadding="2" cellspacing="0" style="direction:ltr; text-align:left; ' + + 'border-collapse:collapse; background:#f0f0ff; border:1px solid #aaa;">\n<tr ' + + 'valign="top">\n<th colspan="4" style="background-color:#e0e0ee; ' + + 'font-weight:bold; border:1px solid #aaa;">\n<span class="fn" id="creator">' + + '<bdi><a href="//en.wikipedia.org/wiki/Mathew_Brady" class="extiw" ' + + 'title="en:Mathew Brady">Mathew Brady</a></bdi></span> (1823\u20131896) <span ' + + 'class="wpImageAnnotatorControl wpImageAnnotatorOff"><a ' + + 'href="//commons.wikimedia.org/wiki/Creator:Mathew_Brady" title="Link back to ' + + 'Creator infobox template"><img alt="Link back to Creator infobox template" ' + + 'src="//upload.wikimedia.org/wikipedia/commons/thumb/7/73/Blue_pencil.svg/15px-Blue_pencil.svg.png" ' + + 'width="15" height="15" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/7/73/Blue_pencil.svg/23px-Blue_pencil.svg.png ' + + '1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/7/73/Blue_pencil.svg/30px-Blue_pencil.svg.png ' + + '2x"></a></span>\u00a0<span class="wpImageAnnotatorControl wpImageAnnotatorOff"><a ' + + 'href="//www.wikidata.org/wiki/Q187850" title="wikidata:Q187850"><img ' + + 'alt="wikidata:Q187850" src="//upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/20px-Wikidata-logo.svg.png" ' + + 'width="20" height="11" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/30px-Wikidata-logo.svg.png ' + + '1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/40px-Wikidata-logo.svg.png 2x">' + + '</a></span>\n</th>\n</tr>\n<tr valign="top">\n<td rowspan="8" style="width:120px" ' + + 'id="fileinfotpl_creator_image"><span class="wpImageAnnotatorControl wpImageAnnotatorOff">' + + '<a href="//commons.wikimedia.org/wiki/File:Mathew_Brady_1875_cropped.jpg" ' + + 'class="image"><img alt="Mathew Brady" src="//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Mathew_Brady_1875_cropped.jpg/120px-Mathew_Brady_1875_cropped.jpg" ' + + 'width="120" height="160" class="photo" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Mathew_Brady_1875_cropped.jpg/180px-Mathew_Brady_1875_cropped.jpg ' + + '1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Mathew_Brady_1875_cropped.jpg/240px-Mathew_Brady_1875_cropped.jpg ' + + '2x"></a></span></td>\n</tr>\n<tr valign="top">\n<td style="background:#e0e0ee; border:1px solid #aaa; font-weight:bold;">' + + 'Description</td>\n<td colspan="2" style="border:1px solid #aaa;" ' + + 'class="note" id="fileinfotpl_creator_desc_value">\n<p>American photographer' + + '<br></p>\n</td>\n</tr>\n<tr valign="top">\n<td style="background:#e0e0ee; ' + + 'border:1px solid #aaa; font-weight:bold;">Date of birth/death</td>\n' + + '<td style="min-width:100px; border:1px solid #aaa;" id="fileinfotpl_creator_birthdate_value">' + + 'circa <time class="dtstart" datetime="1823">1823</time>\n</td>\n' + + '<td style="min-width:100px; border:1px solid #aaa;" id="fileinfotpl_creator_deathdate_value">' + + '<time class="" datetime="1896-01-15">15 January 1896</time></td>\n</tr>\n' + + '<tr valign="top">\n<td style="background:#e0e0ee; border:1px solid #aaa; ' + + 'font-weight:bold;">Location of birth/death</td>\n<td style="min-width:100px; ' + + 'border:1px solid #aaa;" id="fileinfotpl_creator_birthloc_value">' + + '<a href="//en.wikipedia.org/wiki/Warren_County,_New_York" class="extiw" ' + + 'title="en:Warren County, New York">Warren County, New York</a></td>\n<td ' + + 'style="min-width:100px; border:1px solid #aaa;" id="fileinfotpl_creator_deathloc_value">' + + '<a href="//en.wikipedia.org/wiki/New_York_City" class="extiw" ' + + 'title="en:New York City">New York City</a></td>\n</tr>\n<tr valign="top">\n' + + '<td style="background:#e0e0ee; border:1px solid #aaa; font-weight:bold;">Work ' + + 'period</td>\n<td colspan="2" style="border:1px solid #aaa;" ' + + 'id="fileinfotpl_creator_work-period_value">from <time class="dtstart" ' + + 'datetime="1844">1844</time> until circa <time class="dtstart" ' + + 'datetime="1887">1887</time>\n</td>\n</tr>\n<tr valign="top">\n' + + '<td style="background:#e0e0ee; border:1px solid #aaa; font-weight:bold;">' + + 'Work location</td>\n<td colspan="2" style="border:1px solid #aaa;" ' + + 'class="adr" id="fileinfotpl_creator_work-location_value"><span ' + + 'class="locality"><a href="//en.wikipedia.org/wiki/New_York_City" ' + + 'class="extiw" title="en:New York City">New York City</a>, ' + + '<a href="//en.wikipedia.org/wiki/Washington,_D.C." class="extiw" ' + + 'title="en:Washington, D.C.">Washington, D.C.</a></span></td>\n</tr>\n' + + '<tr valign="top">\n<td style="background:#e0e0ee; border:1px solid #aaa; ' + + 'font-weight:bold;">Authority control</td>\n<td colspan="2" style="border:1px ' + + 'solid #aaa;" id="fileinfotpl_creator_authority_value">\n<div class="hlist">\n' + + '<ul>\n<li>\n<a href="//en.wikipedia.org/wiki/Virtual_International_Authority_File" ' + + 'class="extiw" title="en:Virtual International Authority File">VIAF</a>: ' + + '<span class="uid"><a rel="nofollow" class="external text" ' + + 'href="http://viaf.org/viaf/22965552">22965552</a></span>\n</li>\n<li>\n' + + '<a href="//en.wikipedia.org/wiki/Library_of_Congress_Control_Number" ' + + 'class="extiw" title="en:Library of Congress Control Number">LCCN</a>: ' + + '<span class="uid"><a rel="nofollow" class="external text" ' + + 'href="http://id.loc.gov/authorities/names/n81140569.html">n81140569</a></span>\n' + + '</li>\n<li>\n<a href="//en.wikipedia.org/wiki/Universal_Authority_File" ' + + 'class="extiw" title="en:Universal Authority File">GND</a>: <span class="uid">' + + '<a rel="nofollow" class="external text" href="http://d-nb.info/gnd/12017636X">' + + '12017636X</a></span>\n</li>\n<li>\n<a href="//en.wikipedia.org/wiki/Union_List_of_Artist_Names" ' + + 'class="extiw" title="en:Union List of Artist Names">ULAN</a>: <span class="uid">' + + '<a rel="nofollow" class="external text" href="http://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=500126201">' + + '500126201</a></span>\n</li>\n<li>\n<a href="//en.wikipedia.org/wiki/International_Standard_Name_Identifier" ' + + 'class="extiw" title="en:International Standard Name Identifier">ISNI</a>: ' + + '<span class="uid"><a rel="nofollow" class="external text" ' + + 'href="http://isni-url.oclc.nl/isni/0000000122094376">0000\u20090001\u20092209\u20094376' + + '</a></span>\n</li>\n<li><span class="uid"><a rel="nofollow" class="external ' + + 'text" href="http://www.worldcat.org/identities/lccn-n81-140569">WorldCat</a></span>' + + '</li>\n</ul>\n</div>\n</td>\n</tr>\n</table>\n</div>\n'; + + panel.setAuthor( author ); + + assert.strictEqual( panel.$author.html(), + '<a href="//en.wikipedia.org/wiki/Mathew_Brady" class="extiw" title="en:Mathew Brady">Mathew Brady</a>', + 'Simple author representation is correctly extracted' ); + } ); }( mediaWiki, jQuery ) ); -- To view, visit https://gerrit.wikimedia.org/r/113937 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3ee3f7c45a67da126565d58834d2100b2698cbb5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MultimediaViewer Gerrit-Branch: master Gerrit-Owner: Gilles <gdu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits