Headings created inside of a template
Asked Answered
R

2

6

I have a number of templates that create headings based on a formula. I am wondering if there is anyway to create an "edit" link that will take you directly to that section? The way that it currently works, the edit link takes you to editing the template itself. Could I possibly create a customized link that would keep you on the page and take you to right part?

Here is some sample code to help clear things up...

Template:Head:

==={{{1}}}===
This is a heading titled "{{{1}}}"

Test Page:

=Section 1=
{{head|1.1}}
{{head|1.2}}
{{head|1.3}}
=Section 2=
{{head|2.1}}
{{head|2.2}}
{{head|2.3}} 

At the moment, if I want to edit the information for template "2.3", I have to edit all of section 2. (Note that for this example, that isn't a big deal. For the actual templates I am working with on my site, the templates have dozens of parameters and there are sometimes 10 or more in a section.)

Bottom line, is there way to create a custom edit link inside of the {{head}} template that would take you directly to editing the templates call on the page "Test Page"? Hope that makes sense.

Edit: Is there perhaps a way to make use of "anchor" tags? Can anchors be passed in to the URL?

Ratfink answered 1/3, 2013 at 19:17 Comment(0)
S
1

I'm pretty sure there's no way to do that. As far as MediaWiki's section editing feature is concerned, the only thing that begins a new section is a line of the form:

=== Some text here ===

with the number of = signs determining the level of the heading. There's no way to get MediaWiki to let you edit any segment of the document that doesn't begin and end with such a line (or the beginning or end of the page).

Well, OK, I'm sure you technically could do it with an extension, in the sense that you can do anything with a MediaWiki extension. All you'd need to do is provide some way (e.g. a special parameter in an edit URL) for to user to indicate "I want to edit this template", then extract the template from the wikitext, present it to the user for editing, and write the result back into the page text over the original.

The tricky part will be extracting the template from the page source. (Finding and replacing templates on a page is a fairly common task for MediaWiki bot writers, so you might want to look for ideas there.) Whatever method you end up using for that, there will probably be edge cases where you need to give up and tell the user "Sorry, but I can't figure out how that template is transcluded here."

Sellma answered 2/3, 2013 at 17:58 Comment(0)
L
2

To restate your problem, when you transclude a section heading the header isn't treated as being part of the destination page, so the edit link takes you back to the source. So you need a separate container for the template in order to edit it individually, and a complete section is the smallest editable container.

The only way I can think of doing this is using subpages (or virtual subpages if you don't have that ennabled in this namespace, doesn't change anything). So instead of placing {{head|1.1}} on MyPage, put it on MyPage/Subpage1 and then transclude that into MyPage in the usual way ({{:MyPage/Subpage1}}).

{{head}} can then include a custom edit link to the template input by using HTML heading tags (<h2> is equal to ==, etc.) to suppress the standard edit link and then use one of these templates (probably {{ed right}}) to create a custom edit link pointing to MyPage/Subpage1.

The way to create anchors in Mediawiki, by the way, is to use a <span id="name"/> tag, but that doesn't create a container that can be edited (or at least, not that I've been able to work out through URL tinkering).

Longsighted answered 4/3, 2013 at 15:23 Comment(7)
The issue is what argument do you supply as {{{1}}} to the template? Its a great idea but it doesn't seem to work. Thanks though.Ratfink
Right, sorry, didn't think it through all the way. To restate your problem, when you transclude a section heading the header isn't treated as being part of the destination page, so the edit link takes you back to the source. So what you really want to do is edit on part of a section without opening the entire section in the edit box. Before I try to devise some particularly complex WML slight-of-hand, is there a reason why you can't include the section headers directly on the destination page?Longsighted
The section headers are created based off of a formula.Ratfink
Are the templates for inclusion set in stone, or are they included or excluded automatically based on predetermined criteria?Longsighted
They can be included or excluded based on the user's preference. It is not set it stone.Ratfink
Okay, that kills one way of doing it. The problem is that you need a container for the template in order to edit it separately, and a complete section is the smallest editable container. The only other way I can think of doing that is using subpages (or virtual subpages if you don't have that ennabled in this namespace, doesn't change anything). Instead of placing {{head|1.1}} on MyPage, put it on MyPage/Section 1.1 and then transclude that into MyPage in the usual way ({{:Mypage/Section 1.1}}). {{head}} can then include a custom edit link to Mypage/Section 1.1 in the way I mentioned.Longsighted
The way to create anchors in Mediawiki, by the way, is to use a <span id="name"/> tag, but that doesn't create a container that can be edited (or at least, not that I've been able to work out through URL tinkering.Longsighted
S
1

I'm pretty sure there's no way to do that. As far as MediaWiki's section editing feature is concerned, the only thing that begins a new section is a line of the form:

=== Some text here ===

with the number of = signs determining the level of the heading. There's no way to get MediaWiki to let you edit any segment of the document that doesn't begin and end with such a line (or the beginning or end of the page).

Well, OK, I'm sure you technically could do it with an extension, in the sense that you can do anything with a MediaWiki extension. All you'd need to do is provide some way (e.g. a special parameter in an edit URL) for to user to indicate "I want to edit this template", then extract the template from the wikitext, present it to the user for editing, and write the result back into the page text over the original.

The tricky part will be extracting the template from the page source. (Finding and replacing templates on a page is a fairly common task for MediaWiki bot writers, so you might want to look for ideas there.) Whatever method you end up using for that, there will probably be edge cases where you need to give up and tell the user "Sorry, but I can't figure out how that template is transcluded here."

Sellma answered 2/3, 2013 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.