Jump to content

Topic on Extension talk:Cite/Flow archive

Remove numbering from id/href when reference name is defined

12
Jiou7 (talkcontribs)

I would like my references/notes to have permalinks, i.e. links which do not change when new references are added. So I was wondering whether there is a possibility to remove the number in id and href when references have name attributes.

Behavior I expect:

- <ref>...</ref> gives href="#cite-note-1" (which is the current behavior)

- <ref name="foo">...</ref> gives href="#cite-note-foo" (instead of href="#cite-note-foo-1" with the current behavior)


This numbering is hardcoded in ReferencesFormatter.php and FootnoteMarkFormatter.php using $val['key'] and $ref['key'] and I do not see any hook or system message able to change that.

Is there a clean way to do this, i.e. without changing Mediawiki core code?

Ancheta Wis (talkcontribs)

The footnote numbering is in order of appearance of the article. You can define a single reference in wikitext thus:

<ref name= foo >[https:theURLhere Your foo content here]</ref> at a single ref occurrence anywhere in the article. Your foo content obeys the rules of wikitext, such as bold, italic, indent, bullet etc. All the other occurrences of that ref content foo are of the form

<ref name= foo /> and the footnotes renumber automatically.

You can then position other copies of ref foo with the wikitext <ref name= foo /> where ever you need in the article. (I use NavPops to check the ref foo content but I have learned that the numbers themselves do not need to be maintained.) Each occurrence of that single foo is distinguished with alphabetical labels. But its footnote number is under program control. Only the name foo is under your control.

I have learned that name= foo works just as well as name="foo" and that camelCaseServesToDistinguish each ref foo namespace.

Thiemo Kreuz (WMDE) (talkcontribs)

What is the purpose of this permalink? What do you want to use it for?

One suggestion I have is to do something like this: <ref><span id="custom_anchor">…</span></ref>. The Wikipedias use templates for this, i.e. Template:Anchor.

Jiou7 (talkcontribs)

Thank you for your answers

@Ancheta Wis I want to keep the seconday numbering you mention when a reference name is used multiple times, but the first numbering seems useless as a given name cannot be used for different references but only to refer to the same reference multiple times. So to be more precise, let us imagine we have the successive ref tags:

- First <ref>...</ref> => gives id ="cite-ref-1"; href="#cite-note-1" . Ok for me

- Then <ref name="foo">...</ref> => gives id="cite-ref-foo_2-0"; href="#cite-note-foo-2" (I would like to have id="cite-ref-foo-0"; href="#cite-note-foo" instead)

- Then <ref name="foo" /> => gives id="cite-ref-foo_2-1"; href="#cite-note-foo-2" (I would like to have id="cite-ref-foo-1"; href="#cite-note-foo" instead)


@Thiemo Kreuz (WMDE) My notes will be used to store additional information which are not just references so I want readers and contributors to be able to share a link to a specific note to share its valuable content.

I want this "permalink" to be created automatically for each named reference. I also want an anchor in the text (where the reference/note will be cited) so I need the second numberig mentionned above. (which is not so doable with templates) The Cite extension already does a lot of the work, so the solution consisting in creating an anchor is not ideal for me.

In fact, I do not understand why the numbering is kept in named references as you cannot use the same name for a different reference so it will necessary be uniue. A secondary numbering is used in the case of multiplle uses of a given reference as mentioned above and it seems sufficient.

Thiemo Kreuz (WMDE) (talkcontribs)

The way the Cite extension works (most notably: the behavior of each element heavily depends on it's position on the page) is quite a beast that's hard to tame. These additional sequence numbers help. I don't know if they are strictly necessary in all situations. Maybe they aren't. But even if, this is impossible to change 15 years and millions of pages later. Sorry. My suggestion is to use a template, e.g. <ref>{{refid|foo|Content of the reference here…}}</ref>.

Jiou7 (talkcontribs)

Thank you for your suggestion. I understand it is impossible to change the default behavior of the Cite extension. But wouldn't it be possible to create hooks or system message to make it parameterizable? For instance, you can alter a reference link with cite_reference_link_key_with_num but unfortunately not enough for my case.

Thiemo Kreuz (WMDE) (talkcontribs)

I had a closer look. Unfortunately, what you want to achieve is currently only possibly by patching the code:

  • In FootnoteMarkFormatter.php change the line with the code snippet $subkey = to $subkey = '';
  • In ReferencesFormatter.php change the line with the code snippet $key . '-' . ( $val['key'] ?? '' ) to $this->anchorFormatter->getReferencesKey( $key ),
Jiou7 (talkcontribs)

Indeed, I modified the core code of Mediawiki but I was looking for a solution which would not imply I have to redo the same modification at each upgrade.

Thank you for your time!

Ancheta Wis (talkcontribs)

My experience is with Wikipedia.en; in this wikipedia, I can define a more slowly varying ref with

<ref name= foo25 group= Bah >The noted [https: Your fooBahContent] </ref>

where each note has a distinguishing name foo1, foo2, .. foo25 etc.

which renders these slowly varying ref foo as [Bah 1], [Bah 2], etc in the body of the article in their own ref list.

Copies of the annotation get referenced as before: <ref name= foo25 group= Bah /> etc. You can intermix [Bah 1] and other refs [1]

But I also have to define a destination at the bottom

{{reflist| name = "Bah"}}

to display the notes at the bottom



Bahs

  1. The noted Your fooBahContent
  2. More note Their fooBahContent

References

1.

2.



I don't use visual editor, but I guess I'm learning a little usage here on this mediaWiki talk page.

  1. Your fooBah here

For example, it was not obvious to me that I did not need a reflist template location here. On Wikipedia you have to explicitly position the Bahs to see them.

  1. Ordinary foo
Jiou7 (talkcontribs)

I am not sure I understand how it can solve my problem of primary numbering that I want get rid of. Indeed, the primary numbering is still present in the href and id of notes in your example. Am I missing something?

This post was hidden by Ancheta Wis (history)
Ancheta Wis (talkcontribs)

The visual editor is getting in the way, so I deleted my reply, which had an example. Sorry

Reply to "Remove numbering from id/href when reference name is defined"