String prefix) throws APIException {
setText(prefix + " - " + GT._("Analyzing page {0}", page.getTitle()));
// Retrieve page content
API api = APIFactory.getAPI();
api.retrieveContents(getWikipedia(), Collections.singletonList(page), true, false);
PageAnalysis analysis = page.getAnalysis(page.getContents(), true);
// Check that robots are authorized to change this page
if (saveModifications) {
WPCConfiguration config = getWikipedia().getConfiguration();
List<String[]> nobotTemplates = config.getStringArrayList(
WPCConfigurationStringList.NOBOT_TEMPLATES);
if ((nobotTemplates != null) && (!nobotTemplates.isEmpty())) {
for (String[] nobotTemplate : nobotTemplates) {
String templateName = nobotTemplate[0];
List<PageElementTemplate> templates = analysis.getTemplates(templateName);
if ((templates != null) && (!templates.isEmpty())) {
if (analyzeNonFixed) {
Controller.runFullAnalysis(page.getTitle(), null, getWikipedia());
}
return;
}
}
}
}
// Analyze page to check if error has been found
List<CheckErrorPage> errorPages = CheckError.analyzeErrors(allAlgorithms, analysis, true);
boolean found = false;
if (errorPages != null) {
for (CheckErrorPage errorPage : errorPages) {
if (algorithm.equals(errorPage.getAlgorithm()) &&
errorPage.getErrorFound()) {
found = true;
}
}
}
CheckWiki checkWiki = APIFactory.getCheckWiki();
if (found) {
// Fix all errors that can be fixed
String newContents = page.getContents();
List<CheckErrorAlgorithm> usedAlgorithms = new ArrayList<CheckErrorAlgorithm>();
newContents = AutomaticFormatter.tidyArticle(page, newContents, allAlgorithms, true, usedAlgorithms);
// Save page if errors have been fixed
if ((!newContents.equals(page.getContents())) &&
(!usedAlgorithms.isEmpty())) {
if (!saveModifications) {
return;
}
StringBuilder comment = new StringBuilder();
if ((extraComment != null) && (extraComment.trim().length() > 0)) {
comment.append(extraComment.trim());
comment.append(" - ");
}
comment.append(getWikipedia().getCWConfiguration().getComment(usedAlgorithms));
setText(prefix + " - " + GT._("Fixing page {0}", page.getTitle()));
api.updatePage(
getWikipedia(), page, newContents,
getWikipedia().createUpdatePageComment(comment.toString(), null, true),
false);
countModified++;
for (CheckErrorAlgorithm usedAlgorithm : usedAlgorithms) {