Completed
Push — master ( 14d2bd...06e609 )
by mw
81:37 queued 59:24
created

includes/specials/SMW_SpecialURIResolver.php (1 issue)

Upgrade to new PHP Analysis Engine

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 ) {
27
		global $wgOut;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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