forked from wikimedia/operations-mediawiki-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-redirect.php
49 lines (43 loc) · 1.11 KB
/
search-redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
// get params
$language = isset( $_GET['language'] ) ? $_GET['language'] : '';
$search = isset( $_GET['search'] ) ? $_GET['search'] : '';
$fulltext = isset( $_GET['fulltext'] ) ? $_GET['fulltext'] : false;
$go = isset( $_GET['go'] ) ? $_GET['go'] : false;
$family = isset( $_GET['family'] ) ? $_GET['family'] : 'wikipedia';
if ( ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' )
|| ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' )
) {
$proto = 'https';
} else {
$proto = 'http';
}
// validate $language
if ( !preg_match( '/^[a-zA-Z\-]*$/', $language ) ) {
$language = 'en';
}
// validate $family
$sites = array(
'wikipedia',
'wiktionary',
'wikisource',
'wikinews',
'wikiversity',
'wikimedia',
'wikiquote',
'wikibooks',
'wikivoyage',
);
if ( !in_array( $family, $sites ) ) {
$family = 'wikipedia';
}
// make url
$url = "$proto://" . $language . '.' . $family . '.org/wiki/Special:Search?search=' . urlencode( $search );
if ( $fulltext ) {
$url .= '&fulltext=Search';
}
if ( $go ) {
$url .= '&go=Go';
}
// Redirect
header( "Location: {$url}" );