summaryrefslogtreecommitdiff
path: root/includes/SpecialFilepath.php
blob: 4ba8fdb032c264522145a8118cc2b28c2ee5a030 (plain)
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
<?php

function wfSpecialFilepath( $par ) {
	global $wgRequest, $wgOut;

	$file = isset( $par ) ? $par : $wgRequest->getText( 'file' );

	$title = Title::newFromText( $file, NS_IMAGE );

	if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) {
		$cform = new FilepathForm( $title );
		$cform->execute();
	} else {
		$file = wfFindFile( $title );
		if ( $file && $file->exists() ) {
			$wgOut->redirect( $file->getURL() );
		} else {
			$wgOut->setStatusCode( 404 );
			$cform = new FilepathForm( $title );
			$cform->execute();
		}
	}
}

class FilepathForm {
	var $mTitle;

	function FilepathForm( &$title ) {
		$this->mTitle =& $title;
	}

	function execute() {
		global $wgOut, $wgTitle, $wgScript;

		$wgOut->addHTML(
			wfElement( 'form',
				array(
					'id' => 'specialfilepath',
					'method' => 'get',
					'action' => $wgScript,
				),
				null
			) .
				wfHidden( 'title', $wgTitle->getPrefixedText() ) .
				wfOpenElement( 'label' ) .
					wfMsgHtml( 'filepath-page' ) .
					' ' .
					wfElement( 'input',
						array(
							'type' => 'text',
							'size' => 25,
							'name' => 'file',
							'value' => is_object( $this->mTitle ) ? $this->mTitle->getText() : ''
						),
						''
					) .
					' ' .
					wfElement( 'input',
						array(
							'type' => 'submit',
							'value' => wfMsgHtml( 'filepath-submit' )
						),
						''
					) .
				wfCloseElement( 'label' ) .
			wfCloseElement( 'form' )
		);
	}
}