r46271 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46270‎ | r46271 | r46272 >
Date:18:02, 26 January 2009
Author:mrzman
Status:ok
Tags:
Comment:
(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 (modified) (history)
  • /trunk/extensions/Cite/Cite_body.php (modified) (history)
  • /trunk/extensions/Cite/citeParserTests.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Cite/Cite_body.php
@@ -667,6 +667,25 @@
668668 }
669669
670670 /**
 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+ /**
671690 * Initialize the parser hooks
672691 */
673692 function setHooks() {
@@ -676,6 +695,7 @@
677696 $wgParser->setHook( 'references' , array( &$this, 'references' ) );
678697
679698 $wgHooks['ParserClearState'][] = array( &$this, 'clearState' );
 699+ $wgHooks['ParserBeforeTidy'][] = array( &$this, 'checkRefsNoReferences' );
680700 }
681701
682702 /**
Index: trunk/extensions/Cite/Cite.i18n.php
@@ -44,6 +44,8 @@
4545 'cite_error_references_no_text' => 'Invalid <code>&lt;ref&gt;</code> tag;
4646 no text was provided for refs named <code>$1</code>',
4747 'cite_error_included_ref' => 'Closing &lt;/ref&gt; missing for &lt;ref&gt; tag',
 48+ 'cite_error_refs_without_references' => '<code>&lt;ref&gt;</code> tags exist, but no <code>&lt;references/&gt;</code> tag was found',
 49+ 'cite_error_group_refs_without_references' => '<code>&lt;ref&gt;</code> tags exist for a group named "$1", but no corresponding <code>&lt;references group="$1"/&gt;</code> tag was found',
4850
4951 /*
5052 Output formatting
Index: trunk/extensions/Cite/citeParserTests.txt
@@ -11,6 +11,7 @@
1212 !! result
1313 <p>Wikipedia rocks!<sup id="cite_ref-0" class="reference"><a href="#cite_note-0" title="">[1]</a></sup>
1414 </p>
 15+<br /><strong class="error">Cite error: <code>&lt;ref&gt;</code> tags exist, but no <code>&lt;references/&gt;</code> tag was found</strong>
1516 !! end
1617
1718 !! test
@@ -129,6 +130,7 @@
130131 !! result
131132 <p>1337<sup id="cite_ref-0" class="reference"><a href="#cite_note-0" title="">[1]</a></sup>
132133 </p>
 134+<br /><strong class="error">Cite error: <code>&lt;ref&gt;</code> tags exist, but no <code>&lt;references/&gt;</code> tag was found</strong>
133135 !! end
134136
135137 !! test
@@ -236,8 +238,8 @@
237239 </p><p><strong class="error">Cite error: Invalid <code>&lt;references&gt;</code> tag;
238240 no input is allowed. Use <code>&lt;references /&gt;</code></strong>
239241 </p><p><strong class="error">Cite error: Invalid <code>&lt;references&gt;</code> tag;
240 -no parameters are allowed.
241 -Use <code>&lt;references /&gt;</code></strong>
 242+parameter "group" is allowed only.
 243+Use <code>&lt;references /&gt;</code>, or <code>&lt;references group="..." /&gt;</code></strong>
242244 </p>
243245 <ol class="references"><li id="cite_note-0"><a href="#cite_ref-0" title="">↑</a> Also zero, but differently! (Normal ref)</li>
244246 <li id="cite_note-bar"><a href="#cite_ref-bar_0" title="">↑</a> <strong class="error">Cite error: Invalid <code>&lt;ref&gt;</code> tag;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r45379(bug 16854) Provide explicit error when <references /> is omitted. Patch by B...demon18:59, 3 January 2009
r45499Reverting r45379 as per comment 5 on bug 16854, i.e. it doesn't work with sec...tstarling13:10, 7 January 2009
r46270add mIsPreview and mIsSectionPreview to parserOptions, set in EditPage. patch...mrzman18:02, 26 January 2009

Status & tagging log