MediaWiki - Searching based on PageID - mediawiki

I'm using MediaWiki at work and creating a Knowledge Base. We've got everything set up but one requirement is to have a unique identifier on each page, then it can be referenced in official documentation. I've done this by using the magic word {{PAGEID}} so it's added to the bottom right of each page.
Another requirement is to be able to find the page based on this unique number but when using the built in search function the page can't be found.
For example, the main page has the text "Page ID:1" in the bottom right corner. When doing a search for "Page ID:1" nothing can be found and the Wiki only gives me the option to create the page.
Does anyone know how you can either search on, or have the search include the Page ID?
Any help would be appreciated.

global $wgHooks;
$wgHooks['SearchGetNearMatchBefore'][] = function ( array $allSearchTerms, &$titleResult ) {
$searchTerm = $allSearchTerms[0];
if ( preg_match( '/^id:\d+$/', $searchTerm ) ) {
$pageId = (int)substr( $searchTerm, 3 );
$titleResult = Title::newFromID( $pageId );
return false;
}
};
will jump to the page with ID 123 when you enter id:123 in the search box. Seems like a silly way to use search though.

Related

List of forward links on mediawiki page

I am using a Mediawiki site as a personal Zettelkasten. The zettelkasten is basically a collection of notes that should be linked to one another, making a wiki a good place to store one. The linking between the notes is the key feature of the zettelkasten. So for each "note" (i.e., page on my wiki), I need a list of 1) how to get to that page and 2) where you can go from that page. The first part is easy, since I can use the built-in {{Special:Whatlinkshere/{{PAGENAME}}}}. However, I can't figure out how to create a similar list of forward links from each page. Is there a way to do this within mediawiki, or an extension that can do this? What is the best way to gather a list of all (internal) links on a given wiki page?
If you install DynamicPageList3, you can use {{#dpl: linksfrom = {{FULLPAGENAME}} }}.
With Scribunto, you can define Module:Links with inner function:
local p = {}
function p.inner (frame)
local wikitext = frame:preprocess (mw.title.new (frame.args [1]):getContent ())
local link_set = {}
-- Find all occurences of [[...]]:
for title in mw.ustring.gmatch (wikitext, '%[%[([^%#|%]]+)%]%]') do
-- Remove #... or |...:
title = mw.text.trim (mw.ustring.gsub (title, '[#|][^%]]*', '', 1))
if title ~= '' then
link_set [title] = true
end
end
local links = {}
for link, _ in pairs (link_set) do
links [#links + 1] = '[[' .. link .. ']]'
end
table.sort (links)
return table.concat (links, ', ')
end
return p
and call it like this: {{#invoke:Links|inner|{{FULLPAGENAME}}}}. But this is expensive, and you mat need to filter titles better, if you have Semantic MediaWiki installed. There also will be issues with synchronisation (the list of links will be one version behind the page it is in, until a purge).

Can I add Heading text to the footer in a Google Docs file automatically?

I have a document that consists of approximately 20 chapters, divided over 60 pages. Each new chapter starts at the top of a new page. What I would like to do, is to automatically add the active Chapter title to the footer of that page. I know this behavior is possible in Microsoft Word, but I can not find it in Google Docs.
It can be done manually by inserting section breaks, but that is inconvenient for me, since I want to use this process in over 1.000 different documents.
Example:
Chapter 1 is called "Test chapter" and starts at page 1
Chapter 2 is called "Another chapter" and starts at page 4
Then on page 1, 2 and 3 the footer of the page should contain the text "Test Chapter". On page 4, the footer should contain the text "Another chapter".
Thank you in advance!
Unfortunately, this still isn't available as of the moment and has no update since the issue of the bug.
I have been trying to circumvent this issue via Apps Script and never had a proper solution as the footers and headers are being treated as one.
By default, changing a footer section will apply to all footer sections, and if they were separated by section break, they are not ordered by page but by the order of them being added on the document so it would be tricky and would require you to add them in this order for my code to work.
Object Order:
After BODY_SECTION, next children of the document should be alternating HEADER_SECTION then FOOTER_SECTION.
NOTE:
Logger.log part of the code shows what is the object order of your document. If it looks like the above order, then the code below will work.
Code:
function setHeaderAsFooter() {
var d = DocumentApp.getActiveDocument();
var p = d.getBody().getParent();
for ( var i = 0; i < p.getNumChildren(); i += 1 ) {
var c = p.getChild(i);
var t = c.getType();
// Check what type is the object
// Comment out if-block below to see if what is the object order in your document
Logger.log(t);
// Every header you encounter, set it as footer value of the next object
if ( t === DocumentApp.ElementType.HEADER_SECTION) {
var f = c.getNextSibling();
f.asFooterSection().setText(c.asHeaderSection().getText());
}
}
}
If they aren't in HEADER -> FOOTER alternating order after the BODY, then the code above won't work.
Most likely, this is not the answer you were hoping for, so I do sincerely apologize. I hope that this answer will help you in any way at least.

Recommendations for populating formatted content pages from the database

I'm working on my first laravel project- a family tree website. Everything's going great with the normal models/controllers/views, but I've gotten to a special case that I'm not sure how to approach. I have about a dozen auxiliary stories that go along with specific people or families- this is extra stuff that most records don't have.
In my previous incarnation of this site, I had a stories table with a headline, source for the material, and a slug, I made an html page for each story, and then I'd link to that page using the slug value.
In Laravel this seems like a really clunky way to go about it (especially as I add more stories), because it's messy to have to make a new route/controller/view for each one.
So I've made a general StoryController and view in hopes of reusing that to display the contents of any story. I've added a 'text' column into my stories table for those contents, and I've copied the HTML (with the problematic characters escaped). But of course when I display this story text on the view, I see all the markup tags displayed themselves (instead of helping to render the actual text in paragraphs, etc).
So two questions: is there a way to treat the field as html itself (instead of a string)? And is my approach off-base and I should do this a different way?
Thanks in advance for any help!
Update: thanks to The Happy Mamba, it works if I call to another function for html_entity_decode and echo out the results, but weirdly it DOESN'T work if I 'return' the results (or do it in the same function). It didn't render the tags until I did it like so (in StoryController):
public function convert($string)
{
echo (html_entity_decode($string));
}
public function show($id)
{
$story = Story::find($id);
$content = StoryController::convert($story->text);
return view ('story/show', compact('story', 'content'));
}
The snag there is that because it's using echo, that field is displayed first no matter what.... so if I can't get around that I'll need to conversion in and out of the database as suggested (still need to get the Connection string working)- but this is a great step forward!
Have you tried pulling it out of the database and then sending the text to htmlentities?
Here's some code to test it. Examples are in postgresql but should work the same with PDO/laravel specific functions:
<?php
$conn = pg_connect('db connection string here');
$text = pg_escape_literal( $conn, htmlentities( '<html><head></head><body><em>test</em></body></html>' ) );
pg_query( $conn, 'TRUNCATE TABLE test' );
pg_query( $conn, "INSERT INTO test VALUES ( {$text} )" );
$result = pg_query( $conn, 'SELECT * FROM test' );
$row = pg_fetch_row( $result );
pg_close( $conn );
$string = $row[0];
echo html_entity_decode($string);
?>
Result:
bolded "test" in browser.
After trying a few things, the solution I like best is to make a partial for each story, and then dynamically include the correct one based on the story.slug. (This way I still need only one story route/show function/view, and I can update the content much more easily than if I'm cramming html into the database)

AngularJS - Conditionally display key and value if they exist

This may be a little confusing to describe.
Basically, I am parsing multiple external JSON feeds that display in different views depending on the 'active tab' displayed. They both share the same partial template, so they both look exactly the same, just different content.
The problem that I am facing now is, that in some feeds, some keys are placed in an array and others are not.
For example, the feeds parses this kind of data:
JSON Feed 1 - One 'attributes' inside of 'link'
"link":{
"attributes":{
"href":"www.link1.com"
}
}
JSON Feed 2 - Two 'attributes' inside of 'link'
"link":[
{
"attributes":{
"href":"www.link1.com"
}
},
{
"attributes":{
"href":"www.link2.com"
}
}
]
The only way I am able to get the value "www.link1.com" is via:
For Feed 1:
link1
And for Feed 2:
link1
I am trying to figure out what would be the best way to do:
1) If link[0] exists - display it, else if [link] exists, display that instead.
2) Or if targeting the activeTab would be safer? For instance, if activeTab = view2 or view4, use [link][0], else if activeTab = view1 or view3 use [link], else if I do not want it to be displayed, do not display anything.
Also a relatable question, if I am on view2 can I only display [link][0] on that view?
Any feedback would be appreciated. Thanks!
In your model controller, you can reconstruct the JSON objects to make them similar. The value of link in both feeds should be an array.
Then in your template you can simply use ngRepeat to get the items from inside the array.
Okay - so I found a solution to one of the questions above: "How to only display [link][0] in a specific view"
Pro: It's a simple code that depends on the activeTab / view that is being displayed.
Con(?): Since I am really a newbie to AngularJS - not sure if this is the best solution.
Basically:
Depending on the ng-view that is currently displayed, than a specific JSON object will be displayed, such as:
<a ng-show="activeTab == 'view1' || activeTab == 'view3'" ng-href="{{item['link'][0]['attributes']['href']}}">
<h6>Link1 from Feed2</h6>
</a>
Although the primary question is still unresolved: How to swap/switch JSON objects (key,values) if one exists, and not the other. I am still definitely trying to find a solution, although any help is still appreciated.
Please let me know what you think, or how I can improve the solution to the problem!
Thanks!
Roc.

Mediawiki inline template creation

Is it possible to create a wiki page, where you mark a single piece of text as a placeholder which can be put anywhere else on the wiki?
Let's say I have a wiki page containing a simple list. The first item in list must be always shown in the Main Page but the editing user should not edit two pages for that, just one page.
The list page:
Pineapples
{{SaveThisText|TodaysMeal|Dumplings}}
Beans
Oranges
Main Page:
Today, we'll have {{GetSavedText|TodaysMeal}}
...Main Page will result to "Today, we'll have Dumplings"
I know that it is possible to do this using templates but I want to avoid them, I want to edit the template like it's a part of page.
You can do this without writing any custom PHP, see:
http://www.mediawiki.org/wiki/Extension:Variables
This is definitely possible if you write a MediaWiki extension for it. This means that you could place a hook on GetSavedText and SaveThisText so their behaviour can be customized.
If you have a small wiki, you could just cycle through every page on the occurance of GetSavedText an search for {{SaveThisText|TodaysMeal|. Getting every page is easy:
// get existing pages
$db = wfGetDB ( DB_MASTER );
$results = $db->resultObject ( $db->query(
"select distinct page_title from {$wgDBprefix}page " )
);
$existing_pages = array();
while ( $r = $results->next() )
$title = Title::newFromText( $r->page_title );
$article = new Article ( $title );
$content = $article->getContent();
A more efficient approach would be to place a hook on the update of a page. If SaveThisText is present, you could update a line in a database table.