These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use SMW\Exporter\Escaper; |
||
4 | |||
5 | /** |
||
6 | * This special page solves the URI crisis |
||
7 | * without the need of changing code deep in |
||
8 | * MediaWiki were no hook has ever seen light. |
||
9 | * |
||
10 | * @ingroup SpecialPage |
||
11 | * |
||
12 | * @ingroup SMWSpecialPage |
||
13 | * @ingroup SpecialPage |
||
14 | * |
||
15 | * @author Denny Vrandecic |
||
16 | */ |
||
17 | class SMWURIResolver extends SpecialPage { |
||
18 | |||
19 | /** |
||
20 | * Constructor |
||
21 | */ |
||
22 | public function __construct() { |
||
23 | parent::__construct( 'URIResolver', '', false ); |
||
24 | } |
||
25 | |||
26 | function execute( $query ) { |
||
0 ignored issues
–
show
execute uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
Loading history...
|
|||
27 | global $wgOut; |
||
28 | |||
29 | |||
30 | if ( is_null( $query ) || trim( $query ) === '' ) { |
||
31 | if ( stristr( $_SERVER['HTTP_ACCEPT'], 'RDF' ) ) { |
||
32 | $wgOut->redirect( SpecialPage::getTitleFor( 'ExportRDF' )->getFullURL( array( 'stats' => '1' ) ), '303' ); |
||
33 | } else { |
||
34 | $this->setHeaders(); |
||
35 | $wgOut->addHTML( |
||
36 | '<p>' . |
||
37 | wfMessage( 'smw_uri_doc', 'http://www.w3.org/2001/tag/issues.html#httpRange-14' )->parse() . |
||
38 | '</p>' |
||
39 | ); |
||
40 | } |
||
41 | } else { |
||
42 | $query = Escaper::decodeUri( $query ); |
||
43 | $query = str_replace( '_', '%20', $query ); |
||
44 | $query = urldecode( $query ); |
||
45 | $title = Title::newFromText( $query ); |
||
46 | |||
47 | // In case the title doesn't exists throw an error page |
||
48 | if ( $title === null ) { |
||
49 | $wgOut->showErrorPage( 'badtitle', 'badtitletext' ); |
||
50 | } else { |
||
51 | $wgOut->redirect( stristr( $_SERVER['HTTP_ACCEPT'], 'RDF' ) |
||
52 | ? SpecialPage::getTitleFor( 'ExportRDF', $title->getPrefixedText() )->getFullURL( array( 'xmlmime' => 'rdf' ) ) |
||
53 | : $title->getFullURL(), '303' ); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | } |
||
58 | } |
||
59 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.