if (warningTemplateName != null) {
setText(GT._("Retrieving talk pages including {0}", "{{" + warningTemplateName + "}}"));
String templateTitle = wikiConfiguration.getPageTitle(
Namespace.TEMPLATE,
warningTemplateName);
Page warningTemplate = DataManager.getPage(
wiki, templateTitle, null, null, null);
api.retrieveEmbeddedIn(
wiki, warningTemplate,
configuration.getEncyclopedicTalkNamespaces(),
false);
warningPages.addAll(warningTemplate.getRelatedPages(Page.RelatedPages.EMBEDDED_IN));
}
// Retrieve articles in categories for ISBN errors
List<String> categories = configuration.getStringList(WPCConfigurationStringList.ISBN_ERRORS_CATEGORIES);
if (categories != null) {
for (String category : categories) {
String categoryTitle = wikiConfiguration.getPageTitle(Namespace.CATEGORY, category);
Page categoryPage = DataManager.getPage(wiki, categoryTitle, null, null, null);
api.retrieveCategoryMembers(wiki, categoryPage, 0, false);
List<Page> categoryMembers = categoryPage.getRelatedPages(
Page.RelatedPages.CATEGORY_MEMBERS);
if (categoryMembers != null) {
warningPages.addAll(categoryMembers);
}
}
}
// Retrieve articles listed for ISBN errors in Check Wiki
retrieveCheckWikiPages(70, warningPages); // Incorrect length
retrieveCheckWikiPages(71, warningPages); // Incorrect X
retrieveCheckWikiPages(72, warningPages); // Incorrect ISBN-10
retrieveCheckWikiPages(73, warningPages); // Incorrect ISBN-13
// Construct list of articles with warning
setText(GT._("Constructing list of articles with warning"));
HashSet<Page> tmpWarningPages = new HashSet<Page>();
List<Integer> encyclopedicNamespaces = configuration.getEncyclopedicNamespaces();
for (Page warningPage : warningPages) {
// Get article page for talks pages and to do sub-pages
String title = warningPage.getTitle();
if (!warningPage.isArticle()) {
String todoSubpage = configuration.getString(WPCConfigurationString.TODO_SUBPAGE);
if (title.endsWith("/" + todoSubpage)) {
title = title.substring(0, title.length() - 1 - todoSubpage.length());
}
Integer namespace = warningPage.getNamespace();
if (namespace != null) {
Namespace namespaceTalk = wikiConfiguration.getNamespace(namespace.intValue());
if (namespaceTalk != null) {
int colonIndex = title.indexOf(':');
if (colonIndex >= 0) {
title = title.substring(colonIndex + 1);
}
if (namespace != Namespace.MAIN_TALK) {
title = wikiConfiguration.getPageTitle(namespace - 1, title);
}
}
}
}
// Add article to the list
Page page = DataManager.getPage(wiki, title, null, null, null);
if (encyclopedicNamespaces.contains(page.getNamespace()) &&
!tmpWarningPages.contains(page)) {
tmpWarningPages.add(page);
}
}
if (getWindow() != null) {
int answer = getWindow().displayYesNoWarning(GT._(
"Analysis found {0} articles to check for ISBN errors.\n" +
"Do you want to update the warnings ?",
Integer.valueOf(tmpWarningPages.size()).toString() ));
if (answer != JOptionPane.YES_OPTION) {
return Integer.valueOf(0);
}
}
// Sort the list of articles
warningPages.clear();
warningPages.addAll(tmpWarningPages);
tmpWarningPages.clear();
Collections.sort(warningPages, PageComparator.getTitleFirstComparator());
if (warningPages.isEmpty()) {
return Integer.valueOf(0);
}
}
// Working with sublists
UpdateISBNWarningTools tools = new UpdateISBNWarningTools(wiki, this, true, automaticEdit);
tools.setContentsAvailable(contentsAvailable);
tools.prepareErrorsMap();
if (simulation) {
tools.setSimulation(true);
}
String lastTitle = null;
while (!warningPages.isEmpty()) {
// Creating sublist
int size = Math.min(10, warningPages.size());
List<Page> sublist = new ArrayList<Page>(size);
while ((sublist.size() < size) && (warningPages.size() > 0)) {
Page page = warningPages.remove(0);
sublist.add(page);
}
if (sublist.isEmpty()) {
errors = tools.getErrorsMap();
displayResult(stats, startTime, errors);