@@ -164,7 +164,7 @@ public SimplePage getWikiSimplePage(PageLocation loc) {
164164 public boolean doesPageExist (PageLocation loc ) {
165165 JsonNode serverOutput = getWikiPageJsonCode (loc );
166166
167- return serverOutput .findValue ("missing" ) == null ; // If contains missing tag, the page is missing.
167+ return serverOutput .findValue ("missing" ) == null && serverOutput . findValue ( "invalid" ) == null ; // If contains missing tag, the page is missing.
168168 }
169169
170170 private JsonNode getWikiPageJsonCode (PageLocation loc ) {
@@ -351,7 +351,8 @@ private void getPageRevisions(Page page) {
351351 public ArrayList <Revision > getPastRevisions (PageLocation loc , int localRevisionDepth , boolean getContent ) {
352352 ArrayList <Revision > toReturn = new ArrayList <>();
353353
354- String serverOutput = APIcommand (new QueryPageRevisions (loc , Math .min (localRevisionDepth , APIlimit ), getContent ));
354+ int revDepth = Math .min (localRevisionDepth , APIlimit );
355+ String serverOutput = APIcommand (new QueryPageRevisions (loc , revDepth , getContent ));
355356
356357
357358 // Read in the Json!!!
@@ -416,7 +417,8 @@ public ArrayList<Revision> getRecentChanges(String language, int depth) {
416417
417418 int revisionsNeeded = depth ;
418419 do {
419- int batchSize = Math .min (Math .min (30 , APIlimit ), revisionsNeeded );
420+ revisionsNeeded = depth - toReturn .size ();
421+ int batchSize = Math .min (APIlimit , revisionsNeeded );
420422
421423 //Make a query call.
422424 String serverOutput ;
@@ -465,8 +467,6 @@ public ArrayList<Revision> getRecentChanges(String language, int depth) {
465467 toReturn .add (revision );
466468 }
467469
468- revisionsNeeded -= batchSize ;
469-
470470 //Try continuing the query.
471471 if (rootNode .findValue ("rccontinue" ) != null ) {
472472 rccontinue = rootNode .findValue ("rccontinue" ).asText ();
@@ -475,7 +475,7 @@ public ArrayList<Revision> getRecentChanges(String language, int depth) {
475475 } else {
476476 rccontinue = null ;
477477 }
478- } while (rccontinue != null && revisionsNeeded != 0 );
478+ } while (rccontinue != null && toReturn . size () < depth );
479479
480480 return toReturn ;
481481 }
@@ -618,9 +618,10 @@ public ArrayList<PageLocation> getPagesThatLinkTo(PageLocation loc, int depth) {
618618
619619 logFine ("Getting pages that link to: " + loc .getTitle ());
620620
621- int backlinksNeeded = depth ;
621+ int backlinksNeeded ;
622622 do {
623623 //Make a query call.
624+ backlinksNeeded = depth - toReturn .size ();
624625 int batchSize = Math .min (Math .min (30 , APIlimit ), backlinksNeeded );
625626
626627 String serverOutput ;
@@ -651,8 +652,6 @@ public ArrayList<PageLocation> getPagesThatLinkTo(PageLocation loc, int depth) {
651652 toReturn .add (backlinkLoc );
652653 }
653654
654- backlinksNeeded -= batchSize ;
655-
656655 //Try continuing the query.
657656 if (rootNode .findValue ("blcontinue" ) != null ) {
658657 blcontinue = rootNode .findValue ("blcontinue" ).asText ();
@@ -661,7 +660,7 @@ public ArrayList<PageLocation> getPagesThatLinkTo(PageLocation loc, int depth) {
661660 } else {
662661 blcontinue = null ;
663662 }
664- } while (blcontinue != null && backlinksNeeded != 0 );
663+ } while (blcontinue != null && toReturn . size () < depth );
665664
666665 return toReturn ;
667666 }
@@ -705,26 +704,28 @@ public ArrayList<PageLocation> getAllPages(String language, int depth, String fr
705704
706705 do {
707706 //Make query call.
707+ int pagesNeeded = toReturn .size () - depth ;
708+ int batchSize = Math .min (APIlimit , pagesNeeded );
708709 String serverOutput ;
709710 if (apnamespace == null ) {
710711 if (apcontinue == null ) {
711712 if (from != null ) {
712- serverOutput = APIcommand (new QueryAllPages (language , APIlimit , from ));
713+ serverOutput = APIcommand (new QueryAllPages (language , batchSize , from ));
713714 } else {
714- serverOutput = APIcommand (new QueryAllPages (language , APIlimit ));
715+ serverOutput = APIcommand (new QueryAllPages (language , batchSize ));
715716 }
716717 } else {
717- serverOutput = APIcommand (new QueryAllPages (language , APIlimit , apcontinue ));
718+ serverOutput = APIcommand (new QueryAllPages (language , batchSize , apcontinue ));
718719 }
719720 } else {
720721 if (apcontinue == null ) {
721722 if (from != null ) {
722- serverOutput = APIcommand (new QueryAllPages (language , APIlimit , from , apnamespace ));
723+ serverOutput = APIcommand (new QueryAllPages (language , batchSize , from , apnamespace ));
723724 } else {
724- serverOutput = APIcommand (new QueryAllPages (language , APIlimit , apnamespace ));
725+ serverOutput = APIcommand (new QueryAllPages (language , batchSize , apnamespace ));
725726 }
726727 } else {
727- serverOutput = APIcommand (new QueryAllPages (language , APIlimit , apcontinue , apnamespace ));
728+ serverOutput = APIcommand (new QueryAllPages (language , batchSize , apcontinue , apnamespace ));
728729 }
729730 }
730731
@@ -757,7 +758,7 @@ public ArrayList<PageLocation> getAllPages(String language, int depth, String fr
757758 } else {
758759 apcontinue = null ;
759760 }
760- } while (apcontinue != null && toReturn .size () != depth );
761+ } while (apcontinue != null && toReturn .size () < depth );
761762
762763 return toReturn ;
763764 }
@@ -1188,7 +1189,7 @@ public ArrayList<ArrayList<Revision>> getUserContribs(ArrayList<User> users, int
11881189 logFine (userLogMessage );
11891190
11901191 //Method code below
1191- ArrayList <ArrayList <Revision >> multiContribs = new ArrayList <ArrayList < Revision > >();
1192+ ArrayList <ArrayList <Revision >> multiContribs = new ArrayList <>();
11921193
11931194 String language = users .get (0 ).getLanguage ();
11941195
@@ -1206,17 +1207,13 @@ public ArrayList<ArrayList<Revision>> getUserContribs(ArrayList<User> users, int
12061207 User user = users .get (u );
12071208
12081209 //Query user's contributions.
1209- int rev = 0 ;
1210+ multiContribs . add ( new ArrayList < Revision >()) ;
12101211 boolean moreRevisionsExist = true ;
12111212 String queryContinue = null ; // User for continuing queries.
1212- while (rev < depth && moreRevisionsExist ) {
1213+ while (multiContribs . get ( u ). size () < depth && moreRevisionsExist ) {
12131214 //Query the server.
1214- int querySize = -1 ;
1215- if (rev + maxQuerySize < depth ) {
1216- querySize = maxQuerySize ;
1217- } else {
1218- querySize = depth - rev ;
1219- }
1215+ int querySize = Math .min (maxQuerySize , depth - multiContribs .get (u ).size ());
1216+
12201217 APIcommand queryUserContribs = new QueryUserContribs (user , properties , querySize );
12211218 if (queryContinue != null ) {
12221219 queryUserContribs .addParameter ("ucstart" , queryContinue );
@@ -1236,8 +1233,6 @@ public ArrayList<ArrayList<Revision>> getUserContribs(ArrayList<User> users, int
12361233 }
12371234
12381235 //Parse Json for contribs
1239- ArrayList <Revision > contribs = new ArrayList <Revision >();
1240-
12411236 JsonNode queryNode = rootNode .findValue ("query" );
12421237 JsonNode userContribs = queryNode .findValue ("usercontribs" );
12431238
@@ -1265,13 +1260,9 @@ public ArrayList<ArrayList<Revision>> getUserContribs(ArrayList<User> users, int
12651260 }
12661261
12671262 //Package and ship the revision! Then have it sink due to a bunyip and cucumber sandwiches.
1268- contribs .add (new Revision (loc , userName , comment , date , flags ));
1263+ multiContribs . get ( u ) .add (new Revision (loc , userName , comment , date , flags ));
12691264 }
12701265
1271- multiContribs .add (contribs );
1272-
1273- rev += querySize ;
1274-
12751266 //Parse for query continue
12761267 JsonNode queryContinueNode = rootNode .findValue ("query-continue" );
12771268 if (queryContinueNode == null ) {
@@ -1658,13 +1649,13 @@ private String APIcommandHTTP(APIcommand command) {
16581649 }
16591650 }
16601651
1661- //Follor the url!
1652+ //Follow the url!
16621653 try {
1663- String [] output = getURL ( url , command . shouldUnescapeHTML ( ));
1654+ String output = removeBOM ( EntityUtils . toString ( getURL ( url ) ));
16641655 if (output == null ) {
16651656 throw new NetworkError ("Cannot connect to server at: " + baseURL );
16661657 } else {
1667- return ArrayUtils . compactArray ( output , " \n " ) ;
1658+ return output ;
16681659 }
16691660 } catch (IOException e ) {
16701661 throw new Error (e );
0 commit comments