r40998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40997‎ | r40998 | r40999 >
Date:17:16, 18 September 2008
Author:simetrical
Status:old
Tags:
Comment:
(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>.
Modified paths:
  • /trunk/extensions/Cite/Cite.i18n.php (modified) (history)
  • /trunk/extensions/Cite/Cite_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Cite/Cite_body.php
@@ -155,6 +155,23 @@
156156 return $this->error( 'cite_error_ref_numeric_key' );
157157 }
158158
 159+ if( strpos(
 160+ preg_replace( '#<([^ ]+?).*?>.*?</\\1 *>|<!--.*?-->#', '', $str ),
 161+ '<ref>'
 162+ ) !== false ) {
 163+ # (bug 6199) This most likely implies that someone left off the
 164+ # closing </ref> tag, which will cause the entire article to be
 165+ # eaten up until the next <ref>. So we bail out early instead.
 166+ # The fancy regex above first tries chopping out anything that
 167+ # looks like a comment or SGML tag, which is a crude way to avoid
 168+ # false alarms for <nowiki>, <pre>, etc.
 169+ #
 170+ # Possible improvement: print the warning, followed by the contents
 171+ # of the <ref> tag. This way no part of the article will be eaten
 172+ # even temporarily.
 173+ return $this->error( 'cite_error_included_ref' );
 174+ }
 175+
159176 # Split these into groups.
160177 if( $group === null ) {
161178 $group = $default_group;
Index: trunk/extensions/Cite/Cite.i18n.php
@@ -43,6 +43,7 @@
4444 Define more in the <nowiki>[[MediaWiki:Cite references link many format backlink labels]]</nowiki> message',
4545 'cite_error_references_no_text' => 'Invalid <code>&lt;ref&gt;</code> tag;
4646 no text was provided for refs named <code>$1</code>',
 47+ 'cite_error_included_ref' => 'Closing &lt;/ref&gt; missing for &lt;ref&gt; tag',
4748
4849 /*
4950 Output formatting