(bug 6199) Generate error for unbalanced <ref>s

This basically uses the patch I posted to that bug two years ago.  It's crude, but it should avoid the most common false positives while hopefully not causing too many false negatives.  It should be possible to refine it to avoid even more false negatives, but for the time being, this will at least prevent most of the constant headaches that newbies get when chunks of articles vanish because they forgot a closing </ref>.
This commit is contained in:
Aryeh Gregor 2008-09-18 17:16:10 +00:00
parent 5bca5776eb
commit 1c902f410c
2 changed files with 18 additions and 0 deletions

View file

@ -43,6 +43,7 @@ Use <code>&lt;references /&gt;</code>, or <code>&lt;references group="..." /&gt;
Define more in the <nowiki>[[MediaWiki:Cite references link many format backlink labels]]</nowiki> message',
'cite_error_references_no_text' => 'Invalid <code>&lt;ref&gt;</code> tag;
no text was provided for refs named <code>$1</code>',
'cite_error_included_ref' => 'Closing &lt;/ref&gt; missing for &lt;ref&gt; tag',
/*
Output formatting

View file

@ -155,6 +155,23 @@ class Cite {
return $this->error( 'cite_error_ref_numeric_key' );
}
if( strpos(
preg_replace( '#<([^ ]+?).*?>.*?</\\1 *>|<!--.*?-->#', '', $str ),
'<ref>'
) !== false ) {
# (bug 6199) This most likely implies that someone left off the
# closing </ref> tag, which will cause the entire article to be
# eaten up until the next <ref>. So we bail out early instead.
# The fancy regex above first tries chopping out anything that
# looks like a comment or SGML tag, which is a crude way to avoid
# false alarms for <nowiki>, <pre>, etc.
#
# Possible improvement: print the warning, followed by the contents
# of the <ref> tag. This way no part of the article will be eaten
# even temporarily.
return $this->error( 'cite_error_included_ref' );
}
# Split these into groups.
if( $group === null ) {
$group = $default_group;