r45379 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45378‎ | r45379 | r45380 >
Date:18:59, 3 January 2009
Author:demon
Status:reverted (Comments)
Tags:
Comment:
(bug 16854) Provide explicit error when <references /> is omitted. 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
@@ -426,7 +426,7 @@
427427 // Named references with >1 occurrences
428428 else {
429429 $links = array();
430 -//for group handling, we have an extra key here.
 430+ //for group handling, we have an extra key here.
431431 for ( $i = 0; $i <= $val['count']; ++$i ) {
432432 $links[] = wfMsgForContentNoTrans(
433433 'cite_references_link_many_format',
@@ -665,6 +665,23 @@
666666
667667 return true;
668668 }
 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+ }
669686
670687 /**
671688 * Initialize the parser hooks
@@ -676,6 +693,7 @@
677694 $wgParser->setHook( 'references' , array( &$this, 'references' ) );
678695
679696 $wgHooks['ParserClearState'][] = array( &$this, 'clearState' );
 697+ $wgHooks['ParserBeforeTidy'][] = array( &$this, 'checkRefsNoReferences' );
680698 }
681699
682700 /**
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;

Follow-up revisions

RevisionCommit summaryAuthorDate
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
r46271(bug 16854) Show an error message when a page has <ref> tags and no <referenc...mrzman18:02, 26 January 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   02:23, 7 January 2009

So far so good :D

#Comment by Tim Starling (talk | contribs)   13:39, 7 January 2009

Reverted as per comment 5 on bug 16854, i.e. it doesn't work with section editing.

Status & tagging log