FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
admin/src/App.php at master · toolforge/admin · GitHub
toolforge
/
admin
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Actions
Security and quality
0
Insights
Additional navigation options
Code
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
admin
/
src
/
App.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
216 lines (190 loc) · 6.2 KB
Breadcrumbs
admin
/
src
/
App.php
Copy path
File metadata and controls
216 lines (190 loc) · 6.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
* This file is part of Toolforge Admin
* Copyright (C) 2016 Wikimedia Foundation and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace
Tools
\
Admin
;
use
Wikimedia
\
SimpleI18n
\
I18nContext
;
use
Wikimedia
\
SimpleI18n
\
JsonCache
;
use
Wikimedia
\
Slimapp
\
AbstractApp
;
use
Wikimedia
\
Slimapp
\
Config
;
class
App
extends
AbstractApp {
/**
* Apply settings to the Slim application.
*
* @param \Slim\Slim $slim Application
*/
protected
function
configureSlim
(
\
Slim
\
Slim
$
slim
) {
$
slim
->
configureMode
(
'
production
'
,
static
function
()
use
(
$
slim
) {
$
slim
->
config
( [
'
debug
'
=>
false
,
'
log.level
'
=> Config::
getStr
(
'
LOG_LEVEL
'
,
'
INFO
'
),
] );
// Install a custom error handler
$
slim
->
error
(
static
function
(
\
Exception
$
e
)
use
(
$
slim
) {
$
errorId
=
substr
(
session_id
(),
0
,
8
) .
'
-
'
.
substr
(
uniqid
(), -
8
);
$
slim
->
log
->
critical
(
$
e
->
getMessage
(), [
'
exception
'
=>
$
e
,
'
errorId
'
=>
$
errorId
,
] );
$
slim
->
view
->
set
(
'
errorId
'
,
$
errorId
);
$
slim
->
render
(
'
error.html
'
);
} );
} );
$
slim
->
configureMode
(
'
development
'
,
static
function
()
use
(
$
slim
) {
$
slim
->
config
( [
'
debug
'
=>
true
,
'
log.level
'
=> Config::
getStr
(
'
LOG_LEVEL
'
,
'
DEBUG
'
),
'
view.cache
'
=>
false
,
] );
} );
}
/**
* Configure inversion of control/dependency injection container.
*
* @param \Slim\Helper\Set $container IOC container
*/
protected
function
configureIoc
(
\
Slim
\
Helper
\
Set
$
container
) {
$
container
->
singleton
(
'
i18nCache
'
,
static
function
(
$
c
) {
return
new
JsonCache
(
$
c
->
settings
[
'
i18n.path
'
],
$
c
->
log
);
} );
$
container
->
singleton
(
'
i18nContext
'
,
static
function
(
$
c
) {
return
new
I18nContext
(
$
c
->
i18nCache
,
$
c
->
settings
[
'
i18n.default
'
],
$
c
->
log
);
} );
}
/**
* Configure view behavior.
*
* @param \Slim\View $view Default view
*/
protected
function
configureView
(
\
Slim
\
View
$
view
) {
$
view
->
parserOptions
= [
'
charset
'
=>
'
utf-8
'
,
'
cache
'
=>
$
this
->
slim
->
config
(
'
view.cache
'
),
'
debug
'
=>
$
this
->
slim
->
config
(
'
debug
'
),
'
auto_reload
'
=>
true
,
'
strict_variables
'
=>
false
,
'
autoescape
'
=>
true
,
];
// Install twig parser extensions
$
view
->
parserExtensions
= [
new
\
Slim
\
Views
\
TwigExtension
(),
new
\
Wikimedia
\
SimpleI18n
\
TwigExtension
(
$
this
->
slim
->
i18nContext
),
new
\
Twig_Extension_Debug
(),
];
// Set default view data
$
view
->
replace
( [
'
app
'
=>
$
this
->
slim
,
'
i18nCtx
'
=>
$
this
->
slim
->
i18nContext
,
] );
}
/**
* @inheritDoc
*/
protected
function
configureHeaderMiddleware
() {
$
headers
=
parent
::
configureHeaderMiddleware
();
$
headers
[
'
Content-Security-Policy
'
] =
"
default-src 'self' https://tools-static.wmflabs.org;
"
.
"
child-src 'none';
"
.
"
object-src 'none';
"
.
"
img-src 'self' data: https://tools-static.wmflabs.org
"
;
return
$
headers
;
}
/**
* Configure routes to be handled by application.
*
* @param \Slim\Slim $slim Application
*/
protected
function
configureRoutes
(
\
Slim
\
Slim
$
slim
) {
$
slim
->
hook
(
'
slim.before.router
'
,
static
function
()
use
(
$
slim
) {
$
env
=
$
slim
->
environment
;
$
path
=
$
env
[
'
PATH_INFO
'
];
$
qs
=
$
env
[
'
QUERY_STRING
'
];
if
(
substr
(
$
path
,
0
,
2
) ===
'
/.
'
) {
// Treat /. as /? by moving path data into query string. This
// may be legacy legacy behavior. Documented previously as
// being used for error_document handling where query strings
// were not allowed in the webserver/proxy config.
$
qs
=
substr
(
$
path
,
2
);
$
path
=
'
/
'
;
}
if
(
$
path
===
'
/
'
&&
$
qs
!==
''
) {
// Map query string routes into path based routes.
$
parts
=
explode
(
'
=
'
,
$
qs
,
2
);
if
(
$
parts
[
0
] ===
'
list
'
) {
$
path
.=
'
tools
'
;
}
elseif
(
in_array
(
$
parts
[
0
], [
'
403
'
,
'
404
'
,
'
500
'
,
'
503
'
] ) ) {
$
path
.=
"
error/
{
$
parts
[
0
]}"
;
}
elseif
(
$
parts
[
0
] ===
'
tool
'
&&
count
(
$
parts
) ===
2
) {
$
path
.=
"
tool/
{
$
parts
[
1
]}"
;
}
elseif
(
preg_match
(
'
/^[A-Z]/
'
,
$
parts
[
0
] ) ) {
$
path
.=
"
wiki/
{
$
parts
[
0
]}"
;
}
else
{
$
slim
->
log
->
info
(
'
Unhandled query string: {qs}
'
, [
'
qs
'
=>
$
qs
,
] );
}
$
qs
=
''
;
}
$
env
[
'
PATH_INFO
'
] =
$
path
;
$
env
[
'
QUERY_STRING
'
] =
$
qs
;
// Clear Slim\Http\Request's internal query string cache
unset(
$
env
[
'
slim.request.query_hash
'
] );
},
0
);
$
slim
->
group
(
'
/
'
,
static
function
()
use
(
$
slim
) {
$
slim
->
get
(
''
,
static
function
()
use
(
$
slim
) {
$
slim
->
render
(
'
splash.html
'
);
} )->
name
(
'
splash
'
);
$
slim
->
get
(
'
error/:errorCode
'
,
static
function
(
$
errorCode
)
use
(
$
slim
) {
$
page
=
new
Pages
\
Error
(
$
slim
);
$
page
->
setI18nContext
(
$
slim
->
i18nContext
);
$
page
(
$
errorCode
);
} )->
name
(
'
error
'
);
$
slim
->
get
(
'
favicon.ico
'
,
static
function
()
use
(
$
slim
) {
$
slim
->
redirect
(
'
https://tools-static.wmflabs.org/toolforge/favicons/favicon.ico
'
,
301
);
} )->
name
(
'
favicon
'
);
$
slim
->
get
(
'
tools
'
,
static
function
()
use
(
$
slim
) {
$
page
=
new
Pages
\
Redirect
(
$
slim
);
$
page
->
setBaseUrl
(
'
https://toolhub.wikimedia.org/
'
);
$
page
(
''
);
} )->
name
(
'
tools
'
);
$
slim
->
get
(
'
tool/:name
'
,
static
function
(
$
name
)
use
(
$
slim
) {
$
page
=
new
Pages
\
Redirect
(
$
slim
);
$
page
->
setBaseUrl
(
'
https://toolsadmin.wikimedia.org/tools/id/
'
);
$
page
(
$
name
);
} )->
name
(
'
tool
'
);
$
slim
->
get
(
'
healthz
'
,
static
function
()
use
(
$
slim
) {
$
page
=
new
Pages
\
Healthz
();
$
page
();
} )->
name
(
'
healthz
'
);
}
);
// end group '/'
$
slim
->
notFound
(
static
function
()
use
(
$
slim
) {
$
page
=
new
Pages
\
Error
(
$
slim
);
$
page
->
setI18nContext
(
$
slim
->
i18nContext
);
$
page
(
'
404
'
,
true
);
} );
}
}
Back
|
FazBrowse Home
|
New Git URL