Topic on Extension talk:Cite

Zackmann08 (talkcontribs)

Is there a way to get the number of references on a page? I am trying to get the ref-list to automatically appear on pages but I don't want it to appear if there are no references being used.

קיפודנחש (talkcontribs)

This should be relatively easy (and chpeap) to do through javascript (granted, readers with JS disabled will miss this feature).

i do not know a way to get this data displayed on the page directly (i.e., becoming part of the page directly, through wiki-code). it may be possible via scribunto (aka lua), but this will requires you to write some code also, so the advantage over JS is not clear (except for readers with JS disabled). and i'm not even sure if it's possible (and of course, if possible, it requires installing the scribunto extension).

here is a snippet that, if added to mediawiki:common.js will display the number of references under the page title (100% untested - this is meant mainly to illustrate):

if ( ! mw.config.get( 'wgNamespaceNumber' ) ) // only in namespace 0
$(function() {
    var num = $('ol.references  li[id|="cite_note"]').length
    if (num)
        $('#siteSub').append(' | ' + num + ' Cite notes');
});

peace.

קיפודנחש (talkcontribs)

reading the original request more carefully, my reply was not very useful.

you can still use JS to *hide* the "references" section in case it's empty, but it may not be very pretty - the section will momentarily appear, and only after the page finishes rendering it will disappear (somewhat like "collapsible" elements). it will also not solve the case where there *are* references but no <references /> section.

again, you can use a pre-save JS hook that will at least warn the user when they are going to save a page with <ref> tags but no <references/> tag. you want to be careful, and not trigger the warning when editing a section.

peace.

Cavila (talkcontribs)

Actually, I have the <references /> tag on almost any page, embedded as it is in a template so that I don't have to remind myself of adding it manually. When no references are used on the page, the list simply does not appear. The only nuisance is that I can't make the subheading (e.g. "References" or "Endnotes") conditional on the presence of <ref>...</ref> tags. The subheading appears regardless.

קיפודנחש (talkcontribs)

the little snippet above can do it, if you replace "if num > 0" with "if (num == 0)" or simply "if (! num)", and the action should be something like "$('ol.references').closest('h2').toggle(false)" or something similar.

peace.

Reply to "Number of references"