r97866 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97865‎ | r97866 | r97867 >
Date:23:06, 22 September 2011
Author:tstarling
Status:ok
Tags:
Comment:
Added 404.php from live-1.5
Modified paths:
  • /trunk/tools/web-scripts/404.php (added) (history)

Diff [purge]

Index: trunk/tools/web-scripts/404.php
@@ -0,0 +1,162 @@
 2+<?php
 3+header( 'Content-Type: text/html; charset=utf-8' );
 4+
 5+# $_SERVER['REQUEST_URI'] has two different definitions depending on PHP version
 6+if ( preg_match( '!^([a-z]*://)([a-z.]*)(/.*)$!', $_SERVER['REQUEST_URI'], $matches ) ) {
 7+ $prot = $matches[1];
 8+ $serv = $matches[2];
 9+ $loc = $matches[3];
 10+} else {
 11+ $prot = "http://";
 12+ $serv = strlen($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] :
 13+ $_SERVER['SERVER_NAME'];
 14+ $loc = $_SERVER["REQUEST_URI"];
 15+}
 16+# Fix protocol if needed
 17+if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) {
 18+ $prot = "https://";
 19+}
 20+
 21+$encUrl = htmlspecialchars( $prot . $serv . $loc );
 22+header( "Cache-Control: s-maxage=2678400, max-age=2678400");
 23+header( "X-Wikimedia-Debug: prot=$prot serv=$serv loc=$loc");
 24+if( preg_match( "|(%2f)|i", $loc, $matches ) ||
 25+ preg_match( "|^/upload/(.*)|i",$loc, $matches ) || preg_match("|^/style/(.*)|i",$loc, $matches ) ||
 26+ preg_match( "|^/wiki/(.*)|i",$loc, $matches ) || preg_match("|^/w/(.*)|i",$loc, $matches ) ||
 27+ preg_match( "|^/extensions/(.*)|i",$loc, $matches ) ) {
 28+ $title = $matches[1];
 29+ $details = "<p style=\"font-weight: bold;\">To check for \"$title\" on Wikipedia, see:
 30+ <a href=\"//en.wikipedia.org/wiki/$title\" title=\"Wikipedia:$title\">
 31+ //en.wikipedia.org/wiki/$title</a></p>";
 32+} else {
 33+ if( in_array( $loc, array( '/Broccoli',
 34+ '/Romanesco',
 35+ '/Mandelbrot_set',
 36+ '/Mandelbrotmenge' ) ) ) {
 37+ # HACKHACKHACK
 38+ # Special case for broken URLs which somebody
 39+ # put into a print ad. Why??!!?!??!?!?!?!
 40+ if (headers_sent()) return false;
 41+ header("HTTP/1.1 301 Moved Permanently");
 42+ header("Location: ".$prot.$serv."/wiki".$loc);
 43+ header("X-Wikimedia-Debug: prot=$prot serv=$serv loc=$loc");
 44+ }
 45+
 46+ $target = $prot . $serv . "/wiki" . $loc;
 47+ $encTarget = htmlspecialchars( $target );
 48+ header( "Refresh: 5; url=$encTarget" );
 49+ $details="<p><b>Did you mean to type <a href=$encTarget>$encTarget</a>?</b>
 50+ You will be automatically redirected there in five seconds.</p>";
 51+}
 52+$base_404=<<<END
 53+<html>
 54+ <head>
 55+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 56+ <title>Wikimedia page not found: $encUrl</title>
 57+ <link rel="shortcut icon" href="https://www.mediawiki.org/favicon.ico">
 58+ <style type="text/css">
 59+ * {
 60+ font-family: 'Gill Sans', 'Gill Sans MT', sans-serif;
 61+ }
 62+ a:link, a:visited {
 63+ color: #005b90;
 64+ }
 65+ a:hover, a:active {
 66+ color: #900000;
 67+ }
 68+ body {
 69+ background-image:
 70+url('//upload.wikimedia.org/wikipedia/commons/9/96/Errorbg.png');
 71+ background-repeat: repeat-x;
 72+ background-color: white;
 73+ color: #484848;
 74+ margin: 0;
 75+ padding: 0;
 76+ height: 100%;
 77+ }
 78+ h1 {
 79+ color: black;
 80+ margin: 0px;
 81+ }
 82+ h2 {
 83+ color: #484848;
 84+ padding: 0px;
 85+ margin: 0px;
 86+ }
 87+ p {
 88+ margin-top: 10px;
 89+ margin-bottom: 0px;
 90+ padding-bottom: 0.5em;
 91+ }
 92+ #center {
 93+ position: absolute;
 94+ top: 50%;
 95+ width: 100%;
 96+ height: 1px;
 97+ overflow: visible;
 98+ }
 99+ #main {
 100+ position: absolute;
 101+ left: 50%;
 102+ width: 720px;
 103+ margin-left: -360px;
 104+ height: 340px;
 105+ top: -170px
 106+ }
 107+ #logo {
 108+ display: block;
 109+ float: left;
 110+ background-image:
 111+url('//upload.wikimedia.org/wikipedia/commons/thumb/8/81/Wikimedia-logo.svg/300px-Wikimedia-logo.svg.png');
 112+ background-position: top center;
 113+ background-repeat: no-repeat;
 114+ height: 340px;
 115+ width: 300px;
 116+ }
 117+ #divider {
 118+ display: block;
 119+ float: left;
 120+ background-image:
 121+url('//upload.wikimedia.org/wikipedia/commons/9/97/Errorline.png');
 122+ background-position: center center;
 123+ background-repeat: no-repeat;
 124+ height: 340px;
 125+ width: 1px;
 126+ margin-left: 10px;
 127+ margin-right: 10px;
 128+ }
 129+ #message {
 130+ padding-left: 10px;
 131+ float: left;
 132+ display: block;
 133+ height: 340px;
 134+ width: 370px;
 135+ }
 136+ </style>
 137+ </head>
 138+ <body>
 139+ <div id="center">
 140+ <div id="main">
 141+ <div id="logo"></div>
 142+ <div id="divider"></div>
 143+ <div id="message">
 144+ <h1>Error</h1>
 145+ <h2>404 – File not found</h2>
 146+ <p style="font-style: italic;">$encUrl</p>
 147+ <p>We could not find the above page on our servers.</p>
 148+ $details
 149+ <p>Alternatively, you can visit the <a href="https://www.mediawiki.org/">Main Page</a> or
 150+read <a href="https://www.mediawiki.org//en.wikipedia.org/wiki/HTTP_404" title="Wikipedia:
 151+HTTP 404">more information</a> about this type of error.</p>
 152+ <p style="font-size: smaller;">A project of the <a
 153+href="https://www.mediawiki.org//wikimediafoundation.org/wiki/Home" title="Wikimedia
 154+Foundation">Wikimedia Foundation</a></p>
 155+ </div>
 156+ </div>
 157+ </div>
 158+ </body>
 159+</html>
 160+END;
 161+
 162+print ($base_404);
 163+?>
Property changes on: trunk/tools/web-scripts/404.php
___________________________________________________________________
Added: svn:eol-style
1164 + native

Status & tagging log