while (hasRemainingTask() && !shouldStop()) {
Object result = getNextResult();
if ((result != null) && (result instanceof Page)) {
boolean changed = false;
List<String> replacementsDone = new ArrayList<String>();
Page page = (Page) result;
String oldContents = page.getContents();
if (oldContents != null) {
String newContents = oldContents;
details.setLength(0);
for (Entry<String, List<AutomaticFixing>> replacement : replacements.entrySet()) {
replacementsDone.clear();
String tmpContents = AutomaticFixing.apply(replacement.getValue(), newContents, replacementsDone);
if (!newContents.equals(tmpContents)) {
newContents = tmpContents;
// Update description
if (description != null) {
if (!changed) {
String title =
"<a href=\"" + wiki.getSettings().getURL(page.getTitle(), false, secured) + "\">" +
page.getTitle() + "</a>";
description.append(GT._("Page {0}:", title));
description.append("\n");
description.append("<ul>\n");
changed = true;
}
for (String replacementDone : replacementsDone) {
description.append("<li>");
description.append(replacementDone);
description.append("</li>\n");
}
}
// Memorize replacement
if ((replacement.getKey() != null) && (replacement.getKey().length() > 0)) {
if (details.length() > 0) {
details.append(", ");
}
details.append(replacement.getKey());
}
}
}
// Page contents has been modified
if (!oldContents.equals(newContents)) {
// Initialize comment
StringBuilder fullComment = new StringBuilder();
fullComment.append(wiki.createUpdatePageComment(comment, details.toString(), false));
// Apply automatic Check Wiki fixing
if (automaticCW) {
List<CheckErrorAlgorithm> algorithms = CheckErrorAlgorithms.getAlgorithms(wiki);
List<CheckErrorAlgorithm> usedAlgorithms = new ArrayList<CheckErrorAlgorithm>();
newContents = AutomaticFormatter.tidyArticle(
page, newContents, algorithms, false, usedAlgorithms);
if (!usedAlgorithms.isEmpty()) {
fullComment.append(" / ");
fullComment.append(wiki.getCWConfiguration().getComment(usedAlgorithms));
if (description != null) {
for (CheckErrorAlgorithm algorithm : usedAlgorithms) {
description.append("<li>");
description.append(algorithm.getShortDescriptionReplaced());
description.append("</li>\n");
}
}
}
}
if ((description != null) && (changed)) {
description.append("</ul>\n");
}
// Save page
setText(GT._("Updating page {0}", page.getTitle()));
count++;
if (save) {
api.updatePage(wiki, page, newContents, fullComment.toString(), false);
if (updateDabWarning) {
dabWarnings.updateWarning(