Index: trunk/extensions/Cite/Cite_body.php |
— | — | @@ -426,7 +426,7 @@ |
427 | 427 | // Named references with >1 occurrences |
428 | 428 | else { |
429 | 429 | $links = array(); |
430 | | -//for group handling, we have an extra key here. |
| 430 | + //for group handling, we have an extra key here. |
431 | 431 | for ( $i = 0; $i <= $val['count']; ++$i ) { |
432 | 432 | $links[] = wfMsgForContentNoTrans( |
433 | 433 | 'cite_references_link_many_format', |
— | — | @@ -665,6 +665,23 @@ |
666 | 666 | |
667 | 667 | return true; |
668 | 668 | } |
| 669 | + |
| 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 | + foreach ( $this->mRefs as $group => $refs ) { |
| 676 | + if ( count( $refs ) == 0 ) continue; |
| 677 | + $text .= "\n<br />"; |
| 678 | + if ( $group == CITE_DEFAULT_GROUP ) { |
| 679 | + $text .= $this->error( 'cite_error_refs_without_references' ); |
| 680 | + } else { |
| 681 | + $text .= $this->error( 'cite_error_group_refs_without_references', htmlspecialchars( $group ) ); |
| 682 | + } |
| 683 | + } |
| 684 | + return true; |
| 685 | + } |
669 | 686 | |
670 | 687 | /** |
671 | 688 | * Initialize the parser hooks |
— | — | @@ -676,6 +693,7 @@ |
677 | 694 | $wgParser->setHook( 'references' , array( &$this, 'references' ) ); |
678 | 695 | |
679 | 696 | $wgHooks['ParserClearState'][] = array( &$this, 'clearState' ); |
| 697 | + $wgHooks['ParserBeforeTidy'][] = array( &$this, 'checkRefsNoReferences' ); |
680 | 698 | } |
681 | 699 | |
682 | 700 | /** |
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; |