This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathwikia.php
92 lines (66 loc) · 2.89 KB
/
wikia.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
// This is from google translate, just return early.
if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) {
header ( "HTTP/1.1 200", true, 200 );
return;
}
// prevent $_GET['title'] from being overwritten on API calls (BAC-906)
define( 'DONT_INTERPOLATE_TITLE', true );
// Initialise common MW code
require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
if ( $wgProfiler instanceof Profiler ) {
$wgProfiler->setTemplated( true );
}
// Construct a tag for newrelic -- wgRequest is global in this scope
Transaction::setEntryPoint( Transaction::ENTRY_POINT_NIRVANA );
if ( is_object( $wgRequest ) ) {
Transaction::setAttribute( Transaction::PARAM_CONTROLLER, $wgRequest->getVal( 'controller' ) );
Transaction::setAttribute( Transaction::PARAM_METHOD, $wgRequest->getVal( 'method' ) );
}
if ( function_exists( 'newrelic_disable_autorum' ) ) {
newrelic_disable_autorum();
}
if ( !empty( $wgEnableNirvanaAPI ) ) {
// temporarily force ApiDocs extension regardless of config
require_once $IP . "/extensions/wikia/ApiDocs/ApiDocs.setup.php";
// same for JsonFormat
require_once $IP . "/extensions/wikia/JsonFormat/JsonFormat.setup.php";
$app = F::app();
// Ensure that we have a title stub, otherwise parser does not work BugId: 12901
$app->wg->title = Wikia::createTitleFromRequest( $app->wg->Request );
// support "mcache" URL parameter to ease debugging
Wikia::setUpMemcachePurge( $app->wg->Request, $app->wg->User );
// initialize skin if requested
$app->initSkin( (bool) $app->wg->Request->getVal( "skin", false ) );
$response = $app->sendExternalRequest( null, null, null );
// commit any open transactions just in case the controller forgot to
$app->commit();
// if cache policy wasn't explicitly set (e.g. WikiaResponse::setCacheValidity)
// then force no cache to reflect api.php default behavior
$cacheControl = $response->getHeader( 'Cache-Control' );
if ( empty( $cacheControl ) ) {
$response->setHeader( 'Cache-Control', 'private', true );
Wikia\Logger\WikiaLogger::instance()->info( 'wikia-php.caching-disabled', [
'controller' => $response->getControllerName(),
'method' => $response->getMethodName()
] );
}
// PLATFORM-1633: decrease the noise in reported transactions
$ex = $response->getException();
if ( $ex instanceof ControllerNotFoundException || $ex instanceof MethodNotFoundException ) {
Transaction::setAttribute( Transaction::PARAM_CONTROLLER, 'notFound' );
Transaction::setAttribute( Transaction::PARAM_METHOD, '' );
Wikia\Logger\WikiaLogger::instance()->info( 'wikia-php.not-found', [
'controller' => $response->getControllerName(),
'method' => $response->getMethodName()
] );
}
wfHandleCrossSiteAJAXdomain(); // PLATFORM-1719
$response->sendHeaders();
wfRunHooks( 'NirvanaAfterRespond', [ $app, $response ] );
$response->render();
wfLogProfilingData();
wfRunHooks( 'RestInPeace' );
} else {
header( "HTTP/1.1 503 Service Unavailable", true, 503 );
}