2006-06-29 08:07:00 +00:00
|
|
|
<?php
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) die();
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
class SpecialCite extends SpecialPage {
|
2010-08-30 17:11:45 +00:00
|
|
|
function __construct() {
|
2010-08-30 17:18:13 +00:00
|
|
|
parent::__construct( 'Cite' );
|
2006-06-29 08:07:00 +00:00
|
|
|
}
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
function execute( $par ) {
|
2010-07-24 21:12:27 +00:00
|
|
|
global $wgRequest, $wgUseTidy;
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
// Having tidy on causes whitespace and <pre> tags to
|
|
|
|
// be generated around the output of the CiteOutput
|
|
|
|
// class TODO FIXME.
|
|
|
|
$wgUseTidy = false;
|
|
|
|
|
|
|
|
$this->setHeaders();
|
|
|
|
$this->outputHeader();
|
|
|
|
|
2011-11-13 14:22:24 +00:00
|
|
|
$page = $par !== null ? $par : $wgRequest->getText( 'page' );
|
2006-06-29 08:07:00 +00:00
|
|
|
$title = Title::newFromText( $page );
|
|
|
|
|
2011-11-13 14:22:24 +00:00
|
|
|
$cform = new CiteForm( $title );
|
|
|
|
$cform->execute();
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2011-11-13 14:22:24 +00:00
|
|
|
if ( $title && $title->exists() ) {
|
|
|
|
$id = $wgRequest->getInt( 'id' );
|
|
|
|
$cout = new CiteOutput( $title, $id );
|
2006-06-29 08:07:00 +00:00
|
|
|
$cout->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CiteForm {
|
2011-05-28 20:44:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Title
|
|
|
|
*/
|
2006-06-29 08:07:00 +00:00
|
|
|
var $mTitle;
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2010-08-30 17:11:45 +00:00
|
|
|
function __construct( &$title ) {
|
2006-06-29 08:07:00 +00:00
|
|
|
$this->mTitle =& $title;
|
|
|
|
}
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
function execute() {
|
2011-01-12 15:13:06 +00:00
|
|
|
global $wgOut, $wgScript;
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
$wgOut->addHTML(
|
2011-01-12 15:13:06 +00:00
|
|
|
Xml::openElement( 'form',
|
2006-06-29 08:07:00 +00:00
|
|
|
array(
|
|
|
|
'id' => 'specialcite',
|
|
|
|
'method' => 'get',
|
2011-01-12 15:13:06 +00:00
|
|
|
'action' => $wgScript
|
|
|
|
) ) .
|
|
|
|
Html::hidden( 'title', SpecialPage::getTitleFor( 'Cite' )->getPrefixedDBkey() ) .
|
2008-12-20 09:32:47 +00:00
|
|
|
Xml::openElement( 'label' ) .
|
2006-07-03 13:11:35 +00:00
|
|
|
wfMsgHtml( 'cite_page' ) . ' ' .
|
2008-12-20 09:32:47 +00:00
|
|
|
Xml::element( 'input',
|
2006-06-29 08:07:00 +00:00
|
|
|
array(
|
|
|
|
'type' => 'text',
|
2008-05-01 12:48:22 +00:00
|
|
|
'size' => 30,
|
2006-06-29 08:07:00 +00:00
|
|
|
'name' => 'page',
|
|
|
|
'value' => is_object( $this->mTitle ) ? $this->mTitle->getPrefixedText() : ''
|
|
|
|
),
|
|
|
|
''
|
|
|
|
) .
|
|
|
|
' ' .
|
2008-12-20 09:32:47 +00:00
|
|
|
Xml::element( 'input',
|
2006-06-29 08:07:00 +00:00
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'value' => wfMsgHtml( 'cite_submit' )
|
|
|
|
),
|
|
|
|
''
|
|
|
|
) .
|
2008-12-20 09:32:47 +00:00
|
|
|
Xml::closeElement( 'label' ) .
|
|
|
|
Xml::closeElement( 'form' )
|
2006-06-29 08:07:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class CiteOutput {
|
2011-05-28 20:44:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Title
|
|
|
|
*/
|
|
|
|
var $mTitle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Article
|
|
|
|
*/
|
|
|
|
var $mArticle;
|
|
|
|
|
|
|
|
var $mId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Parser
|
|
|
|
*/
|
|
|
|
var $mParser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ParserOptions
|
|
|
|
*/
|
|
|
|
var $mParserOptions;
|
|
|
|
|
|
|
|
var $mSpTitle;
|
2006-06-29 08:07:00 +00:00
|
|
|
|
2011-11-13 14:22:24 +00:00
|
|
|
function __construct( $title, $id ) {
|
2006-06-29 08:07:00 +00:00
|
|
|
global $wgHooks, $wgParser;
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2011-11-13 14:22:24 +00:00
|
|
|
$this->mTitle = $title;
|
|
|
|
$this->mArticle = new Article( $title );
|
2006-06-29 08:07:00 +00:00
|
|
|
$this->mId = $id;
|
|
|
|
|
|
|
|
$wgHooks['ParserGetVariableValueVarCache'][] = array( $this, 'varCache' );
|
|
|
|
|
|
|
|
$this->genParserOptions();
|
|
|
|
$this->genParser();
|
|
|
|
|
|
|
|
$wgParser->setHook( 'citation', array( $this, 'CiteParse' ) );
|
|
|
|
}
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
function execute() {
|
2012-04-26 10:13:54 +00:00
|
|
|
global $wgOut, $wgParser, $wgHooks;
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
$wgHooks['ParserGetVariableValueTs'][] = array( $this, 'timestamp' );
|
|
|
|
|
|
|
|
$msg = wfMsgForContentNoTrans( 'cite_text' );
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $msg == '' ) {
|
2012-04-26 10:13:54 +00:00
|
|
|
# With MediaWiki 1.20 the plain text files were deleted and the text moved into SpecialCite.i18n.php
|
|
|
|
# This code is kept for b/c in case an installation has its own file "cite_text-xx"
|
|
|
|
# for a previously not supported language.
|
|
|
|
global $wgContLang, $wgContLanguageCode;
|
|
|
|
$dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
|
|
|
|
$code = $wgContLang->lc( $wgContLanguageCode );
|
|
|
|
if ( file_exists( "${dir}cite_text-$code" ) ) {
|
|
|
|
$msg = file_get_contents( "${dir}cite_text-$code" );
|
|
|
|
} elseif( file_exists( "${dir}cite_text" ) ){
|
|
|
|
$msg = file_get_contents( "${dir}cite_text" );
|
|
|
|
}
|
2006-07-03 13:11:35 +00:00
|
|
|
}
|
2011-11-13 14:22:24 +00:00
|
|
|
$ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->getRevId() );
|
2012-04-26 10:13:54 +00:00
|
|
|
$wgOut->addModules( 'ext.specialcite' );
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( $ret->getText() );
|
2006-06-29 08:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function genParserOptions() {
|
2006-07-13 17:18:50 +00:00
|
|
|
global $wgUser;
|
2006-06-29 08:07:00 +00:00
|
|
|
$this->mParserOptions = ParserOptions::newFromUser( $wgUser );
|
|
|
|
$this->mParserOptions->setDateFormat( MW_DATE_DEFAULT );
|
|
|
|
$this->mParserOptions->setEditSection( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
function genParser() {
|
|
|
|
$this->mParser = new Parser;
|
2011-01-12 15:13:06 +00:00
|
|
|
$this->mSpTitle = SpecialPage::getTitleFor( 'Cite' );
|
2006-06-29 08:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CiteParse( $in, $argv ) {
|
2011-01-12 15:13:06 +00:00
|
|
|
$ret = $this->mParser->parse( $in, $this->mSpTitle, $this->mParserOptions, false );
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
return $ret->getText();
|
|
|
|
}
|
|
|
|
|
2011-05-28 20:44:24 +00:00
|
|
|
function varCache() {
|
|
|
|
return false;
|
|
|
|
}
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
function timestamp( &$parser, &$ts ) {
|
2011-05-28 20:44:24 +00:00
|
|
|
if ( isset( $parser->mTagHooks['citation'] ) ) {
|
2006-06-29 08:07:00 +00:00
|
|
|
$ts = wfTimestamp( TS_UNIX, $this->mArticle->getTimestamp() );
|
2011-05-28 20:44:24 +00:00
|
|
|
}
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-11-13 14:22:24 +00:00
|
|
|
|
|
|
|
function getRevId() {
|
|
|
|
if ( $this->mId ) {
|
|
|
|
return $this->mId;
|
|
|
|
} else {
|
|
|
|
return $this->mTitle->getLatestRevID();
|
|
|
|
}
|
|
|
|
}
|
2006-06-29 08:07:00 +00:00
|
|
|
}
|