Index: citeParserTests.txt
===================================================================
--- citeParserTests.txt (revision 24156)
+++ citeParserTests.txt (working copy)
@@ -22,7 +22,7 @@
!! result
Wikipedia rocks![1]
-- ↑ Proceeds of Rockology, vol. XXI
+- ↑ Proceeds of Rockology, vol. XXI
!! end
@@ -43,7 +43,7 @@
!! result
Templating[1]
-- ↑ A simple template.
+- ↑ A simple template.
!! end
@@ -56,7 +56,7 @@
!! result
Templating[1]
-- ↑ {{simple template}}
+- ↑ {{simple template}}
!! end
@@ -94,7 +94,7 @@
!! result
Templating[1]
-- ↑ Text
+- ↑ Text
!! end
@@ -118,7 +118,7 @@
-- ↑ one
+- ↑ one
!! end
@@ -152,7 +152,7 @@
[1]
[1]
-- ↑ 1.0 1.1 content
+- ↑ 1.0 1.1 content
!! end
@@ -168,7 +168,7 @@
[1]
[1]
-- ↑ 1.0 1.1 0
+- ↑ 1.0 1.1 0
!! end
@@ -184,6 +184,6 @@
[1]
[1]
-- ↑ 1.0 1.1 1
+- ↑ 1.0 1.1 1
!! end
Index: Cite.php
===================================================================
--- Cite.php (revision 24156)
+++ Cite.php (working copy)
@@ -341,29 +341,67 @@
* Make output to be returned from the references() function
*
* @return string XHTML ready for output
+ *
+ * This function builds the list of references
+ * and if also feeds the references back to the title-objects of the inline marks.
+ * That has to be done here, because:
+ * 1) It is possible to fill the references not at the first call (a may appear before
+ * the defining [ref about something]. Resulting in the first ref having no text.
+ * 2) The [ marks generate html from wikitext, and hence, the title object is not easily accessible
+ * 3) Future compatibility with other means of filling references (bibliographies)
*/
function referencesFormat() {
if ( count( $this->mRefs ) == 0 )
return '';
$ent = array();
- foreach ( $this->mRefs as $k => $v )
+
+ $varlist = "";
+ foreach ( $this->mRefs as $k => $v ) {
$ent[] = $this->referencesFormatEntry( $k, $v );
+ $varlist .= $this->referencesTagName($k, $v);
+ }
$prefix = wfMsgForContentNoTrans( 'cite_references_prefix' );
$suffix = wfMsgForContentNoTrans( 'cite_references_suffix' );
$content = implode( "\n", $ent );
// Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar
- return rtrim( $this->parse( $prefix . $content . $suffix ), "\n" );
+ return rtrim( $this->parse( $prefix . $content . $suffix ), "\n" ) .
+ '';
}
/**
+ * Create a scriptline for the tooltip of the reference
+ *
+ * @param string $key The key of the reference
+ * @param mixed $val The value of the reference, string for anonymous
+ * references, array for user-supplied
+ * @return string javascript
+ */
+ function referencesTagName($key, $val) {
+ // Anonymous reference
+ if ( ! is_array( $val ) )
+ return 'var ref=document.getElementById("' . $this->refKey($key) . '");ref.title="' . Xml::escapeJsString( $this->parse($val)) . '";';
+ // Named references with only 1 occurence
+ else if ( $val['count'] === 0 ) {
+ return 'var ref=document.getElementById("' . $this->refKey($key,0) . '");ref.title="' . Xml::escapeJsString( $this->parse($val['text'])) . '";';
+ // Named references with >1 occurrences
+ } else {
+ $links = "";
+ for ( $i = 0; $i <= $val['count']; ++$i ) {
+ $links .= 'var ref=document.getElementById("' . $this->refKey($key,$i) . '");ref.title="' . Xml::escapeJsString( $this->parse($val['text'])) . '";';
+ }
+ return $links;
+ }
+ }
+
+ /**
* Format a single entry for the referencesFormat() function
*
* @param string $key The key of the reference
* @param mixed $val The value of the reference, string for anonymous
- * references, array for user-suppplied
+ * references, array for user-supplied
* @return string Wikitext
*/
function referencesFormatEntry( $key, $val ) {
]