mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CiteThisPage
synced 2024-09-25 03:10:13 +00:00
8145ded3a9
This was done because they needed to be split from one file to two, for efficiency, and it makes sense to have two files in their own directory. It probably makes sense to have each extension in its own directory anyway. Tested both the inefficient backwards compatible interface and the present interface. Still more to be converted...
158 lines
3.5 KiB
PHP
158 lines
3.5 KiB
PHP
<?php
|
|
if (!defined('MEDIAWIKI')) die();
|
|
|
|
global $wgMessageCache, $wgContLang, $wgContLanguageCode;
|
|
|
|
$dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
|
|
$code = $wgContLang->lc( $wgContLanguageCode );
|
|
$file = file_exists( "${dir}cite_text-$code" ) ? "${dir}cite_text-$code" : "${dir}cite_text";
|
|
|
|
$wgMessageCache->addMessages(
|
|
array(
|
|
'cite' => 'Cite',
|
|
'cite_page' => 'Page: ',
|
|
'cite_submit' => 'Cite',
|
|
'cite_text' => file_get_contents( $file )
|
|
)
|
|
);
|
|
|
|
class SpecialCite extends SpecialPage {
|
|
function SpecialCite() {
|
|
SpecialPage::SpecialPage( 'Cite' );
|
|
}
|
|
|
|
function execute( $par ) {
|
|
global $wgOut, $wgRequest, $wgUseTidy;
|
|
|
|
// 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' );
|
|
|
|
$title = Title::newFromText( $page );
|
|
$article = new Article( $title );
|
|
|
|
$cform = new CiteForm( $title );
|
|
|
|
if ( is_null( $title ) || ! $article->exists() )
|
|
$cform->execute();
|
|
else {
|
|
$cform->execute();
|
|
|
|
$cout = new CiteOutput( $title, $article, $id );
|
|
$cout->execute();
|
|
}
|
|
}
|
|
}
|
|
|
|
class CiteForm {
|
|
var $mTitle;
|
|
|
|
function CiteForm( &$title ) {
|
|
$this->mTitle =& $title;
|
|
}
|
|
|
|
function execute() {
|
|
global $wgOut, $wgTitle;
|
|
|
|
$wgOut->addHTML(
|
|
wfElement( 'form',
|
|
array(
|
|
'id' => 'specialcite',
|
|
'method' => 'get',
|
|
'action' => $wgTitle->escapeLocalUrl()
|
|
),
|
|
null
|
|
) .
|
|
wfOpenElement( 'label' ) .
|
|
wfMsgHtml( 'cite_page' ) .
|
|
wfElement( 'input',
|
|
array(
|
|
'type' => 'text',
|
|
'size' => 20,
|
|
'name' => 'page',
|
|
'value' => is_object( $this->mTitle ) ? $this->mTitle->getPrefixedText() : ''
|
|
),
|
|
''
|
|
) .
|
|
' ' .
|
|
wfElement( 'input',
|
|
array(
|
|
'type' => 'submit',
|
|
'value' => wfMsgHtml( 'cite_submit' )
|
|
),
|
|
''
|
|
) .
|
|
wfCloseElement( 'label' ) .
|
|
wfCloseElement( 'form' )
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
class CiteOutput {
|
|
var $mTitle, $mArticle, $mId;
|
|
var $mParser, $mParserOptions;
|
|
|
|
function CiteOutput( &$title, &$article, $id ) {
|
|
global $wgHooks, $wgParser;
|
|
|
|
$this->mTitle =& $title;
|
|
$this->mArticle =& $article;
|
|
$this->mId = $id;
|
|
|
|
$wgHooks['ParserGetVariableValueVarCache'][] = array( $this, 'varCache' );
|
|
|
|
$this->genParserOptions();
|
|
$this->genParser();
|
|
|
|
$wgParser->setHook( 'citation', array( $this, 'CiteParse' ) );
|
|
}
|
|
|
|
function execute() {
|
|
global $wgOut, $wgUser, $wgParser, $wgHooks;
|
|
|
|
$wgHooks['ParserGetVariableValueTs'][] = array( $this, 'timestamp' );
|
|
|
|
$msg = wfMsgForContentNoTrans( 'cite_text' );
|
|
$this->mArticle->fetchContent( $this->mId, false );
|
|
$ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->mArticle->getRevIdFetched() );
|
|
$wgOut->addHtml( $ret->getText() );
|
|
}
|
|
|
|
function genParserOptions() {
|
|
$this->mParserOptions = ParserOptions::newFromUser( $wgUser );
|
|
$this->mParserOptions->setDateFormat( MW_DATE_DEFAULT );
|
|
$this->mParserOptions->setEditSection( false );
|
|
}
|
|
|
|
function genParser() {
|
|
$this->mParser = new Parser;
|
|
}
|
|
|
|
function CiteParse( $in, $argv ) {
|
|
global $wgTitle;
|
|
|
|
$ret = $this->mParser->parse( $in, $wgTitle, $this->mParserOptions, false );
|
|
|
|
return $ret->getText();
|
|
}
|
|
|
|
function varCache() { return false; }
|
|
|
|
function timestamp( &$parser, &$ts ) {
|
|
if ( isset( $parser->mTagHooks['citation'] ) )
|
|
$ts = wfTimestamp( TS_UNIX, $this->mArticle->getTimestamp() );
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
?>
|