1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Make interwiki_* functions not crash if the interwiki index hasn't been configured yet

This commit is contained in:
Starbeamrainbowlabs 2019-01-05 17:10:46 +00:00
parent 7507867ca7
commit 76263f770c
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -3,7 +3,7 @@ register_module([
"name" => "Interwiki links",
"version" => "0.1",
"author" => "Starbeamrainbowlabs",
"description" => "Adds interwiki link support. Point the se",
"description" => "Adds interwiki link support. Set the interwiki_index_location setting at an index file to activate support.",
"id" => "feature-interwiki-links",
"code" => function() {
global $settings;
@ -15,13 +15,21 @@ register_module([
else
$env->interwiki_index = json_decode(file_get_contents($paths->interwiki_index));
}
// TODO: Fill this in
add_help_section("22-interwiki-links", "Interwiki Links", "");
}
]);
/**
* Updates the interwiki index cache file.
* If the interwiki_index_location isn't defined, then this function will do
* nothing.
*/
function interwiki_index_update() {
if(empty($settings->interwiki_index_location))
return;
$env->interwiki_index = new stdClass();
$interwiki_csv_handle = fopen($settings->interwiki_index_location, "r");
if($interwiki_csv_handle === false)
@ -60,6 +68,10 @@ function interwiki_pagename_parse($interwiki_pagename) {
*/
function interwiki_pagename_resolve($interwiki_pagename) {
global $env;
if(empty($env->interwiki_index))
return null;
// If it's not an interwiki link, then don't bother confusing ourselves
if(strpos($interwiki_pagename, ":") === false)
return null;