Skip to content

Commit

Permalink
added flag to getContribs() to return new pages only, closes #22
Browse files Browse the repository at this point in the history
Also included:
* Added revid field to Revision
* Bump okhttp version
  • Loading branch information
fastily committed Apr 8, 2020
1 parent 50161ef commit 691a5e9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ repositories {

dependencies {
api "com.google.code.gson:gson:2.8.6"
api "com.squareup.okhttp3:okhttp:4.4.0"
api "com.squareup.okhttp3:okhttp:4.5.0"

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.1'
//testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.5.2'

testImplementation 'com.squareup.okhttp3:mockwebserver:4.4.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.5.0'
}

test {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/fastily/jwiki/core/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
Expand Down Expand Up @@ -55,8 +54,7 @@ protected ApiClient(Wiki wiki, Proxy proxy)
{
this.wiki = wiki;

OkHttpClient.Builder builder = new OkHttpClient.Builder().cookieJar(new JwikiCookieJar()).readTimeout(2, TimeUnit.MINUTES)
.protocols(List.of(Protocol.HTTP_1_1));
OkHttpClient.Builder builder = new OkHttpClient.Builder().cookieJar(new JwikiCookieJar()).readTimeout(2, TimeUnit.MINUTES);
if (proxy != null)
builder.proxy(proxy);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fastily/jwiki/core/WQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class WQuery
* Default parameters for listing page revisions
*/
public static final QTemplate REVISIONS = new QTemplate(
FL.pMap("prop", "revisions", "rvprop", "timestamp|user|comment|content", "titles", null), "rvlimit", "revisions");
FL.pMap("prop", "revisions", "rvprop", "comment|content|ids|timestamp|user", "titles", null), "rvlimit", "revisions");

/**
* Default parameters for listing searches
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/fastily/jwiki/core/Wiki.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,10 @@ public int getCategorySize(String title)
* @param cap The maximum number of results to return. Optional, disable with -1 (<b>caveat</b>: this will get *all* of a user's contributions)
* @param olderFirst Set to true to enumerate from older → newer revisions
* @param ns Restrict titles returned to the specified Namespace(s). Optional, leave blank to select all namespaces.
* @param createdOnly Filter returned titles for instances where the contribution was a page creation. Optional, set false to disable.
* @return A list of contributions.
*/
public ArrayList<Contrib> getContribs(String user, int cap, boolean olderFirst, NS... ns)
public ArrayList<Contrib> getContribs(String user, int cap, boolean olderFirst, boolean createdOnly, NS... ns)
{
conf.log.info(this, "Fetching contribs of " + user);

Expand All @@ -759,6 +760,8 @@ public ArrayList<Contrib> getContribs(String user, int cap, boolean olderFirst,
wq.set("ucnamespace", nsl.createFilter(ns));
if (olderFirst)
wq.set("ucdir", "newer");
if(createdOnly)
wq.set("ucshow", "new");

ArrayList<Contrib> l = new ArrayList<>();
while (wq.has())
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/fastily/jwiki/dwrap/Revision.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*/
public class Revision extends DataEntry
{
/**
* The unique id associated with this revision.
*/
public long revid;

/**
* The text of this revision
*/
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/fastily/jwiki/test/QueryTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void testGetCategorySize()
public void testGetContribs()
{
// Test 1
ArrayList<Contrib> result = wiki.getContribs("FastilyClone", -1, false, NS.FILE);
ArrayList<Contrib> result = wiki.getContribs("FastilyClone", -1, false, false, NS.FILE);

assertEquals("File:FCTest2.svg", result.get(0).title); // descending
assertEquals("File:FCTest1.png", result.get(1).title);
Expand All @@ -226,11 +226,11 @@ public void testGetContribs()
assertEquals(Instant.parse("2015-10-20T00:28:32Z"), result.get(1).timestamp);

// Test 2
result = wiki.getContribs("FastilyClone", 1, true, NS.FILE);
result = wiki.getContribs("FastilyClone", 1, true, false, NS.FILE);
assertEquals("File:FCTest1.png", result.get(0).title);

// Test 3 - non-existent user
result = wiki.getContribs("Fastilyy", 10, true);
result = wiki.getContribs("Fastilyy", 10, true, false);
assertTrue(result.isEmpty());
}

Expand Down Expand Up @@ -331,6 +331,7 @@ public void testGetRevisions()
ArrayList<Revision> result = wiki.getRevisions("User:FastilyClone/Page/1", -1, false, null, null);

assertEquals(3, result.size());
assertEquals(244465, result.get(0).revid);
assertEquals("1", result.get(1).text);
assertEquals("s0", result.get(2).summary);
assertEquals(Instant.parse("2015-10-23T05:58:54Z"), result.get(0).timestamp);
Expand Down

0 comments on commit 691a5e9

Please sign in to comment.