mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CiteThisPage
synced 2024-11-27 17:00:15 +00:00
(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:
parent
5bca5776eb
commit
1c902f410c
|
@ -43,6 +43,7 @@ Use <code><references /></code>, or <code><references group="..." />
|
|||
Define more in the <nowiki>[[MediaWiki:Cite references link many format backlink labels]]</nowiki> message',
|
||||
'cite_error_references_no_text' => 'Invalid <code><ref></code> tag;
|
||||
no text was provided for refs named <code>$1</code>',
|
||||
'cite_error_included_ref' => 'Closing </ref> missing for <ref> tag',
|
||||
|
||||
/*
|
||||
Output formatting
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue