String contents = todoSubpage.getContents();
if (contents == null) {
contents = "";
}
PageAnalysis analysis = todoSubpage.getAnalysis(contents, true);
PageElementTemplate templateWarning = getFirstWarningTemplate(analysis);
// If warning is missing, add it
if (templateWarning == null) {
if (!createWarning) {
return false;
}
setText(getMessageUpdateWarning(todoSubpage.getTitle()));
StringBuilder tmp = new StringBuilder(contents);
if ((tmp.length() > 0) && (tmp.charAt(tmp.length() - 1) != '\n')) {
tmp.append('\n');
}
tmp.append("* ");
addWarning(tmp, pageRevId, elements);
tmp.append('\n');
updatePage(
todoSubpage, tmp.toString(),
wiki.formatComment(
getWarningComment(elements),
automaticEdit),
false);
// Inform creator and modifiers of the page
informContributors(analysis, elements, creator, modifiers);
return true;
}
// Check if modifications are needed
if (isModified(elements, templateWarning)) {
StringBuilder tmp = new StringBuilder();
int index = templateWarning.getBeginIndex();
while ((index > 0) && (contents.charAt(index) != '\n')) {
index--;
}
if (index > 0) {
tmp.append(contents.substring(0, index));
tmp.append('\n');
}
tmp.append("* ");
addWarning(tmp, pageRevId, elements);
tmp.append('\n');
index = templateWarning.getEndIndex();
while ((index < contents.length()) && (contents.charAt(index) != '\n')) {
index++;
}
index++;
if (index < contents.length()) {