diff --git a/src/main/java/fastily/jwiki/core/MQuery.java b/src/main/java/fastily/jwiki/core/MQuery.java index 8f6261a..fc273a9 100644 --- a/src/main/java/fastily/jwiki/core/MQuery.java +++ b/src/main/java/fastily/jwiki/core/MQuery.java @@ -456,8 +456,7 @@ public static HashMap> getDuplicatesOf(Wiki wiki, bool /** * Gets shared (non-local) duplicates of a file. PRECONDITION: The Wiki this query is run against has the - * GlobalUsage extension installed. Note that - * results are returned *without* a namespace prefix. + * GlobalUsage extension installed. * * @param wiki The wiki object to use * @param titles The titles to query @@ -469,7 +468,7 @@ public static HashMap> getSharedDuplicatesOf(Wiki wiki getContProp(wiki, titles, WQuery.DUPLICATEFILES, null, "duplicatefiles"), "name", "shared"); HashMap> l = new HashMap<>(); - xl.forEach((k, v) -> l.put(k, FL.toAL(v.stream().filter(t -> t.y != null).map(t -> t.x.replace('_', ' '))))); + xl.forEach((k, v) -> l.put(k, FL.toAL(v.stream().filter(t -> t.y != null).map(t -> wiki.convertIfNotInNS(t.x.replace('_', ' '), NS.FILE))))); return l; } diff --git a/src/main/java/fastily/jwiki/core/Wiki.java b/src/main/java/fastily/jwiki/core/Wiki.java index 9d1be80..3165cb7 100644 --- a/src/main/java/fastily/jwiki/core/Wiki.java +++ b/src/main/java/fastily/jwiki/core/Wiki.java @@ -994,8 +994,7 @@ public ArrayList getRevisions(String title, int cap, boolean olderFirs /** * Gets the shared (non-local) duplicates of a file. PRECONDITION: The Wiki this query is run against has the - * GlobalUsage extension installed. Note that - * results are returned *without* a namespace prefix. + * GlobalUsage extension installed. * * @param title The title of the file to query * @return An ArrayList containing shared duplicates of the file diff --git a/src/test/java/fastily/jwiki/test/MockQueryTests.java b/src/test/java/fastily/jwiki/test/MockQueryTests.java index 7c6d372..0f22969 100644 --- a/src/test/java/fastily/jwiki/test/MockQueryTests.java +++ b/src/test/java/fastily/jwiki/test/MockQueryTests.java @@ -220,4 +220,19 @@ public void testSearch() assertTrue(l.contains("Git")); assertTrue(l.contains("GitHub Pages")); } + + /** + * Tests fetching of shared duplicate files + */ + @Test + public void testGetSharedDuplicateOf() + { + addResponse("mockSharedDuplicateFiles"); + + ArrayList l = wiki.getSharedDuplicatesOf("File:Test.jpg"); + + assertEquals(1, l.size()); + assertTrue(l.contains("File:TestTest.jpg")); + } + } \ No newline at end of file diff --git a/src/test/resources/fastily/jwiki/test/mockSharedDuplicateFiles.json b/src/test/resources/fastily/jwiki/test/mockSharedDuplicateFiles.json new file mode 100644 index 0000000..84c54bb --- /dev/null +++ b/src/test/resources/fastily/jwiki/test/mockSharedDuplicateFiles.json @@ -0,0 +1,25 @@ +{ + "batchcomplete": "", + "query": { + "pages": { + "111111": { + "pageid": 111111, + "ns": 6, + "title": "File:Test.jpg", + "duplicatefiles": [ + { + "name": "TestTest.jpg", + "user": "Foo", + "timestamp": "2018-03-03T21:03:22Z", + "shared": "" + }, + { + "name": "LocalOnlyDuplicate.jpg", + "user": "Foo", + "timestamp": "2018-03-03T21:03:22Z" + } + ] + } + } + } +} \ No newline at end of file