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
|
|
|
|
2008-01-09 20:52:38 +00:00
|
|
|
global $wgContLang, $wgContLanguageCode, $wgCiteDefaultText;
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
$dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
|
|
|
|
$code = $wgContLang->lc( $wgContLanguageCode );
|
|
|
|
$file = file_exists( "${dir}cite_text-$code" ) ? "${dir}cite_text-$code" : "${dir}cite_text";
|
2006-07-03 13:11:35 +00:00
|
|
|
$wgCiteDefaultText = file_get_contents( $file );
|
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();
|
|
|
|
|
|
|
|
$page = isset( $par ) ? $par : $wgRequest->getText( 'page' );
|
|
|
|
$id = $wgRequest->getInt( 'id' );
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
$title = Title::newFromText( $page );
|
2008-02-08 09:05:06 +00:00
|
|
|
if ( $title ) {
|
|
|
|
$article = new Article( $title );
|
|
|
|
}
|
2006-06-29 08:07:00 +00:00
|
|
|
$cform = new CiteForm( $title );
|
|
|
|
|
2008-02-08 09:05:06 +00:00
|
|
|
if ( !$title || ! $article->exists() )
|
2006-06-29 08:07:00 +00:00
|
|
|
$cform->execute();
|
|
|
|
else {
|
|
|
|
$cform->execute();
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
$cout = new CiteOutput( $title, $article, $id );
|
|
|
|
$cout->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CiteForm {
|
|
|
|
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 {
|
|
|
|
var $mTitle, $mArticle, $mId;
|
2011-01-12 15:13:06 +00:00
|
|
|
var $mParser, $mParserOptions, $mSpTitle;
|
2006-06-29 08:07:00 +00:00
|
|
|
|
2010-08-30 17:11:45 +00:00
|
|
|
function __construct( &$title, &$article, $id ) {
|
2006-06-29 08:07:00 +00:00
|
|
|
global $wgHooks, $wgParser;
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
$this->mTitle =& $title;
|
|
|
|
$this->mArticle =& $article;
|
|
|
|
$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() {
|
2010-07-24 21:32:07 +00:00
|
|
|
global $wgOut, $wgParser, $wgHooks, $wgCiteDefaultText;
|
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 == '' ) {
|
2006-07-03 13:11:35 +00:00
|
|
|
$msg = $wgCiteDefaultText;
|
|
|
|
}
|
2006-06-29 08:07:00 +00:00
|
|
|
$this->mArticle->fetchContent( $this->mId, false );
|
|
|
|
$ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->mArticle->getRevIdFetched() );
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
function varCache() { return false; }
|
|
|
|
|
|
|
|
function timestamp( &$parser, &$ts ) {
|
|
|
|
if ( isset( $parser->mTagHooks['citation'] ) )
|
|
|
|
$ts = wfTimestamp( TS_UNIX, $this->mArticle->getTimestamp() );
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2006-06-29 08:07:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|