diff --git a/Cite.i18n.php b/Cite.i18n.php index 11a2381e..40f18ca9 100644 --- a/Cite.i18n.php +++ b/Cite.i18n.php @@ -44,6 +44,8 @@ Define more in the [[MediaWiki:Cite references link many format backlink 'cite_error_references_no_text' => 'Invalid <ref> tag; no text was provided for refs named $1', 'cite_error_included_ref' => 'Closing </ref> missing for <ref> tag', + 'cite_error_refs_without_references' => '<ref> tags exist, but no <references/> tag was found', + 'cite_error_group_refs_without_references' => '<ref> tags exist for a group named "$1", but no corresponding <references group="$1"/> tag was found', /* Output formatting diff --git a/Cite_body.php b/Cite_body.php index f2fa9460..1c9104db 100644 --- a/Cite_body.php +++ b/Cite_body.php @@ -666,6 +666,25 @@ class Cite { return true; } + /** + * Called at the end of page processing to append an error if refs were + * used without a references tag. + */ + function checkRefsNoReferences(&$parser, &$text){ + if ( $parser->getOptions()->getIsSectionPreview() ) return true; + + foreach ( $this->mRefs as $group => $refs ) { + if ( count( $refs ) == 0 ) continue; + $text .= "\n
"; + if ( $group == CITE_DEFAULT_GROUP ) { + $text .= $this->error( 'cite_error_refs_without_references' ); + } else { + $text .= $this->error( 'cite_error_group_refs_without_references', htmlspecialchars( $group ) ); + } + } + return true; + } + /** * Initialize the parser hooks */ @@ -676,6 +695,7 @@ class Cite { $wgParser->setHook( 'references' , array( &$this, 'references' ) ); $wgHooks['ParserClearState'][] = array( &$this, 'clearState' ); + $wgHooks['ParserBeforeTidy'][] = array( &$this, 'checkRefsNoReferences' ); } /** diff --git a/citeParserTests.txt b/citeParserTests.txt index 322672b3..d7543f21 100644 --- a/citeParserTests.txt +++ b/citeParserTests.txt @@ -11,6 +11,7 @@ Wikipedia rocks!Proceeds of Rockology, vol. XXI !! result

Wikipedia rocks![1]

+
Cite error: <ref> tags exist, but no <references/> tag was found !! end !! test @@ -129,6 +130,7 @@ TemplatingText !! result

1337[1]

+
Cite error: <ref> tags exist, but no <references/> tag was found !! end !! test @@ -236,8 +238,8 @@ refs with no content must have a name

Cite error: Invalid <references> tag; no input is allowed. Use <references />

Cite error: Invalid <references> tag; -no parameters are allowed. -Use <references /> +parameter "group" is allowed only. +Use <references />, or <references group="..." />

  1. Also zero, but differently! (Normal ref)
  2. Cite error: Invalid <ref> tag;