Revision: 46271
Author: mrzman
Date: 2009-01-26 18:02:28 +0000 (Mon, 26 Jan 2009)
Log Message:
-----------
(bug 16854) Show an error message when a page has <ref> tags and no
<references/>. Patch by Brad Jorsch.
Modified Paths:
--------------
trunk/extensions/Cite/Cite.i18n.php
trunk/extensions/Cite/Cite_body.php
trunk/extensions/Cite/citeParserTests.txt
Modified: trunk/extensions/Cite/Cite.i18n.php
===================================================================
--- trunk/extensions/Cite/Cite.i18n.php 2009-01-26 18:02:13 UTC (rev 46270)
+++ trunk/extensions/Cite/Cite.i18n.php 2009-01-26 18:02:28 UTC (rev 46271)
@@ -44,6 +44,8 @@
'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',
+ 'cite_error_refs_without_references' =>
'<code><ref></code> tags exist, but no <code><references/></code>
tag was found',
+ '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',
/*
Output formatting
Modified: trunk/extensions/Cite/Cite_body.php
===================================================================
--- trunk/extensions/Cite/Cite_body.php 2009-01-26 18:02:13 UTC (rev 46270)
+++ trunk/extensions/Cite/Cite_body.php 2009-01-26 18:02:28 UTC (rev 46271)
@@ -667,6 +667,25 @@
}
/**
+ * 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<br />";
+ 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
*/
function setHooks() {
@@ -676,6 +695,7 @@
$wgParser->setHook( 'references' , array( &$this, 'references'
) );
$wgHooks['ParserClearState'][] = array( &$this, 'clearState' );
+ $wgHooks['ParserBeforeTidy'][] = array( &$this,
'checkRefsNoReferences' );
}
/**
Modified: trunk/extensions/Cite/citeParserTests.txt
===================================================================
--- trunk/extensions/Cite/citeParserTests.txt 2009-01-26 18:02:13 UTC (rev
46270)
+++ trunk/extensions/Cite/citeParserTests.txt 2009-01-26 18:02:28 UTC (rev
46271)
@@ -11,6 +11,7 @@
!! result
<p>Wikipedia rocks!<sup id="cite_ref-0" class="reference"><a
href="#cite_note-0" title="">[1]</a></sup>
</p>
+<br /><strong class="error">Cite error: <code><ref></code> tags exist,
but no <code><references/></code> tag was found</strong>
!! end
!! test
@@ -129,6 +130,7 @@
!! result
<p>1337<sup id="cite_ref-0" class="reference"><a href="#cite_note-0"
title="">[1]</a></sup>
</p>
+<br /><strong class="error">Cite error: <code><ref></code> tags exist,
but no <code><references/></code> tag was found</strong>
!! end
!! test
@@ -236,8 +238,8 @@
</p><p><strong class="error">Cite error: Invalid
<code><references></code> tag;
no input is allowed. Use <code><references /></code></strong>
</p><p><strong class="error">Cite error: Invalid
<code><references></code> tag;
-no parameters are allowed.
-Use <code><references /></code></strong>
+parameter "group" is allowed only.
+Use <code><references /></code>, or <code><references group="..."
/></code></strong>
</p>
<ol class="references"><li id="cite_note-0"><a href="#cite_ref-0"
title="">↑</a> Also zero, but differently! (Normal ref)</li>
<li id="cite_note-bar"><a href="#cite_ref-bar_0" title="">↑</a> <strong
class="error">Cite error: Invalid <code><ref></code> tag;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs