From af928542d51e84f910ca331b27aa58e330f315b6 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Sat, 7 May 2022 22:11:53 -0400 Subject: [PATCH 1/2] Colorize links to unwritten articles This is a form of dead link detection, called "red links" in MediaWiki. Links to unwritten articles are displayed in another color (red). This makes it easy for wiki authors to spot articles which need written without clicking through, or spelling errors. --- index.css | 4 ++++ index.php | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/index.css b/index.css index 4443f61..3225c4d 100644 --- a/index.css +++ b/index.css @@ -149,6 +149,10 @@ a.tool { color: #eeeeee; } +a.missing-link { + color: #ba0000; +} + input.tool { font-size: 11px; color: #000000; diff --git a/index.php b/index.php index e1313ac..b30c85a 100644 --- a/index.php +++ b/index.php @@ -84,7 +84,13 @@ function _handle_links($match) { - return "" . htmlentities($match[1]) . ""; + $link_page = $match[1]; + $link_filename = PAGES_PATH . "/$link_page.txt"; + $link_page_exists = file_exists($link_filename); + if ($link_page_exists) + return "" . htmlentities($link_page) . ""; + else + return "" . htmlentities($link_page) . ""; } From f4996318e22a8e780bb9129d8955b7af0dbf2032 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Sat, 7 May 2022 22:43:48 -0400 Subject: [PATCH 2/2] Fix colorization if article title needs sanitized. Add configuration option to turn off colorization. --- config.php | 7 +++++++ index.php | 15 ++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/config.php b/config.php index 95314e6..5c31aaa 100644 --- a/config.php +++ b/config.php @@ -113,6 +113,13 @@ define('AUTOLINK_PAGE_TITLES', false); +// COLORIZE_MISSING_PAGES +// +// Automatically highlights as red links, any linked pages which are +// not yet written. Existing but blank pages are not colorized. This +// might degrade performance if you have thousands of links on a page. + +define('COLORIZE_MISSING_PAGES', true); // ----------------------------- // Security and session settings diff --git a/index.php b/index.php index b30c85a..64f97c4 100644 --- a/index.php +++ b/index.php @@ -84,13 +84,18 @@ function _handle_links($match) { - $link_page = $match[1]; - $link_filename = PAGES_PATH . "/$link_page.txt"; - $link_page_exists = file_exists($link_filename); + $link = $match[1]; + if ( COLORIZE_MISSING_PAGES ) { + $link_page = sanitizeFilename($link); + $link_filename = PAGES_PATH . "/$link_page.txt"; + $link_page_exists = file_exists($link_filename); + } else { + $link_page_exists = true; + } if ($link_page_exists) - return "" . htmlentities($link_page) . ""; + return "" . htmlentities($link) . ""; else - return "" . htmlentities($link_page) . ""; + return "" . htmlentities($link) . ""; }