if ((link != null) && (link.getBeginIndex() == currentIndex)) {
shouldCount = false;
}
}
if (shouldCount) {
PageElementImage image = analysis.isInImage(currentIndex);
if ((image != null) && (image.getBeginIndex() == currentIndex)) {
shouldCount = false;
}
}
if (shouldCount) {
PageElementCategory category = analysis.isInCategory(currentIndex);
if ((category != null) && (category.getBeginIndex() == currentIndex)) {
shouldCount = false;
}
}
if (shouldCount) {
PageElementLanguageLink link = analysis.isInLanguageLink(currentIndex);
if ((link != null) && (link.getBeginIndex() == currentIndex)) {
shouldCount = false;
}
}
if (shouldCount) {
PageElementInterwikiLink link = analysis.isInInterwikiLink(currentIndex);
if ((link != null) && (link.getBeginIndex() == currentIndex)) {
shouldCount = false;
}
}
if (shouldCount) {
PageElementExternalLink link = analysis.isInExternalLink(currentIndex + 1);
if ((link != null) && (link.getBeginIndex() == currentIndex + 1)) {
shouldCount = false;
}
}
if (shouldCount) {
if ((analysis.isInComment(currentIndex) != null) ||
(analysis.getSurroundingTag(PageElementTag.TAG_WIKI_NOWIKI, currentIndex) != null) ||
(analysis.getSurroundingTag(PageElementTag.TAG_WIKI_MATH, currentIndex) != null) ||
(analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SCORE, currentIndex) != null) ||
(analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SOURCE, currentIndex) != null) ||
(analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SYNTAXHIGHLIGHT, currentIndex) != null) ||
(analysis.isInTag(currentIndex) != null)) {
shouldCount = false;
}
}
if (shouldCount) {
PageElementTemplate template = analysis.isInTemplate(currentIndex + 2);
if ((template != null) && (contents.startsWith("]]", template.getEndIndex()))) {
shouldCount = false;
}
}
if (shouldCount) {
if (errors == null) {
return true;
}
result = true;
// Check if there is a potential end
int tmpIndex = currentIndex + 2;
boolean errorReported = false;
boolean finished = false;
while (!finished && (tmpIndex < maxLength)) {
char tmpChar = contents.charAt(tmpIndex);
if (REJECTED_CHARS.indexOf(tmpChar) >= 0) {
finished = true;
} else if (tmpChar == ']') {
int tmpIndex2 = tmpIndex + 1;
while ((tmpIndex2 < maxLength) &&
(contents.charAt(tmpIndex2) != ']') &&
(REJECTED_CHARS.indexOf(contents.charAt(tmpIndex2)) < 0)) {
tmpIndex2++;
}
String suffix = "";
if ((tmpIndex2 < maxLength) && (contents.charAt(tmpIndex2) == ']')) {
suffix = contents.substring(tmpIndex + 1, tmpIndex2 + 1);
} else {
tmpIndex2 = tmpIndex;
}
CheckErrorResult errorResult = createCheckErrorResult(
analysis, currentIndex, tmpIndex2 + 1);
// Check if the situation is something like [[http://....] (replacement: [http://....])
boolean protocolFound = PageElementExternalLink.isPossibleProtocol(contents, currentIndex + 2);
if (protocolFound) {
errorResult.addReplacement(contents.substring(currentIndex + 1, tmpIndex2 + 1));
}
errorResult.addReplacement(contents.substring(currentIndex, tmpIndex + 1) + "]" + suffix);
if (suffix.length() > 0) {
errorResult.addReplacement(contents.substring(currentIndex, tmpIndex) + suffix + "]");
}
errors.add(errorResult);
errorReported = true;
finished = true;
} else if (tmpChar == '}') {
int lastChar = tmpIndex;
if ((lastChar + 1 < maxLength) && (contents.charAt(lastChar + 1) == '}')) {
lastChar++;
}
CheckErrorResult errorResult = createCheckErrorResult(
analysis, currentIndex, lastChar + 1);
errorResult.addReplacement(contents.substring(currentIndex, tmpIndex) + "]]");
errorResult.addReplacement("{{" + contents.substring(currentIndex + 2, tmpIndex) + "}}");
errors.add(errorResult);
errorReported = true;
finished = true;
}
tmpIndex++;
}
// Default
if (!errorReported) {
CheckErrorResult errorResult = createCheckErrorResult(
analysis, currentIndex, currentIndex + 2);
errorResult.addReplacement("", GT._("Delete"));
errors.add(errorResult);
}
}
currentIndex = contents.indexOf("[[", currentIndex + 2);
}
// Analyze each internal link to see if it contains a [
for (PageElementInternalLink link : analysis.getInternalLinks()) {
String text = link.getText();
if (text != null) {
text = cleanText(text);
if (text != null) {
if (errors == null) {
return true;
}
result = true;
CheckErrorResult errorResult = createCheckErrorResult(
analysis, link.getBeginIndex(), link.getEndIndex());
errorResult.addReplacement(PageElementInternalLink.createInternalLink(
link.getLink(), link.getAnchor(), text));
errors.add(errorResult);
}
}
}
// Analyze each image to see if it contains a [
for (PageElementImage image : analysis.getImages()) {
String text = image.getDescription();
String modifiedText = cleanText(text);
String alt = image.getAlternateDescription();
String modifiedAlt = cleanText(alt);
if ((modifiedText != null) || (modifiedAlt != null)) {
if (errors == null) {
return true;
}
result = true;
CheckErrorResult errorResult = createCheckErrorResult(
analysis, image.getBeginIndex(), image.getEndIndex());
errorResult.addReplacement(image.getDescriptionReplacement(
(modifiedText != null) ? modifiedText : text,
(modifiedAlt != null) ? modifiedAlt : alt));
errors.add(errorResult);
}
}