Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/176510

Change subject: Parse {{Nuke}} templates
......................................................................

Parse {{Nuke}} templates

Nuke templates on Commons provide a link only visible to administrators
for convenient deletion of the file; find such links and extract
the reason parameter from them.

Bug: T71389
Change-Id: I849674af96cc3a781f87075e5cf823ac19ce7a3e
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/865
---
M DataCollector.php
M TemplateParser.php
A tests/html/File_Kerameikos_October_2012_15.JPG.html
M tests/phpunit/DataCollectorTest.php
M tests/phpunit/ParserTestHelper.php
M tests/phpunit/TemplateParserTest.php
6 files changed, 229 insertions(+), 19 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommonsMetadata 
refs/changes/10/176510/1

diff --git a/DataCollector.php b/DataCollector.php
index a443203..51addf8 100644
--- a/DataCollector.php
+++ b/DataCollector.php
@@ -110,24 +110,25 @@
         */
        public function verifyAttributionMetadata( $descriptionText ) {
                $templateData = $this->templateParser->parsePage( 
$descriptionText );
-               if ( !$templateData ) {
-                       return array( 'no-license', 'no-description', 
'no-author', 'no-source' );
+               $problems = $licenseData = $informationData = array();
+
+               if ( isset( $templateData[TemplateParser::LICENSES_KEY] ) ) {
+                       $licenseData = $this->selectLicense( 
$templateData[TemplateParser::LICENSES_KEY] );
+               }
+               if ( isset( 
$templateData[TemplateParser::INFORMATION_FIELDS_KEY] ) ) {
+                       $informationData = $this->selectInformationTemplate( 
$templateData[TemplateParser::INFORMATION_FIELDS_KEY] );
                }
 
-               $problems = array();
-               $licenseData = $this->selectLicense( 
$templateData[TemplateParser::LICENSES_KEY] );
-               $informationData = $this->selectInformationTemplate( 
$templateData[TemplateParser::INFORMATION_FIELDS_KEY] );
-
-               if ( !$licenseData || empty( $licenseData['LicenseShortName'] ) 
) {
+               if ( empty( $licenseData['LicenseShortName'] ) ) {
                        $problems[] = 'no-license';
                }
-               if ( !$informationData || empty( 
$informationData['ImageDescription'] ) ) {
+               if ( empty( $informationData['ImageDescription'] ) ) {
                        $problems[] = 'no-description';
                }
-               if ( !$informationData || empty( $informationData['Artist'] ) 
&& empty( $informationData['Attribution'] ) ) {
+               if ( empty( $informationData['Artist'] ) && empty( 
$informationData['Attribution'] ) ) {
                        $problems[] = 'no-author';
                }
-               if ( !$informationData || empty( $informationData['Credit'] ) 
&& empty( $informationData['Attribution'] ) ) {
+               if ( empty( $informationData['Credit'] ) && empty( 
$informationData['Attribution'] ) ) {
                        $problems[] = 'no-source';
                }
 
@@ -172,6 +173,10 @@
 
                if ( isset( $templateData[TemplateParser::LICENSES_KEY] ) ) {
                        $templateFields = array_merge( $templateFields, 
$this->selectLicense( $templateData[TemplateParser::LICENSES_KEY] ) );
+               }
+
+               if ( isset( $templateData[TemplateParser::DELETION_KEY] ) ) {
+                       $templateFields = array_merge( $templateFields, 
$this->selectDeletionReason( $templateData[TemplateParser::DELETION_KEY] ) );
                }
 
                $metadata = array();
@@ -375,4 +380,16 @@
                $sortedLicenses = array_values( $sortedLicenses );
                return $sortedLicenses ? $sortedLicenses[0] : array();
        }
+
+       /**
+        * Receives the list of deletion requests on a file page and flattens 
them
+        * @param array $deletions
+        * @return array a metadata key-value list; currently the only key is 
DeletionReason
+        */
+       protected function selectDeletionReason( $deletions ) {
+               if ( empty( $deletions ) ) {
+                       return array();
+               }
+               return $deletions[0];
+       }
 }
diff --git a/TemplateParser.php b/TemplateParser.php
index 9b56c9e..007f6fd 100644
--- a/TemplateParser.php
+++ b/TemplateParser.php
@@ -15,6 +15,7 @@
        const COORDINATES_KEY = 'coordinates';
        const LICENSES_KEY = 'licenses';
        const INFORMATION_FIELDS_KEY = 'informationFields';
+       const DELETION_KEY = 'deletion';
 
        /**
         * HTML element class name => metadata field name mapping for license 
data.
@@ -129,11 +130,12 @@
 
                $domNavigator = new DomNavigator( $html );
 
-               return array(
+               return array_filter( array(
                        self::COORDINATES_KEY => $this->parseCoordinates( 
$domNavigator ),
                        self::INFORMATION_FIELDS_KEY => 
$this->parseInformationFields( $domNavigator ),
                        self::LICENSES_KEY => $this->parseLicenses( 
$domNavigator ),
-               );
+                       self::DELETION_KEY => $this->parseNuke( $domNavigator ),
+               ) );
        }
 
        /**
@@ -318,6 +320,30 @@
        }
 
        /**
+        * Parse and return deletion reason from the {{Nuke}} template
+        * ( https://commons.wikimedia.org/wiki/Template:Nuke )
+        * @param DomNavigator $domNavigator
+        * @return array()
+        */
+       protected function parseNuke( DomNavigator $domNavigator ) {
+               $deletions = array();
+
+               foreach ( $domNavigator->findElementsWithClass( '*', 'nuke' ) 
as $nukeNode ) {
+                       $nukeLink = $nukeNode->firstChild;
+                       if ( $nukeLink && $nukeLink->hasAttribute( 'href' ) ) {
+                               $urlBits = wfParseUrl( $nukeLink->getAttribute( 
'href' ) );
+                               if ( isset( $urlBits['query'] ) ) {
+                                       $params = wfCgiToArray( 
$urlBits['query'] );
+                                       if ( isset( $params['action'] ) && 
$params['action'] === 'delete' && isset( $params['wpReason'] ) ) {
+                                               $deletions[] = array( 
'DeletionReason' => $params['wpReason'] );
+                                       }
+                               };
+                       }
+               }
+               return $deletions;
+       }
+
+       /**
         * Get the text of a node. The result might be a string, or an array of 
strings if the node has multiple
         * languages (resulting from {{en}} and similar templates).
         * @param DomNavigator $domNavigator
diff --git a/tests/html/File_Kerameikos_October_2012_15.JPG.html 
b/tests/html/File_Kerameikos_October_2012_15.JPG.html
new file mode 100644
index 0000000..c38ea3c
--- /dev/null
+++ b/tests/html/File_Kerameikos_October_2012_15.JPG.html
@@ -0,0 +1,131 @@
+<div class="layouttemplate">
+<table cellspacing="0" cellpadding="0" class="plainlinks mw-content-ltr" 
style="clear:both; width:80%; margin:.5em auto; background:#F9F9F9; border:3px 
solid #CC0000" dir="ltr" lang="en">
+<tr style="padding:8px 0px 0; background:#FFE2E0">
+<td style="padding:12px 0px 0px 12px;">
+<div class="center">
+<div class="floatnone"><img alt="Exclam icon.svg" 
src="//upload.wikimedia.org/wikipedia/commons/thumb/2/22/Exclam_icon.svg/55px-Exclam_icon.svg.png"
 width="55" height="50" 
srcset="//upload.wikimedia.org/wikipedia/commons/thumb/2/22/Exclam_icon.svg/83px-Exclam_icon.svg.png
 1.5x, 
//upload.wikimedia.org/wikipedia/commons/thumb/2/22/Exclam_icon.svg/110px-Exclam_icon.svg.png
 2x" data-file-width="200" data-file-height="180" /></div>
+</div>
+</td>
+<td style="padding:8px 4px 0px 0px;">
+<div class="floatright"><img alt="Keep tidy ask.svg" 
src="//upload.wikimedia.org/wikipedia/commons/thumb/1/15/Keep_tidy_ask.svg/70px-Keep_tidy_ask.svg.png"
 width="70" height="70" 
srcset="//upload.wikimedia.org/wikipedia/commons/thumb/1/15/Keep_tidy_ask.svg/105px-Keep_tidy_ask.svg.png
 1.5x, 
//upload.wikimedia.org/wikipedia/commons/thumb/1/15/Keep_tidy_ask.svg/140px-Keep_tidy_ask.svg.png
 2x" data-file-width="368" data-file-height="369" /></div>
+<div style="font-size: larger;"><b>This media file has been nominated for 
deletion since 16 November 2014.</b></div>
+To discuss it, please visit <span style="font-size: larger;"><b><a 
href="//commons.wikimedia.org/wiki/Commons:Deletion_requests/File:Kerameikos_October_2012_15.JPG"
 title="Commons:Deletion requests/File:Kerameikos October 2012 15.JPG">the 
nomination page</a></b>.</span>
+<p><i>Do not remove this tag until the deletion nomination is closed.</i></p>
+<hr />
+<p><b>Reason for the nomination:</b> <i>As far as I know tourist signs as all 
road signs are not in the public domain. --<a 
href="//commons.wikimedia.org/wiki/User:G.dallorto" 
title="User:G.dallorto">User:G.dallorto</a> (<a 
href="//commons.wikimedia.org/wiki/User_talk:G.dallorto" title="User 
talk:G.dallorto"><span class="signature-talk">talk</span></a>) 00:25, 16 
November 2014 (UTC)</i><br style="clear:both" /></p>
+</td>
+</tr>
+<tr>
+<td colspan="2">
+<div class="collapsibletemplate collapsed" style="clear:both;">
+<div class="collapsibleheader header" style="display:none; font-weight:bold; 
background-color:transparent; text-align:center;"><span 
class="headertext">&#160;Click here to show further 
instructions&#160;</span></div>
+<div class="body show-on-commons" style="display:none; padding:3px; 
font-weight:normal; background:transparent;">
+<p>If this template was added because you clicked "Nominate for deletion" in 
the left menu, please make sure that all necessary pages have been created. If 
they haven't been created after a few minutes, or if you added this template 
manually, you should complete these steps:</p>
+<ol>
+<li>Visit the <a 
href="//commons.wikimedia.org/wiki/Commons:Deletion_requests/File:Kerameikos_October_2012_15.JPG"
 title="Commons:Deletion requests/File:Kerameikos October 2012 15.JPG">deletion 
requests subpage</a> and place the following code:<br />
+<small style="color:purple">{{subst:<a 
href="//commons.wikimedia.org/wiki/Template:Delete2" 
title="Template:Delete2">delete2</a>|image=File:Kerameikos October 2012 
15.JPG|reason=As far as I know tourist signs as all road signs are not in the 
public domain. --<a href="//commons.wikimedia.org/wiki/User:G.dallorto" 
title="User:G.dallorto">User:G.dallorto</a> (<a 
href="//commons.wikimedia.org/wiki/User_talk:G.dallorto" title="User 
talk:G.dallorto"><span class="signature-talk">talk</span></a>) 00:25, 16 
November 2014 (UTC)}}&#160;~~~~</small></li>
+<li>Go to the <a class="external text" 
href="//commons.wikimedia.org/w/index.php?title=Commons:Deletion_requests/2014/11/30&amp;action=edit&amp;preload=Commons:Deletion+requests/newday">deletion
 requests log</a> and place the following code at the bottom:<br />
+<small style="color:purple">{{subst:<a 
href="//commons.wikimedia.org/wiki/Template:Delete3" 
title="Template:Delete3">delete3</a>|pg=File:Kerameikos October 2012 
15.JPG}}</small></li>
+<li>Notify the item's uploader or the creator of the page by placing the 
following code on the user's talk page:<br />
+<small style="color:purple">{{subst:<a 
href="//commons.wikimedia.org/wiki/Template:Idw" 
title="Template:Idw">idw</a>|File:Kerameikos October 2012 
15.JPG|}}&#160;~~~~</small></li>
+<li>Additionally, you may want to <a 
href="//commons.wikimedia.org/wiki/Special:GlobalUsage/Kerameikos_October_2012_15.JPG"
 title="Special:GlobalUsage/Kerameikos October 2012 15.JPG">check for Wikimedia 
projects that use this item</a> and then remove or, if possible, replace with a 
superior item.</li>
+</ol>
+<hr />
+<p><i><b>For mass deletions:</b></i> If you want to nominate several related 
images, please make a <a 
href="//commons.wikimedia.org/wiki/Help:Mass_deletion_request" title="Help:Mass 
deletion request" class="mw-redirect">mass request</a> by manually adding {{<a 
href="//commons.wikimedia.org/wiki/Template:Delete" 
title="Template:Delete">delete</a>|reason=<i>write reason</i>|subpage=<i>write 
name</i>|year=2014|month=November|day=30}} to each image page and then 
following the steps hereinbefore. (<a 
href="//commons.wikimedia.org/wiki/Help:Mass_deletion_request" title="Help:Mass 
deletion request" class="mw-redirect">Help on mass requests</a>.)</p>
+<p>Note: This template is for requests that may require discussion in order to 
be deleted. For <a 
href="//commons.wikimedia.org/wiki/Commons:D#Speedy_deletion" title="Commons:D" 
class="mw-redirect">speedy deletions</a>, you can use {{<a 
href="//commons.wikimedia.org/wiki/Template:Speedy" title="Template:Speedy" 
class="mw-redirect">speedy</a>|reason}}.</p>
+<hr /></div>
+</div>
+<div style="text-align: center;"><span 
style="font-size:x-small;line-height:140%" class="plainlinks noprint"><a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/af">Afrikaans</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ar">العربية</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/az">Azərbaycanca</a>&#160;| 
<a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/be-tarask">Беларуская 
(тарашкевіца)‎</a>&#160;| <a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/bn">বাংলা</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ca">Català</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/cs">Čeština</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/da">Dansk</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/de">Deutsch</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/de-formal">Deutsch 
(Sie-Form)‎</a>&#160;| <a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/diq">Zazaki</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/en">English</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/eo">Esperanto</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/es">Español</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/eu">Euskara</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ext">Estremeñu</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/fa">فارسی</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/fi">Suomi</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/fr">Français</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/gl">Galego</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/he">עברית</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/hr">Hrvatski</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/hu">Magyar</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/hy">Հայերեն</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ia">Interlingua</a>&#160;| 
<a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/it">Italiano</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ja">日本語</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ko">한국어</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/mk">Македонски</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ml">മലയാളം</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/nl">Nederlands</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/nn">Norsk nynorsk</a>&#160;| 
<a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/no">Norsk bokmål</a>&#160;| 
<a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/oc">Occitan</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/pl">Polski</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/pt">Português</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/pt-br">Português do 
Brasil</a>&#160;| <a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ro">Română</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/ru">Русский</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/sl">Slovenščina</a>&#160;| 
<a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/sr">Српски / 
srpski</a>&#160;| <a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/sv">Svenska</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/th">ไทย</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/tr">Türkçe</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/vi">Tiếng Việt</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/zh">中文</a>&#160;| <a 
class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/zh-hans">中文(简体)‎</a>&#160;| 
<a class="external text" 
href="//commons.wikimedia.org/wiki/Template:Delete/zh-hant">中文(繁體)‎</a>&#160;| 
<small class="plainlinks"><a class="external text" 
href="//commons.wikimedia.org/w/index.php?title=Template:Delete/lang&amp;action=edit">+/−</a></small></span></div>
+</td>
+</tr>
+</table>
+<p><span id="nuke" class="nuke" title="Delete this!" style="display:none;"><a 
href="//commons.wikimedia.org/w/index.php?title=File:Kerameikos_October_2012_15.JPG&amp;action=delete&amp;wpReason=%5B%5BCommons%3ADeletion+requests%2FFile%3AKerameikos+October+2012+15.JPG%5D%5D%3A+As+far+as+I+know+tourist+signs+as+all+road+signs+are+not+in+the+public+domain.+--%5B%5BUser%3AG.dallorto%7CUser%3AG.dallorto%5D%5D+%28%5B%5BUser+talk%3AG.dallorto%7C%3Cspan+class%3D%22signature-talk%22%3Etalk%3C%2Fspan%3E%5D%5D%29+00%3A25%2C+16+November+2014+%28UTC%29"><img
 alt="Gnome-edit-delete.svg" 
src="//upload.wikimedia.org/wikipedia/commons/thumb/9/96/Gnome-edit-delete.svg/40px-Gnome-edit-delete.svg.png"
 width="40" height="40" 
srcset="//upload.wikimedia.org/wikipedia/commons/thumb/9/96/Gnome-edit-delete.svg/60px-Gnome-edit-delete.svg.png
 1.5x, 
//upload.wikimedia.org/wikipedia/commons/thumb/9/96/Gnome-edit-delete.svg/80px-Gnome-edit-delete.svg.png
 2x" data-file-width="48" data-file-height="48" /></a></span></p>
+<span class="layouttemplateargs" style="display:none;speak:none;" 
title="template=Delete 
1%3DAs+far+as+I+know+tourist+signs+as+all+road+signs+are+not+in+the+public+domain.+--%5B%5BUser%3AG.dallorto%7CUser%3AG.dallorto%5D%5D+%28%5B%5BUser+talk%3AG.dallorto%7C%3Cspan+class%3D%22signature-talk%22%3Etalk%3C%2Fspan%3E%5D%5D%29+00%3A25%2C+16+November+2014+%28UTC%29
 2%3D 4%3D16 5%3DNovember 6%3D2014 9%3Dtrue">&#160;</span></div>
+<h2><span class="mw-headline" id="Summary">Summary</span><span 
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a 
href="//commons.wikimedia.org/w/index.php?title=File:Kerameikos_October_2012_15.JPG&amp;action=edit&amp;section=1"
 title="Edit section: Summary">edit</a><span 
class="mw-editsection-bracket">]</span></span></h2>
+<div class="hproduct commons-file-information-table">
+<table class="fileinfotpl-type-information toccolours vevent mw-content-ltr" 
style="width: 100%; direction: ltr;" cellpadding="4">
+<tr style="vertical-align: top">
+<td id="fileinfotpl_desc" class="fileinfo-paramfield">Description<span 
class="summary fn" style="display:none">Kerameikos October 2012 
15.JPG</span></td>
+<td class="description">
+<div class="description mw-content-ltr de" dir="ltr" lang="de" style=""><span 
class="language de" title="Deutsch"><b>Deutsch:</b></span> Kerameikos, Grave 
yard of ancient Athens.</div>
+<div class="description mw-content-ltr en" dir="ltr" lang="en" style=""><span 
class="language en" title=""><b>English:</b></span> Kerameikos, der größte und 
wichtigste der Friedhöfe des antiken Athens.</div>
+</td>
+</tr>
+<tr style="vertical-align: top">
+<td id="fileinfotpl_date" class="fileinfo-paramfield">Date</td>
+<td><span style="white-space:nowrap"><time class="dtstart" 
datetime="2012-10-27 11:38:59">27 October 2012, 11:38:59</time></span></td>
+</tr>
+<tr style="vertical-align: top">
+<td id="fileinfotpl_src" class="fileinfo-paramfield">Source</td>
+<td>Picture taken by Uploader</td>
+</tr>
+<tr style="vertical-align: top">
+<td id="fileinfotpl_aut" class="fileinfo-paramfield">Author</td>
+<td><a href="//commons.wikimedia.org/wiki/User:Marcus_Cyron" 
title="User:Marcus Cyron">Marcus Cyron</a></td>
+</tr>
+</table>
+</div>
+<h2><span class="mw-headline" id="Licensing">Licensing</span><span 
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a 
href="//commons.wikimedia.org/w/index.php?title=File:Kerameikos_October_2012_15.JPG&amp;action=edit&amp;section=2"
 title="Edit section: Licensing">edit</a><span 
class="mw-editsection-bracket">]</span></span></h2>
+<table cellspacing="8" cellpadding="0" style="width:100%; clear:both; 
text-align:center; margin:0.5em auto; background-color:#f9f9f9; border:2px 
solid #e0e0e0" class="layouttemplate licensetpl mw-content-ltr">
+<tr>
+<td style="width:90px;" rowspan="3"><img alt="w:en:Creative Commons" 
src="//upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png"
 width="90" height="36" 
srcset="//upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/135px-CC_some_rights_reserved.svg.png
 1.5x, 
//upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/180px-CC_some_rights_reserved.svg.png
 2x" data-file-width="744" data-file-height="300" /><br />
+<img alt="attribution" 
src="//upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png"
 width="24" height="24" 
srcset="//upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/36px-Cc-by_new_white.svg.png
 1.5x, 
//upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/48px-Cc-by_new_white.svg.png
 2x" data-file-width="64" data-file-height="64" /> <img alt="share alike" 
src="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png"
 width="24" height="24" 
srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/36px-Cc-sa_white.svg.png
 1.5x, 
//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/48px-Cc-sa_white.svg.png
 2x" data-file-width="64" data-file-height="64" /></td>
+<td>This file is licensed under the <a 
href="//en.wikipedia.org/wiki/en:Creative_Commons" class="extiw" 
title="w:en:Creative Commons">Creative Commons</a> <a rel="nofollow" 
class="external text" 
href="//creativecommons.org/licenses/by-sa/3.0/deed.en">Attribution-Share Alike 
3.0 Unported</a> license.</td>
+<td style="width:90px;" rowspan="3"></td>
+</tr>
+<tr style="text-align:center;">
+<td></td>
+</tr>
+<tr style="text-align:left;">
+<td>
+<dl>
+<dd>You are free:
+<ul>
+<li><b>to share</b> – to copy, distribute and transmit the work</li>
+<li><b>to remix</b> – to adapt the work</li>
+</ul>
+</dd>
+<dd>Under the following conditions:
+<ul>
+<li><b>attribution</b> – You must attribute the work in the manner specified 
by the author or licensor (but not in any way that suggests that they endorse 
you or your use of the work).</li>
+<li><b>share alike</b> – If you alter, transform, or build upon this work, you 
may distribute the resulting work only under the same or similar license to 
this one.</li>
+</ul>
+</dd>
+</dl>
+<p><span class="licensetpl_link" 
style="display:none;">http://creativecommons.org/licenses/by-sa/3.0</span> 
<span class="licensetpl_short" style="display:none;">CC-BY-SA-3.0</span> <span 
class="licensetpl_long" style="display:none;">Creative Commons 
Attribution-Share Alike 3.0</span> <span class="licensetpl_link_req" 
style="display:none;">true</span><span class="licensetpl_attr_req" 
style="display:none;">true</span></p>
+</td>
+</tr>
+</table>
+
+
+<!-- 
+NewPP limit report
+Parsed by mw1104
+CPU time usage: 0.476 seconds
+Real time usage: 0.538 seconds
+Preprocessor visited node count: 1707/1000000
+Preprocessor generated node count: 8891/1500000
+Post‐expand include size: 57269/2097152 bytes
+Template argument size: 9575/2097152 bytes
+Highest expansion depth: 15/40
+Expensive parser function count: 2/500
+Lua time usage: 0.157/10.000 seconds
+Lua memory usage: 754 KB/50 MB
+-->
+
+<!-- 
+Transclusion expansion time report (%,ms,calls,template)
+100.00% 1059.189      1 - -total
+ 19.76%  209.273      1 - Template:Delete
+ 18.99%  201.140      1 - Template:Autotranslate
+ 13.98%  148.037      1 - Template:Delete/layout
+ 10.61%  112.403      1 - Template:Information
+  4.10%   43.401      1 - Template:Hidden2
+  4.00%   42.320      1 - Template:Cc-by-sa-3.0
+  3.97%   42.088      1 - Template:Delete/lang
+  3.46%   36.660      1 - Template:Cc-by-sa-layout
+  3.36%   35.610     11 - Template:Dir
+-->
+
+<!-- Saved in parser cache with key 
commonswiki:pcache:idhash:26249824-1!*!0!!en!4!* and timestamp 20141130002123 
and revision id 139811360
+ -->
diff --git a/tests/phpunit/DataCollectorTest.php 
b/tests/phpunit/DataCollectorTest.php
index f8b2adb..0cfae2e 100644
--- a/tests/phpunit/DataCollectorTest.php
+++ b/tests/phpunit/DataCollectorTest.php
@@ -40,13 +40,40 @@
 
        /*------------------------------- Format tests 
--------------------------*/
 
-       public function testNoMetadata() {
+       public function testEmptyMetadata() {
                $this->templateParser->expects( $this->once() )->method( 
'parsePage' )
                        ->will( $this->returnValue( array(
                                TemplateParser::COORDINATES_KEY => array(),
                                TemplateParser::INFORMATION_FIELDS_KEY => 
array(),
                                TemplateParser::LICENSES_KEY => array(),
+                               TemplateParser::DELETION_KEY => array(),
                        ) ) );
+               $this->licenseParser->expects( $this->any() )->method( 
'parseLicenseString' )
+                       ->will( $this->returnValue( null ) );
+               $metadata = array();
+
+               $this->dataCollector->collect( $metadata, $this->file );
+
+               $this->assertMetadataValue( 'Categories', '', $metadata );
+               $this->assertMetadataValue( 'Assessments', '', $metadata );
+       }
+
+       public function testNoMetadata() {
+               $this->templateParser->expects( $this->once() )->method( 
'parsePage' )
+                       ->will( $this->returnValue( array() ) );
+               $this->licenseParser->expects( $this->any() )->method( 
'parseLicenseString' )
+                       ->will( $this->returnValue( null ) );
+               $metadata = array();
+
+               $this->dataCollector->collect( $metadata, $this->file );
+
+               $this->assertMetadataValue( 'Categories', '', $metadata );
+               $this->assertMetadataValue( 'Assessments', '', $metadata );
+       }
+
+       public function testMissingMetadata() {
+               $this->templateParser->expects( $this->once() )->method( 
'parsePage' )
+                       ->will( $this->returnValue( null ) );
                $this->licenseParser->expects( $this->any() )->method( 
'parseLicenseString' )
                        ->will( $this->returnValue( null ) );
                $metadata = array();
@@ -60,8 +87,6 @@
        public function testTemplateMetadataFormatForSingleValuedProperty() {
                $this->templateParser->expects( $this->once() )->method( 
'parsePage' )
                        ->will( $this->returnValue( array(
-                               TemplateParser::COORDINATES_KEY => array(),
-                               TemplateParser::INFORMATION_FIELDS_KEY => 
array(),
                                TemplateParser::LICENSES_KEY => array(
                                        array( 'UsageTerms' => 'foo' ),
                                ),
@@ -78,8 +103,6 @@
        public function testTemplateMetadataFormatForMultiValuedProperty() {
                $this->templateParser->expects( $this->once() )->method( 
'parsePage' )
                        ->will( $this->returnValue( array(
-                               TemplateParser::COORDINATES_KEY => array(),
-                               TemplateParser::INFORMATION_FIELDS_KEY => 
array(),
                                TemplateParser::LICENSES_KEY => array(
                                        array( 'UsageTerms' => 'foo' ),
                                ),
@@ -136,12 +159,14 @@
                        TemplateParser::COORDINATES_KEY => array( array( 'Foo' 
=> 'bar' ) ),
                        TemplateParser::INFORMATION_FIELDS_KEY => array( array( 
'Baz' => 'boom' ) ),
                        TemplateParser::LICENSES_KEY => array( array( 
'LicenseShortName' => 'quux' ) ),
+                       TemplateParser::DELETION_KEY => array( array( 
'DeletionReason' => 'quuux' ) ),
                ) ) );
 
                $this->assertMetadataValue( 'Foo', 'bar', $templateData );
                $this->assertMetadataValue( 'Baz', 'boom', $templateData );
                $this->assertMetadataValue( 'LicenseShortName', 'quux', 
$templateData );
                $this->assertMetadataValue( 'License', 'quux.name', 
$templateData );
+               $this->assertMetadataValue( 'DeletionReason', 'quuux', 
$templateData );
        }
 
        public function testGetTemplateMetadataForMultipleInfoTemplates() {
@@ -151,9 +176,7 @@
                $template1 = array( 'Artist' => 'a1', 'Foo' => 'x' );
                $template2 = array( 'Artist' => 'a2', 'Bar' => 'y' );
                $templateData = $getTemplateMetadataMethod->invokeArgs( 
$this->dataCollector, array( array(
-                       TemplateParser::COORDINATES_KEY => array(),
                        TemplateParser::INFORMATION_FIELDS_KEY => array( 
$template1, $template2 ),
-                       TemplateParser::LICENSES_KEY => array(),
                ) ) );
 
                $this->assertMetadataValue( 'Artist', 'a1', $templateData );
diff --git a/tests/phpunit/ParserTestHelper.php 
b/tests/phpunit/ParserTestHelper.php
index d90a292..3ed74c7 100644
--- a/tests/phpunit/ParserTestHelper.php
+++ b/tests/phpunit/ParserTestHelper.php
@@ -42,6 +42,8 @@
                'infotpl_class' => 'File_Fourth_Doctor.jpg',
                // {{Artwork}} + {{Photograph}}
                'multiple_infotpl' => 'File_Bust_of_Wilhelmine_of_Bayreuth.jpg',
+               // file marked for deletion
+               'deletion' => 'File_Kerameikos_October_2012_15.JPG',
        );
 
        /**
diff --git a/tests/phpunit/TemplateParserTest.php 
b/tests/phpunit/TemplateParserTest.php
index 399871b..8099f47 100644
--- a/tests/phpunit/TemplateParserTest.php
+++ b/tests/phpunit/TemplateParserTest.php
@@ -271,6 +271,17 @@
        }
 
        /**
+        * Test deletion reason etraction from the {{Nuke}} template
+        */
+       public function testNuke() {
+               $data = $this->parseTestHTML( 'deletion' );
+               $this->assertFieldEquals( 'DeletionReason', '[[Commons:Deletion 
requests/File:Kerameikos October 2012 15.JPG]]: '
+                       . 'As far as I know tourist signs as all road signs are 
not in the public domain. '
+                       . '--[[User:G.dallorto|User:G.dallorto]] ([[User 
talk:G.dallorto|<span class="signature-talk">talk</span>]]) '
+                       . '00:25, 16 November 2014 (UTC)', $data, 
TemplateParser::DELETION_KEY );
+       }
+
+       /**
         * Manually executed speed test to compare performance of the two 
parsers.
         */
        public function _testParsingSpeed() {

-- 
To view, visit https://gerrit.wikimedia.org/r/176510
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I849674af96cc3a781f87075e5cf823ac19ce7a3e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CommonsMetadata
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to