Skip to content
This repository was archived by the owner on Sep 23, 2023. It is now read-only.

Commit 1f67246

Browse files
authored
Add custom 404 handler
Fixes #106
1 parent 844eb65 commit 1f67246

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

.htaccess

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RewriteEngine on
2+
# Equivalent to ErrorDocument, but uses a relative path
3+
RewriteCond %{REQUEST_FILENAME} !-f
4+
RewriteCond %{REQUEST_FILENAME} !-d
5+
RewriteRule .* 404.php [L]

404.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
header( 'HTTP/1.0 404 Not Found' );
3+
require_once "includes.php";
4+
5+
echo new \OOUI\MessageWidget( [
6+
'type' => 'error',
7+
'label' => 'Page not found. The wiki you are looking for may have been deleted.'
8+
] );
9+
10+
include "footer.html";

includes.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,28 @@
1616

1717
OOUI\Theme::setSingleton( new OOUI\WikimediaUITheme() );
1818

19+
$basePath = dirname( $_SERVER['SCRIPT_NAME'] );
20+
if ( $basePath === '/' ) {
21+
$basePath = '';
22+
}
23+
$is404 = basename( $_SERVER['SCRIPT_NAME'] ) === '404.php';
24+
1925
echo '<!DOCTYPE html>
2026
<html>
2127
<head>
2228
<meta charset="utf-8">
2329
<title>Patch demo</title>
24-
<link rel="stylesheet" href="index.css">
25-
<link rel="stylesheet" href="node_modules/oojs-ui/dist/oojs-ui-wikimediaui.min.css">
26-
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
27-
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
28-
<link rel="mask-icon" href="images/safari-pinned-tab.svg" color="#006699">
29-
<link rel="shortcut icon" href="images/favicon.ico">
30+
<link rel="stylesheet" href="' . $basePath . '/index.css">
31+
<link rel="stylesheet" href="' . $basePath . '/node_modules/oojs-ui/dist/oojs-ui-wikimediaui.min.css">
32+
<link rel="icon" type="image/png" sizes="32x32" href="' . $basePath . '/images/favicon-32x32.png">
33+
<link rel="icon" type="image/png" sizes="16x16" href="' . $basePath . '/images/favicon-16x16.png">
34+
<link rel="mask-icon" href="' . $basePath . '/images/safari-pinned-tab.svg" color="#006699">
35+
<link rel="shortcut icon" href="' . $basePath . '/images/favicon.ico">
3036
</head>
3137
<body>
3238
<header>
3339
<div class="headerInner">
34-
<h1><a class="logo" href=".">Patch demo</a></h1>';
40+
<h1><a class="logo" href="' . $basePath . '/.">Patch demo</a></h1>';
3541

3642
include_once 'oauth.php';
3743

oauth.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$useOAuth = !empty( $config[ 'oauth' ][ 'url' ] );
1111

12-
if ( $useOAuth ) {
12+
if ( $useOAuth && !$is404 ) {
1313
$conf = new ClientConfig( $config[ 'oauth' ][ 'url' ] );
1414
$conf->setConsumer( new Consumer(
1515
$config[ 'oauth' ][ 'key' ],
@@ -48,5 +48,4 @@
4848
include 'footer.html';
4949
die();
5050
}
51-
5251
}

0 commit comments

Comments
 (0)