Index: trunk/extensions/Cite/Cite_body.php |
— | — | @@ -667,6 +667,25 @@ |
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
| 671 | + * Called at the end of page processing to append an error if refs were |
| 672 | + * used without a references tag. |
| 673 | + */ |
| 674 | + function checkRefsNoReferences(&$parser, &$text){ |
| 675 | + if ( $parser->getOptions()->getIsSectionPreview() ) return true; |
| 676 | + |
| 677 | + foreach ( $this->mRefs as $group => $refs ) { |
| 678 | + if ( count( $refs ) == 0 ) continue; |
| 679 | + $text .= "\n<br />"; |
| 680 | + if ( $group == CITE_DEFAULT_GROUP ) { |
| 681 | + $text .= $this->error( 'cite_error_refs_without_references' ); |
| 682 | + } else { |
| 683 | + $text .= $this->error( 'cite_error_group_refs_without_references', htmlspecialchars( $group ) ); |
| 684 | + } |
| 685 | + } |
| 686 | + return true; |
| 687 | + } |
| 688 | + |
| 689 | + /** |
671 | 690 | * Initialize the parser hooks |
672 | 691 | */ |
673 | 692 | function setHooks() { |
— | — | @@ -676,6 +695,7 @@ |
677 | 696 | $wgParser->setHook( 'references' , array( &$this, 'references' ) ); |
678 | 697 | |
679 | 698 | $wgHooks['ParserClearState'][] = array( &$this, 'clearState' ); |
| 699 | + $wgHooks['ParserBeforeTidy'][] = array( &$this, 'checkRefsNoReferences' ); |
680 | 700 | } |
681 | 701 | |
682 | 702 | /** |
Index: trunk/extensions/Cite/Cite.i18n.php |
— | — | @@ -44,6 +44,8 @@ |
45 | 45 | 'cite_error_references_no_text' => 'Invalid <code><ref></code> tag; |
46 | 46 | no text was provided for refs named <code>$1</code>', |
47 | 47 | 'cite_error_included_ref' => 'Closing </ref> missing for <ref> tag', |
| 48 | + 'cite_error_refs_without_references' => '<code><ref></code> tags exist, but no <code><references/></code> tag was found', |
| 49 | + 'cite_error_group_refs_without_references' => '<code><ref></code> tags exist for a group named "$1", but no corresponding <code><references group="$1"/></code> tag was found', |
48 | 50 | |
49 | 51 | /* |
50 | 52 | Output formatting |
Index: trunk/extensions/Cite/citeParserTests.txt |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | !! result |
13 | 13 | <p>Wikipedia rocks!<sup id="cite_ref-0" class="reference"><a href="#cite_note-0" title="">[1]</a></sup> |
14 | 14 | </p> |
| 15 | +<br /><strong class="error">Cite error: <code><ref></code> tags exist, but no <code><references/></code> tag was found</strong> |
15 | 16 | !! end |
16 | 17 | |
17 | 18 | !! test |
— | — | @@ -129,6 +130,7 @@ |
130 | 131 | !! result |
131 | 132 | <p>1337<sup id="cite_ref-0" class="reference"><a href="#cite_note-0" title="">[1]</a></sup> |
132 | 133 | </p> |
| 134 | +<br /><strong class="error">Cite error: <code><ref></code> tags exist, but no <code><references/></code> tag was found</strong> |
133 | 135 | !! end |
134 | 136 | |
135 | 137 | !! test |
— | — | @@ -236,8 +238,8 @@ |
237 | 239 | </p><p><strong class="error">Cite error: Invalid <code><references></code> tag; |
238 | 240 | no input is allowed. Use <code><references /></code></strong> |
239 | 241 | </p><p><strong class="error">Cite error: Invalid <code><references></code> tag; |
240 | | -no parameters are allowed. |
241 | | -Use <code><references /></code></strong> |
| 242 | +parameter "group" is allowed only. |
| 243 | +Use <code><references /></code>, or <code><references group="..." /></code></strong> |
242 | 244 | </p> |
243 | 245 | <ol class="references"><li id="cite_note-0"><a href="#cite_ref-0" title="">↑</a> Also zero, but differently! (Normal ref)</li> |
244 | 246 | <li id="cite_note-bar"><a href="#cite_ref-bar_0" title="">↑</a> <strong class="error">Cite error: Invalid <code><ref></code> tag; |