Index: trunk/extensions/Filepath/SpecialFilepath.php |
— | — | @@ -0,0 +1,102 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI')) die(); |
| 4 | +/** |
| 5 | + * @package MediaWiki |
| 6 | + * @subpackage Extensions |
| 7 | + * |
| 8 | + * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 9 | + * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason |
| 10 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 11 | + */ |
| 12 | + |
| 13 | +$wgExtensionFunctions[] = 'wfSpecialFilepath'; |
| 14 | +$wgExtensionCredits['specialpage'][] = array( |
| 15 | + 'name' => 'Filepath', |
| 16 | + 'author' => 'Ævar Arnfjörð Bjarmason', |
| 17 | + 'description' => '[[Special:Filepath|a special page]] to get the full path of a file from its name', |
| 18 | + 'url' => 'http://meta.wikimedia.org/wiki/Filepath' |
| 19 | +); |
| 20 | + |
| 21 | +function wfSpecialFilepath() { |
| 22 | + global $IP, $wgMessageCache; |
| 23 | + |
| 24 | + $wgMessageCache->addMessages( |
| 25 | + array( |
| 26 | + 'filepath' => 'File path', |
| 27 | + 'filepath_page' => 'File: ', |
| 28 | + 'filepath_submit' => 'Path', |
| 29 | + ) |
| 30 | + ); |
| 31 | + |
| 32 | + require_once "$IP/includes/SpecialPage.php"; |
| 33 | + class SpecialFilepath extends SpecialPage { |
| 34 | + function SpecialFilepath() { |
| 35 | + SpecialPage::SpecialPage( 'Filepath' ); |
| 36 | + } |
| 37 | + |
| 38 | + function execute( $par ) { |
| 39 | + global $wgRequest, $wgOut; |
| 40 | + |
| 41 | + $file = isset( $par ) ? $par : $wgRequest->getText( 'file' ); |
| 42 | + |
| 43 | + $title = Title::makeTitleSafe( NS_IMAGE, $file ); |
| 44 | + $article = new Article( $title ); |
| 45 | + |
| 46 | + if ( is_null( $title ) || ! $article->exists() ) { |
| 47 | + $this->setHeaders(); |
| 48 | + $cform = new FilepathForm( $title ); |
| 49 | + $cform->execute(); |
| 50 | + } else { |
| 51 | + $file = new Image( $title ); |
| 52 | + $wgOut->redirect( $file->getURL() ); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + class FilepathForm { |
| 58 | + var $mTitle; |
| 59 | + |
| 60 | + function FilepathForm( &$title ) { |
| 61 | + $this->mTitle =& $title; |
| 62 | + } |
| 63 | + |
| 64 | + function execute() { |
| 65 | + global $wgOut, $wgTitle; |
| 66 | + |
| 67 | + $wgOut->addHTML( |
| 68 | + wfElement( 'form', |
| 69 | + array( |
| 70 | + 'id' => 'specialfilepath', |
| 71 | + 'method' => 'get', |
| 72 | + 'action' => $wgTitle->escapeLocalUrl() |
| 73 | + ), |
| 74 | + null |
| 75 | + ) . |
| 76 | + wfOpenElement( 'label' ) . |
| 77 | + wfMsgHtml( 'filepath_page' ) . |
| 78 | + wfElement( 'input', |
| 79 | + array( |
| 80 | + 'type' => 'text', |
| 81 | + 'size' => 25, |
| 82 | + 'name' => 'file', |
| 83 | + 'value' => is_object( $this->mTitle ) ? $this->mTitle->getText() : '' |
| 84 | + ), |
| 85 | + '' |
| 86 | + ) . |
| 87 | + ' ' . |
| 88 | + wfElement( 'input', |
| 89 | + array( |
| 90 | + 'type' => 'submit', |
| 91 | + 'value' => wfMsgHtml( 'filepath_submit' ) |
| 92 | + ), |
| 93 | + '' |
| 94 | + ) . |
| 95 | + wfCloseElement( 'label' ) . |
| 96 | + wfCloseElement( 'form' ) |
| 97 | + ); |
| 98 | + } |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + SpecialPage::addPage( new SpecialFilepath ); |
| 103 | +} |
Property changes on: trunk/extensions/Filepath/SpecialFilepath.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 104 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 105 | + native |