User:Beetstra/Cite.php

From Meta, a Wikimedia project coordination wiki

Copy of Cite.php, changed by User:Beetstra to reflect the additions made to the code by Beetstra, but which are not yet included into cite.php. Please leave comments on en:user talk:beetstra.

A patch enabling the extended features now resides in Bugzilla bug 423 (here).

Other languages:

Imported with full page histories. --Roosa (Talk) 23:21, 27 June 2007 (UTC)

This page gives general documentation valid for all MediaWiki installations which use the cite extension. For use of this feature in the English Wikipedia see w:Wikipedia:Footnotes. That page also includes more examples.

Cite.php is a Cite extension that adds parser hooks to MediaWiki:

  • <ref> and <references>; these operate together to add citations to pages. (see References).
  • <footnote> and <footnotes>; these operate together to add footnotes to sections/pages (see Footnotes).

Additionally:

  • <bibtex>, <biblio>, <bibref>, <biblioitem> for advanced reference control (see BibTeX).

Where to download[edit]

Required by Cite.php or else you'll get a pretty blank page!

To come:

Required by Bibliographyrader.php or else you'll get a pretty blank page!

Requirements[edit]

This version requires at least Mediawiki 1.6x.

How to install[edit]

  1. Copy the Cite.php and Cite.i18n.php file to your extensions folder, and
  2. Add a
    require_once( "$IP/extensions/Cite.php" );
    line to your LocalSettings.php (Directly below require_once( "includes/DefaultSettings.php" ); )
    • If the above does not work, add this line just above ?> at the bottom of LocalSettings.php:
    include( '$IP/extensions/Cite.php' );

References[edit]

How it works[edit]

The basic concept of the <ref> tag is that it inserts the text enclosed by the ref tags as a reference in a designated section, which you indicate with the placeholder tag <references/>. The new format cannot be used interchangeably with the old format - you must pick one or the other.

If you forget to include <references/> at the end of the article, none of the references will appear.

This page itself uses references, such as the one at the end of this sentence.[1] If you view the Wikicode of this page by clicking "Edit this page", you can see a working example of references.

Example[edit]

According to scientists, the Sun is pretty big.<ref>E. Miller, The Sun, (New York: Academic Press, 2005), 23-5.</ref>
The Moon, however, is not so big.<ref>R. Smith, "Size of the Moon", Scientific American, 46 (April 1978): 44-6.</ref>

==Notes==
<references/>

Multiple uses of the same reference[edit]

To give a reference a unique identifier, use <ref name="name">. You can then refer to the same reference again by using a ref tag with the same name. The text inside the second tag doesn't matter, because the text already exists in the first reference. You can either copy the whole reference, or you can use a terminated empty ref tag that looks like this: <ref name="name"/>.

In the following example, the same source is cited three times.

This is an example of multiple references.<ref name="multiple">Remember that when you refer to the same reference multiple times, the text from the first reference is used.</ref>

Such references are particularly useful when citing sources, if different statements come from the same source.<ref name="multiple">This text is superfluous, and won't show up anywhere. We may as well just use an empty tag.</ref>

A concise way to make multiple references is to use empty ref tags, which have a slash at the end. Although this may reduce redundant work, please be aware that if a future editor removes the first reference, this will result in the loss of all references using the empty ref tags.<ref name="multiple" />

==Notes==
<references/>

The text above gives the following result in the article (see also the following section for the result):

This is an example of multiple references.[2]

Such references are particularly useful when citing sources, when different statements come from the same source.[2]

A concise way to make multiple references is to use empty ref tags, which have a slash at the end. Although this may reduce redundant work, please be aware that if a future editor removes the first reference, this will result in the loss of all references using the empty ref tags.[2]

<references/>[edit]

Placing <references/> inserts the full text of all pending inline citations defined by <ref>, anywhere on the page. For example, based on the citations above, the code:

<references/>

will yield:

  1. This reference is used as an example in the "How to use" section.
  2. a b c Remember that when you refer to the same reference multiple times, the text from the first reference is used. Cite error: Invalid <ref> tag; name "multiple" defined multiple times with different content

On Wikipedia, references are sometimes made smaller than normal text, using the code:

<div class="references-small">
<references/>
</div>

Footnotes[edit]

The working of the footnote and footnotes tags is pretty similar to the above ref and references tags. The only difference is, that the footnotes-tag resets the list of footnotes, hence, footnotes can be inserted per section, the next section will start with a fresh set of footnotes. As for the ref-tag, the footnote-tag takes a parameter 'name', which enables you to re-use the contents of the first tag.

<footnote/>[edit]

As for the ref-tags, footnote can either be supplied in full:

<footnote>This has been observed before</footnote>

Supplied with a name

<footnote name=footnote1>This has been observed before</footnote>

Or you can then refer to the same footnote again by using a footnote tag with the same name. The text inside the second tag doesn't matter, because the text already exists in the first footnote. You can either copy the whole footntoe, or you can use a terminated empty footntoe tag that looks like this:

<footnote name="footnote1"/>.

In the following example, the same source is cited three times.

This is an example of multiple footnotes.<footnote name="multiple">Remember that when you refer to the same footnote multiple times, the text from the first footnote is used.</footnote>

Such footnotes are particularly useful when citing sources, if different statements come from the same source.<footnote name="multiple">This text is superfluous, and won't show up anywhere. We may as well just use an empty tag.</footnote>

A concise way to make multiple footnotes is to use empty footnote tags, which have a slash at the end. Although this may reduce redundant work, please be aware that if a future editor removes the first footnote, this will result in the loss of all footnotes using the empty ref tags.<footnote name="multiple" />

==Notes==
<footnotes/>

The text above gives the following result in the article (see the following section for the result):

This is an example of multiple footnotes.<footnote name=multiple>Remember that when you refer to the same footnote multiple times, the text from the first footnote is used.</footnote>

Such footnotes are particularly useful when citing sources, when different statements come from the same source.<footnote name=multiple>This text is superfluous, and won't show up anywhere. We may as well just use an empty tag.</footnote>

A concise way to make multiple footnotes is to use empty footnote tags, which have a slash at the end. Although this may reduce redundant work, please be aware that if a future editor removes the first footnote, this will result in the loss of all footnotes using the empty ref tags.<footnote name=multiple />

<footnotes/>[edit]

Placing <footnotes/> inserts the full text of all pending inline citations defined by <footnote>, between the beginning of the document and the tag (or between the last footnotes-tag and the current footnotes-tag. For example, based on the footnotes above, the code:

<footnotes/>

will yield:

<footnotes/>

Multiple calls to <footnotes/>[edit]

The folling example shows the effect of multiple calls to the footnotes-tag:

Section 1[edit]

Reference Section 1<ref>This is a reference from the multiple example, section 1</ref>

Footnote 1<footnote>First footnote in section 1</footnote>.

Footnote 2<footnote>Second footnote in section 1</footnote>.

Footnotes[edit]

<footnotes />

Section 2[edit]

Reference Section 2<ref>This is a reference from the multiple example, section 2</ref>

Footnote 1<footnote>First footnote in section 2</footnote>.

Footnote 2<footnote>Second footnote in section 2</footnote>.

Footnotes[edit]

<footnotes />

References[edit]

<references />

Results in

Section 1[edit]

Reference Section 1[1]

Footnote 1<footnote>First footnote in section 1</footnote>.

Footnote 2<footnote>Second footnote in section 1</footnote>.

Footnotes[edit]

<footnotes />

Section 2[edit]

Reference Section 2[2]

Footnote 1<footnote>First footnote in section 2</footnote>.

Footnote 2<footnote>Second footnote in section 2</footnote>.

Footnotes[edit]

<footnotes />

References[edit]

  1. This is a reference from the multiple example, section 1
  2. This is a reference from the multiple example, section 2

Note, that the references section also contains the references from earlier in this document, while the footnotes sections only have footnotes generated since the last <footnotes/> tag.

BibTeX[edit]

The following tagsets require a bit more knowledge of citation systems and references than normal.

These tags provide extra options to fill the datasets for the <ref>-tags. This also results in the posibility to use the the Harvard Referencing method for the references.

There are two ways of filling the bibliography, using <bibtex>-tags (see bibtex) and <biblioitem>-tags (see biblioitem).

For the biblioitem-tags there is a formatting tagset "<biblio>", which enables you to view the list of references (see biblio.

The data can be retrieved from the loaded bibliographies (from the bibtex and or biblioitem lists) using the abovementioned <ref name="name"/> (see here) method, or with a <bibref name="name" field="field"/> tag (see bibref and ref.

General about biblioitem, and biblio and bibtex[edit]

The push stucture of these tags enables to prefill the list of references, and using them throughout the document using <ref> and <bibref> tags. This simplifies the documents structure, one can first make a list of references and use the references througout. The use of <bibtex> and <biblio> also enables to make the lists on another page, which further simplifies document structure (although an unexperienced editor will then not see where the references come from).

The tags biblio and bibtex have to appear before the functions that recall the information from the database, that is it has to appear before:

  • <references /> (but may appear after the <ref> tags)
  • <bibref> tags.

The database can be filled with many references, only the ones that are called with a <ref name="name"> will appear in the <references />-section. The others are ignored.

biblioitem and biblio[edit]

The tagset <biblioitem name="name">text</biblioitem> is used to store references.

<biblioitem name=bibitem1>This is biblioitem 1</biblioitem>

Results in:

<biblioitem name=bibitem1>This is biblioitem 1</biblioitem>

This tag has no further function in output, it is mere a holder for one record. The list of biblioitems has to be encapsulated in biblio-tags. This loads the records into the database, and hides the tags:

<biblio> <biblioitem name=bibitem1>This is biblioitem 1</biblioitem> <biblioitem name=bibitem2>This is biblioitem 2</biblioitem> <biblioitem name=bibitem3>This is biblioitem 3</biblioitem> </biblio>

Results in:

<biblio> <biblioitem name=bibitem1>This is biblioitem 1</biblioitem>

<biblioitem name=bibitem2>This is biblioitem 2</biblioitem>

<biblioitem name=bibitem3>This is biblioitem 3</biblioitem>

</biblio>

(nothing visible, normal use)


Adding a parameter "show" to the biblio-tags

<biblio show> <biblioitem name=bibitem1>This is biblioitem 1</biblioitem> <biblioitem name=bibitem2>This is biblioitem 2</biblioitem> <biblioitem name=bibitem3>This is biblioitem 3</biblioitem> </biblio>


results in:

<biblio show> <biblioitem name=bibitem1>This is biblioitem 1</biblioitem>

<biblioitem name=bibitem2>This is biblioitem 2</biblioitem>

<biblioitem name=bibitem3>This is biblioitem 3</biblioitem>

</biblio>

bibtex[edit]

Bibtex is a standard format for lists of references. For a more complete description of bibtex see en:Bibtex

A BibTeX field looks like this:

@article{Gettys90,
   author = {Jim Gettys and Phil Karlton and Scott McGregor},
   title = {The {X} Window System, Version 11},
   journal = {Software Practice and Experience},
   volume = {20},
   number = {S2},
   year = {1990},
   abstract = {A technical overview of the X11 functionality.  This is an update of the X10 TOG paper by Scheifler \& Gettys.}
}

The @article tells the bibtex-engine that we are referring to an article. The first parameter within the curly brackets ("Gettys90") gives the name of the record, which we later use to retrieve this record with a <ref name=Gettys90/> or a <bibref name=Gettys90> (see bibref and ref). The other fields define the different fields within the record. These can also be pulled (for custom output) from the field using a <bibref name=Gettys90 field=journal> (see bibref and ref).

To load them into the database, these fields (one or more) are directly encapsulated by a bibtex-tag:

<bibtex> @article{Gettys90, author = {Jim Gettys and Phil Karlton and Scott McGregor}, title = {The {X} Window System, Version 11}, journal = {Software Practice and Experience}, volume = {20}, number = {S2}, year = {1990}, abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler \& Gettys.} } <bibtex>

Which results in:

<bibtex> @article{Gettys90, author = {Jim Gettys and Phil Karlton and Scott McGregor}, title = {The {X} Window System, Version 11}, journal = {Software Practice and Experience}, volume = {20}, number = {S2}, year = {1990}, abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler \& Gettys.} } </bibtex>

(again, one sees nothing).

For maintenance one can add a parameter "show" to the bibtex field, to show it's contents:

<bibtex show> @article{Gettys90, author = {Jim Gettys and Phil Karlton and Scott McGregor}, title = {The {X} Window System, Version 11}, journal = {Software Practice and Experience}, volume = {20}, number = {S2}, year = {1990}, abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler \& Gettys.} } </bibtex>

This shows the contents of the bibtex field, and shows how the formatted reference (appearing in a <references/> section, when it has been called with a <ref name=Gettys90/>, looks like:

A reference to Gettys90 (see also the following references section).[1]

parameters[edit]

The parameter "show" has been described above (it shows the contents of the bibtex fields)

Another parameter is the parameter "page":

<bibtex page="pagename" />

In this case, the bibtex fields (residing in <bibtex>records</bibtex>-tags) on the page residing under "pagename" are read into the database for this page.


bibref and ref[edit]

Calling <ref name="name"> activates the database with the name "name", if the reference is filled from biblio/biblioitem, the text is as it appears in the biblioitem tags. When it is filled from a bibtex-record, formatting is according system settings, depending on record-type and data. So the ref:

<ref name=Gettys90/>

results in:

[1]

The bibref-tag retrieves data in Oxford Referencing style, a tag:

<bibref name=Gettys90/>

results in:

<bibref name=Gettys90/>

The bibref-tag can also retrieve other data by adding the appropriate fieldname to the parameter "field". In this way more complex constructions are possible:

The authors <bibref name=Gettys90 field=author /> wrote in their article "<bibref name=Gettys90 field=title>" about the X-windows system.<ref name=Gettys90/>

results in:

The authors <bibref name=Gettys90 field=author /> wrote in their article "<bibref name=Gettys90 field=title/>" about the X-windows system.[1]

references[edit]

  1. a b c Cite error: Invalid <ref> tag; no text was provided for refs named Gettys90

Customization[edit]

To meet Wikimedia's quality standards and make it more accessible, this article or section needs a better explanation of technical details or more context regarding applications or importance to make it more accessible to a general audience, or at least to technical readers outside this specialty. Please help expand it without removing the technical details. Additional rationale may be on this talk page.


The format of the output of <ref> and <references> is almost completely customizable through MediaWiki messages, that can be modified, for example, through the MediaWiki namespace depending on the configuration of the wiki.

For a list of messages that control the output of <ref> and <references> and the values, if any, that are passed to them ($1, $2, $3 ...), see the code in CVS for an up-to-date listing of their default contents.

  • cite_reference_link_key_with_num
    1. key
    2. num
  • cite_reference_link_prefix
  • cite_reference_link_suffix
  • cite_references_link_prefix
  • cite_references_link_suffix
  • cite_reference_link
    1. ref ID
    2. backlink ID
    3. count to display
  • cite_references_link_one
    • Used to format the source list that <references /> outputs, it configures 3 things: the backlink ID, the ref ID, and text of note.
    1. backlink ID - used for creating the number order of the source list.
    2. ref ID - used to link back to the actual reference in the text, this is where you can configure the <bold>^</bold> symbol
    3. text of note - text used above describing the source info
  • cite_references_link_many
    1. backlink ID
    2. list of links
    3. text of note
  • cite_references_link_many_format
    1. ref ID
    2. numeric value to use as a backlink
    3. custom value (as defined in cite_references_link_many_format_backlink_labels to use as a backlink)
  • cite_references_link_many_format_backlink_labels
  • cite_references_link_many_sep
  • cite_references_link_many_and
  • cite_references_prefix
  • cite_references_suffix

Set references to use ^ and letters like Wikipedia[edit]

In file Cite.i18n.php starting at about line 47,

'cite_references_link_one' => '<li id="$1">[[#$2|^]] $3</li>', 
'cite_references_link_many' => '<li id="$1">^ $2 $3</li>', 
'cite_references_link_many_format' => '[[#$1|<sup>$3</sup>]]',


The ^ replaces the up arrows and putting $3 in the last line between the sup /sup tags fixes the links w/ a b c... vice 2.1, 2.2, 2.3, etc...

Issues[edit]

Current issues[edit]

It doesn't work with version 1.6.8! I eventually got cite.php working with "13660" but not "13826" versions. My error messages appeared at the top of the page
Warning: Cannot modify header information - headers already sent by (output started at /****/wiki/extensions/Cite.i18n.php:399) in /****/OutputPage.php on line 575
Warning: Cannot modify header information - headers already sent by (output started at /****/wiki/extensions/Cite.i18n.php:399) in /****/wiki/includes/OutputPage.php on line 576


??? appears in rendered pages instead of ↑
Using <ref> in templates breaks numbering
Issue with MediaWiki regarding in what order things are parsed
Using <ref> within a template will create correctly numbered reference mark but it will be missing from the output of a <reference /> on the calling page. (example)
It's impossible to pass template arguments to <ref>, e.g. <ref name={{{1}}}>
Issue with MediaWiki, see bug 4529
The citation links generated by <ref> and the backlinks generated by <references> have an empty title attribute (<a href="..." title="">...)
Issue with MediaWiki, not this extension. MediaWiki will generate output like <a href="#foo" title="">bar</a> when given input like [[#foo|bar]]
Missing name= anchors for backwards compatibility (5567)
The generated <a href="#_note-n"> links should have a name="_ref-n".
The generated <a href="#_ref-n"> links should have a name="_note-n".
This currently seems to be working. —72.255.34.142 17:02, 22 July 2006 (UTC)
Commenting out <ref> with HTML comments <--…--> hides the citation but the reference still appears on the list
This would appear to be a parser error…
Template substitution misrenders inside <ref> tag.
Contents of non-first named <ref> are not rendered, even if all prior tags with same name are empty.

Criticisms[edit]

The major criticism regarding Cite.php is that it renders the editing of references much more tedious. Moreover, because many casual Wikipedia users are not familar with the cryptic Wikitext tags that they find with the use of Cite.php, it is likely that the net effect of Cite.php is often to deter new users from making edits to reference sections. Although Wikipedia supposedly got its name from the Hawaiian word "wiki-wiki", meaning "quick-quick", Cite.php is arguably neither quick nor easy for the average Wikipedia user.

A possible solution would be to have the actual reference section contain all of the references with given names, then throughout the article, simply reference by name, instead of the full citation. This would also reduce confusion concerning multiple uses of a reference having different text, but only showing the first instance (causing confusion with sections are shifted around, the displayed reference might change, while the text hasn't). I.e.:
Some text that needs a ref.{{ref|foo}} Another sentence that uses a ref,{{ref|bar}} followed by another usage of the first ref.{{ref|foo}}

===References===
{{refs
  {{ref|foo|Text of reference}}
  {{ref|bar|A difference reference}} }}
Although, this would require two passes by the parser, it would greatly simplify the process of sourcing. I.e. if I am adding something to an article and want to use a source that I know is already cited, I have to dig through the text of the article to find where it is used, (which can be a major pain in large articles, esp. ones which have a lot of references) instead of just glancing at the code for the references section and finding the name.

Another criticism is that, unlike Footnotes3, it is currently impossible to separate bibliographic information from article copy.

However, at least one editor, Ta bu shi da yu, has found it incredibly useful in splitting articles and shifting text with footnotes around the article. Before, a paragraph with a footnote needed to be moved, and multiple footnotes in the Notes section shifted. This was very difficult to do. With Cite.php, reorganising text and splitting articles is considerably easier.

Past issues[edit]

The extension didn't generate id attributes that could be uniformly styled with CSS2 attribute selectors
Issue in Cite.php, see bug 4579
Using multibyte characters, colons, spaces and other values that need to be encoded according to the HTML spec breaks internal links
Issue with MediaWiki, not this extension, see bug 4461.
Using <ref> in image captions breaks the XHTML output
Issue with MediaWiki, not this extension, see bug 1887.

Comparing ref/note style and Cite.php style[edit]

They are actually very similar.

  • To make a single use footnote:
    • Ref/note
      1. {{ref|foo}} at the in-text place.
      2. # {{note|foo}} text of note at the proper place in the Notes list.
    • Cite.php
      1. <ref>text of note</ref> at the in-text place.
      2. (Only needed once per article)<references/> under the Notes heading.
  • To make a multiple use footnote:
    • Ref/note
      • With strict ref/note style this was impossible, but a number of alternative forms had been created, for the details of which, see the appropriate pages.
    • Cite.php
      1. <ref name=foo>text of note</ref> at each in-text place.
        1. Alternatively <ref name=foo /> A self-closing tag on every use after name=foo has been defined.
      2. (Only needed once per article)<references/> under the Notes heading; exactly the same as to make a single-use note.