Skip to content

Commit

Permalink
getSharedDuplicatesOf now includes namespace prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
fastily committed Oct 13, 2018
1 parent d6e9586 commit a24c76a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/java/fastily/jwiki/core/MQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,7 @@ public static HashMap<String, ArrayList<String>> getDuplicatesOf(Wiki wiki, bool

/**
* Gets shared (non-local) duplicates of a file. PRECONDITION: The Wiki this query is run against has the
* <a href="https://www.mediawiki.org/wiki/Extension:GlobalUsage">GlobalUsage</a> extension installed. Note that
* results are returned *without* a namespace prefix.
* <a href="https://www.mediawiki.org/wiki/Extension:GlobalUsage">GlobalUsage</a> extension installed.
*
* @param wiki The wiki object to use
* @param titles The titles to query
Expand All @@ -469,7 +468,7 @@ public static HashMap<String, ArrayList<String>> getSharedDuplicatesOf(Wiki wiki
getContProp(wiki, titles, WQuery.DUPLICATEFILES, null, "duplicatefiles"), "name", "shared");

HashMap<String, ArrayList<String>> 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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/fastily/jwiki/core/Wiki.java
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,7 @@ public ArrayList<Revision> 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
* <a href="https://www.mediawiki.org/wiki/Extension:GlobalUsage">GlobalUsage</a> extension installed. Note that
* results are returned *without* a namespace prefix.
* <a href="https://www.mediawiki.org/wiki/Extension:GlobalUsage">GlobalUsage</a> extension installed.
*
* @param title The title of the file to query
* @return An ArrayList containing shared duplicates of the file
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/fastily/jwiki/test/MockQueryTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> l = wiki.getSharedDuplicatesOf("File:Test.jpg");

assertEquals(1, l.size());
assertTrue(l.contains("File:TestTest.jpg"));
}

}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
}
}

0 comments on commit a24c76a

Please sign in to comment.