From a03e2a48d50ad2b4b975e28a5ee5451ae72bb04c Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 4 Jan 2008 13:58:40 +0000 Subject: [PATCH] Improve clarity of error message when no text is given for a reference. --- Cite.i18n.php | 2 +- Cite.php | 16 ++++++++++------ citeParserTests.txt | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cite.i18n.php b/Cite.i18n.php index a5bcba83b..d19d19af4 100644 --- a/Cite.i18n.php +++ b/Cite.i18n.php @@ -27,7 +27,7 @@ $messages['en'] = array( <references />', 'cite_error_references_invalid_parameters' => 'Invalid <references> tag; no parameters are allowed, use <references />', 'cite_error_references_no_backlink_label' => "Ran out of custom backlink labels, define more in the \"''cite_references_link_many_format_backlink_labels''\" message", - 'cite_error_references_no_text' => 'No text given.', + 'cite_error_references_no_text' => 'Invalid <ref> tag; no text was provided for refs named $1', /* Output formatting diff --git a/Cite.php b/Cite.php index 636a797c7..0f48b1f20 100644 --- a/Cite.php +++ b/Cite.php @@ -353,7 +353,7 @@ function wfCite() { 'cite_references_link_one', $this->referencesKey( $key ), $this->refKey( $key, $val['count'] ), - $this->error( 'cite_error_references_no_text' ) + $this->error( 'cite_error_references_no_text', $key ) ); // Standalone named reference, I want to format this like an // anonymous reference because displaying "1. 1.1 Ref text" is @@ -365,7 +365,7 @@ function wfCite() { 'cite_references_link_one', $this->referencesKey( $key ), $this->refKey( $key, $val['count'] ), - ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text' ) ) + ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) ) ); // Named references with >1 occurrences else { @@ -386,7 +386,7 @@ function wfCite() { wfMsgForContentNoTrans( 'cite_references_link_many', $this->referencesKey( $key ), $list, - ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text' ) ) + ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) ) ); } } @@ -619,14 +619,18 @@ function wfCite() { /** * Return an error message based on an error ID * - * @param string $key Message name for the error + * @param string $key Message name for the error + * @param string $param Parameter to pass to the message * @return string XHTML ready for output */ - function error( $key ) { + function error( $key, $param=null ) { + # We rely on the fact that PHP is okay with passing unused argu- + # ments to functions. If $1 is not used in the message, wfMsg will + # just ignore the extra parameter. return $this->parse( '' . - wfMsg( 'cite_error', wfMsg( $key ) ) . + wfMsg( 'cite_error', wfMsg( $key, $param ) ) . '' ); } diff --git a/citeParserTests.txt b/citeParserTests.txt index 1177a510f..8b6f72a2c 100644 --- a/citeParserTests.txt +++ b/citeParserTests.txt @@ -236,8 +236,8 @@ Erroneous refs

Cite error: Invalid <references> tag; no parameters are allowed, use <references />

  1. Also zero, but differently! (Normal ref)
  2. -
  3. Cite error: No text given.
  4. -
  5. Cite error: No text given.
+
  • Cite error: Invalid <ref> tag; no text was provided for refs named bar
  • +
  • Cite error: Invalid <ref> tag; no text was provided for refs named blankwithnoreference
  • !! end