* @throws APIException
*/
@Override
protected boolean retrievePageInformation(
List<Page> pages) throws APIException {
MediaWiki mw = MediaWiki.getMediaWikiAccess(worker);
// Retrieving links in each page
if (!linksAvailable) {
for (Page page : pages) {
mw.retrieveAllLinks(wiki, page, Namespace.MAIN, null, false, false);
}
mw.block(true);
if (shouldStop()) {
return false;
}
}
// Retrieving disambiguation information in each page
boolean hasDisambiguationLink = false;
if (!dabInformationAvailable) {
if (!wiki.isDisambiguationPagesLoaded()) {
List<Page> tmpPages = new ArrayList<Page>();
for (Page page : pages) {
for (int numLink = 0; numLink < page.getLinks().size(); numLink++) {
Page link = page.getLinks().get(numLink);
if (dabPages.containsKey(link.getTitle())) {
page.getLinks().set(numLink, dabPages.get(link.getTitle()));
hasDisambiguationLink = true;
} else if (nonDabPages.containsKey(link.getTitle())) {
page.getLinks().set(numLink, nonDabPages.get(link.getTitle()));
} else {
tmpPages.add(link);
}
}
}
if (!tmpPages.isEmpty()) {
mw.retrieveDisambiguationInformation(wiki, tmpPages, null, false, false, true);
}
for (Page page : tmpPages) {
if (Boolean.TRUE.equals(page.isDisambiguationPage())) {
dabPages.put(page.getTitle(), page);
hasDisambiguationLink = true;
} else {
nonDabPages.put(page.getTitle(), page);
}
}
} else {
for (Page page : pages) {
List<Page> links = page.getLinksWithRedirect();
for (int numLink = 0; numLink < links.size(); numLink++) {
Page link = links.get(numLink);
if (Boolean.TRUE.equals(wiki.isDisambiguationPage(link))) {
link.setDisambiguationPage(Boolean.TRUE);
hasDisambiguationLink = true;
} else {
link.setDisambiguationPage(Boolean.FALSE);
}
}
}
}
if (shouldStop()) {
return false;
}
}
// Retrieving page contents
if (hasDisambiguationLink && !getContentsAvailable()) {
List<Page> tmpPages = new ArrayList<Page>();
for (Page page : pages) {
boolean toAdd = false;
for (Page link : page.getLinks()) {
if (Boolean.TRUE.equals(link.isDisambiguationPage())) {
toAdd = true;
}
}
if (toAdd) {
tmpPages.add(page);
}
}
if (!tmpPages.isEmpty()) {
mw.retrieveContents(wiki, tmpPages, true, false, false, false);
}
}
return true;
}