Headings created inside of a template - mediawiki

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?

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).

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."

Related

MediaWiki: How to update a link status programmatically

My extension renders additional links on a page (that is adds some <a href='...'>...</a> to the page text (in HtmlPageLinkRendererEnd hook)).
See small arrows in https://withoutvowels.org/wiki/Tanakh:Genesis_1:1 for an example. The arrows are automatically added by my extension (sorry, at the time of writing this the source code is not yet released).
The problem is that red/blue ("new") status is not updated for links which I add.
Please explain how to make Wikipedia to update color of my links as appropriate together with regular [[...]] MediaWiki links.
My current workaround is to run php maintenance/update.php. It is a very bad workaround. How to do it better?
Normally you'd use LinkRenderer to create the links and LinkBatch to make the page existence check efficient (you don't want a separate SQL query for each link). You can't really do that in HtmlPageLinkRendererEnd since you only learn about the links one by one.
The way the parser deals with this is that it replaces links with a placeholder and collects them in a list, then after parsing is mostly done it looks them all up at once and then switches the placeholders with the rendered links. You can probably hook into somthing that happens between the two (e.g. ParserAfterParse), get the list of links from the parser and use them to build a list of your own links.
With valuable help of Wikitech-l mailing list, I found a solution.
The solution is to use ParserAfterTidy hook.
public static function onParserAfterTidy( &$parser, &$text ) {
# ...
$parserOutput = $parser->getOutput();
foreach($parserOutput->getLinks() as ...) {
# ...
$parserOutput->addLink( Title::newFromDBkey(...) );
}
}

How to best transfer a document to a SAPUI5 framwork?

I'd like to achieve the following and I'm looking for ideas. I have a document and I want to represent/transform this content in/to a nice SAPUI5 framework. My idea is the following: a split app with having the paragraph titles in the master view (plus a search function on top) and the respective content in the detail view.
I'd like to know from you if
a) you might want to share your ideas and hints on alternatives.
b) this can be achieved within one single file (i.e. all the code for the split app and document content in one html) and maybe using pure html code (xml also feasible) - against the background of easily handing a large amount of text available in html.
c) if you happen to have/know a reusable template.
Thanks in advance!
An interesting question. I went through a similar exercise once, re-presenting my site with UI5.
To your questions:
(a) I would think that the approach you suggest is a good one
(b) You can indeed include all the app in a single file, I do that often by using script templates, even with XML Views. You can see some examples in my sapui5bin repository, in particular in the SinglePageExamples folder. Have a look at this html file for example: https://github.com/qmacro/sapui5bin/blob/master/SinglePageExamples/SAP-Inside-Track-Sheffield-2014/end.html
What I would suggest is, rather than intermingle the document content and the app & view definitions, maintain the content of your document separately, for example, in XML or JSON, and use a client side model to load it in and bind the parts to the right places.

Drupal 7 navigation based on URL

Does anyone know if it's possible to extract the URL and if a value is found within the URL to display/hide something?
For instance, if I have a navigation bar that I want to only display for pages that contain 'copier' and I have URL aliases setup, can I setup Views module (or something like that) to check the URL for the 'copier' value and if it's found to display the navigation? If so, how would I go about doing that?
I know there can't be duplicate URL aliases but if say I had them as:
node/Copier
node/Copier-training
Could I check that URL and see if copier is present, and if it is display the navigation assoicated with copier?
I'm not really familiar with Views.
Not sure if this answers your question or not, the mention of Views is throwing me off a bit, but I believe all you need work with is a Block. You put your navigation into the Block, and then set the "Visilibity Settings" to be
node/*copier*
and set "Show block on specific pages" to "Only the listed pages".
This would then show the block on any page with copier in the URL, however this would only work for URLs of the type node/blahblahblah, if you wanted it to also show on say a URL such as blog/copier-training you would have to add another line to the Visibility Settings of the Block
node/*copier*
blog/*copier*
and also for any subsequent drill-downs also, for instance say blog/richie/copier-training would require
node/*copier*
blog/*copier*
blog/richie/*copier*
alternatively you could write a whole load of wildcarded options that go as deep as your site URLs may go
*/*copier*
*/*/*copier*
*/*/*/*copier*
ad infinitum
which is probably better...
If you do want to show a View within the Block you can use the following PHP
<?php
//load the view by name
$view = views_get_view('sample_view');
//output the view
print views_build_view('embed', $view);
?>
Hope this helped.

Pulling out some text from a giant HTML file using Nokogiri/xpath

I am scraping a website and am trying to pull out certain elements from the HTML. In the sites I am scraping, there are script tags with a bunch of info in them however, there is one part inside these tags that I am interested in. The line basically looks like:
'image':'http://ut5.example.com/t/231/3_b_643435.jpg',
With some stuff above and below it. Now, this is different for each page source except for obviously the domain and some of the subfolders that store the images.
How would I go about looking through the source for this specific line, and cutting out just the URL? I would need to use regular expressions I feel as the URLs are dynamic.
The "gsub" method does something similar to what I want to search for, with its ability to use /regex/. But, I am not wanting to replace anything, I just want to find that URL in the source code using a /regex/ and copy it.
According to you comments, this is what you're looking for I guess
var regex = /http.+/;
Example http://jsfiddle.net/Km9ZB/

MediaWiki : is it possible to add an edit link in a template?

I have a template on my wiki, kind of a box template.
Then, there is this page where I use it several times.
Can I add an edit link to each of the boxes so I don't have to edit the whole page in order to modify one of the boxes?
The boxes contain only text, not other templates.
Thanks!
Edit: Actually there's an easier way to ask my question:
Let's say I have a page without sections defined (namely without == titles ==):
content A
content B
content C
Is there a way to open an edit form only for content B?
"Is there a way to open an edit form only for content B?" - in standard mediawiki - no, but you can do sth like this
Main page will look like this:
{{/subpageA}}
{{/subpageB}}
{{/subpageC}}
subpageA will contain link to edit subpageA etc
But it is worse than sections in every possible way.
If I understand your question, and I'm not sure I do, I'm assuming your box is a div or table of some sort? If so, you could add id="{{{1|Some identifying parameter}}} to it.. Now, similar to if you had used == header 2 == you will be able to link to that section of the page with [[{{PAGENAMEE}}#{{{1|Some identifying parameter}}}]]. The only trick is to edit that section. You would likely have to set up a <span class=plainlinks>[http://somewiki.com/edit/{{PAGENAMEE}}&section={{{1|Some identifying parameter}}}]</span> Although, I'm not sure using the section name will work on your wiki, it works on only one of four that I edit. The other three require the section number, which may be harder to figure out, or at very least is beyond my pay-grade atm..
Not sure what you're asking here. Do you want to edit the template from the referring page?
Update:
One: The ugly but simple solution:
Add the following code above the text you want to edit:
=== ===
This will create a section with no name, but with an edit link. If you make four or more of these links, you will create a TOC in the page. You can suppress this with:
__NOTOC__
Two: The neat but extensive solution:
Make your wiki semantic and use Semantic_Forms to edit the page using a form.
Not with the standard installation.
But, I'm sure you could write an extension to do this. Eg. Right click on the page and it will start editing there.
It is possible to add link to edit template, so you can make ugly hack and create separate templates/subpages for every single box.