r106857 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106856‎ | r106857 | r106858 >
Date:20:43, 20 December 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
Also handle URLs like index.php?title=Page. Fallback to main page if no title found. Also do a basic check if URL seems valid before redirecting.
Some other changes: pass &uselang on to main page; missed some URLs to make protocol-relative; put HTML outside of PHP
Modified paths:
  • /trunk/tools/web-scripts/missing.php (modified) (history)

Diff [purge]

Index: trunk/tools/web-scripts/missing.php
@@ -59,7 +59,13 @@
6060 $project = $tmp[0];
6161 $language = $tmp[1];
6262 $base = 'secure.wikimedia.org/wikipedia/incubator/wiki/';
63 - $page = implode( array_slice( $tmp, 3 ) );
 63+ if( isset( $_SERVER['PATH_INFO'] ) ) {
 64+ $page = implode( array_slice( $tmp, 3 ) ); # /wiki/Page (possibly /wiki/Page?foo=bar)
 65+ elseif( $_GET['title'] ) {
 66+ $page = $_GET['title']; # index.php?title=Page
 67+ } else {
 68+ $page = ''; # no known title, fallback to main page
 69+ }
6470
6571 } else {
6672
@@ -68,7 +74,13 @@
6975 $project = $tmp[1];
7076 $language = $tmp[0];
7177 $base = 'incubator.wikimedia.org/wiki/';
72 - $page = preg_replace( '/^\/wiki\//', '', $url['path'] );
 78+ if( isset( $_SERVER['PATH_INFO'] ) ) {
 79+ $page = preg_replace( '/^\/wiki\//', '', $url['path'] ); # /wiki/Page (possibly /wiki/Page?foo=bar)
 80+ elseif( $_GET['title'] ) {
 81+ $page = $_GET['title']; # index.php?title=Page
 82+ } else {
 83+ $page = ''; # no known title, fallback to main page
 84+ }
7385
7486 }
7587
@@ -79,7 +91,8 @@
8092 $location = $url['scheme'] . '://' . $base . 'W' . $projectcode . '/' . urlencode( $language );
8193 # Go to the page if specified (look out for slashes), otherwise go to
8294 # the main page Wx/xyz?goto=mainpage (WikimediaIncubator extension takes care of that)
83 -$location .= $page && $page !== '/' ? '/' . $page : '?goto=mainpage';
 95+$location .= $page && $page !== '/' ? '/' . $page :
 96+ '?goto=mainpage' . ( $_GET['uselang'] ? '&uselang=' . urlencode( $_GET['uselang'] ) : '' );
8497
8598 $redir = false;
8699
@@ -87,15 +100,15 @@
88101
89102 # Wikisource
90103 case 's':
91 - $logo = 'http://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Wikisource-logo.svg/280px-Wikisource-logo.svg.png';
92 - $home = 'http://wikisource.org';
 104+ $logo = '//upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Wikisource-logo.svg/280px-Wikisource-logo.svg.png';
 105+ $home = '//wikisource.org';
93106 $name = 'Multilingual Wikisource';
94107 break;
95108
96109 # Wikiversity
97110 case 'v':
98 - $logo = 'http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Wikiversity-logo.svg/300px-Wikiversity-logo.svg.png';
99 - $home = 'http://beta.wikiversity.org';
 111+ $logo = '//upload.wikimedia.org/wikipedia/commons/thumb/9/91/Wikiversity-logo.svg/300px-Wikiversity-logo.svg.png';
 112+ $home = '//beta.wikiversity.org';
100113 $name = 'Beta Wikiversity';
101114 break;
102115
@@ -105,22 +118,21 @@
106119
107120 }
108121
109 -# OUTPUT
110 -# @fixme replace heredoc by better approach
111 -if( $redir ) {
 122+# If not Wikisource/Wikiversity and the URL seems valid, redirect to Incubator
 123+if( $redir && parse_url( $location ) !== false ) {
112124
113125 header( 'Location: ' . $location );
114126 exit();
115127
116 -} else {
 128+}
117129
118 - header( 'HTTP/1.x 404 Not Found' );
119 - header( 'Content-Type: text/html; charset=utf-8');
 130+header( 'HTTP/1.x 404 Not Found' );
 131+header( 'Content-Type: text/html; charset=utf-8' );
120132
121 - $escLanguage = htmlspecialchars( $language );
122 - $escProject = htmlspecialchars( $project );
123 - echo <<< EOT
124 -<!DOCTYPE html>
 133+$escLanguage = htmlspecialchars( $language );
 134+$escProject = htmlspecialchars( $project );
 135+
 136+?><!DOCTYPE html>
125137 <html lang="en" dir="ltr">
126138 <head>
127139 <title>$escLanguage&nbsp;$escProject does not exist</title>
@@ -193,6 +205,3 @@
194206 </div>
195207 </body>
196208 </html>
197 -EOT;
198 -
199 -}

Follow-up revisions

RevisionCommit summaryAuthorDate
r106957Follow-up r106857: forgot variables in html, fix {} with elseif, and avoid so...robin17:06, 21 December 2011

Comments

#Comment by Catrope (talk | contribs)   08:36, 21 December 2011
+
+?><!DOCTYPE html>

Putting the HTML outside PHP tags like that doesn't work because you have variables like $escProject in there. You need to either keep it in a heredoc or use <?php echo $escProject; ?> in a bunch of places.

#Comment by SPQRobin (talk | contribs)   17:06, 21 December 2011

Fixed in r106957

Status & tagging log