2005-11-26 23:22:24 +00:00
|
|
|
<?php
|
|
|
|
if (!defined('MEDIAWIKI')) die();
|
|
|
|
/**
|
|
|
|
* A special page extension that adds a special page that generates citations
|
|
|
|
* for pages.
|
|
|
|
*
|
|
|
|
* @package MediaWiki
|
|
|
|
* @subpackage Extensions
|
|
|
|
*
|
|
|
|
* @link http://meta.wikimedia.org/wiki/Help:Cite Documentation
|
|
|
|
*
|
|
|
|
* @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
|
|
|
|
* @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
$wgExtensionFunctions[] = 'wfSpecialCite';
|
|
|
|
$wgExtensionCredits['specialpage'][] = array(
|
|
|
|
'name' => 'Cite',
|
|
|
|
'author' => 'Ævar Arnfjörð Bjarmason',
|
|
|
|
'description' => 'adds a [[Special:Cite|citation]] special page & toolbox link',
|
|
|
|
'url' => 'http://meta.wikimedia.org/wiki/Help:Cite'
|
|
|
|
);
|
|
|
|
|
|
|
|
$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'wfSpecialCiteNav';
|
|
|
|
$wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfSpecialCiteToolbox';
|
|
|
|
|
|
|
|
function wfSpecialCite() {
|
|
|
|
global $IP, $wgMessageCache, $wgHooks;
|
|
|
|
|
|
|
|
$wgMessageCache->addMessages(
|
|
|
|
array(
|
|
|
|
'cite' => 'Cite',
|
|
|
|
'cite_page' => 'Page: ',
|
|
|
|
'cite_submit' => 'Cite',
|
2005-11-27 02:55:12 +00:00
|
|
|
'cite_article_link' => 'Cite this article',
|
2005-11-26 23:22:24 +00:00
|
|
|
'cite_text' =>
|
|
|
|
"* ''{{FULLPAGENAME}}'' (last modified {{CURRENTTIME}}," .
|
|
|
|
' {{CURRENTDAY}} {{CURRENTMONTHNAME}} {{CURRENTYEAR}} UTC).' .
|
|
|
|
' {{SITENAME}}, {{int:sitesubtitle}}. Retrived <cite>{{CURRENTTIME}},' .
|
|
|
|
' {{CURRENTDAY}} {{CURRENTMONTHNAME}} {{CURRENTYEAR}}</cite> from' .
|
|
|
|
' {{fullurl:{{FULLPAGENAME}}|oldid={{REVISIONID}}}}'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
require_once "$IP/includes/SpecialPage.php";
|
|
|
|
class Cite extends SpecialPage {
|
|
|
|
function Cite() {
|
|
|
|
SpecialPage::SpecialPage( 'Cite' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function execute( $par ) {
|
2005-11-27 02:55:12 +00:00
|
|
|
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;
|
2005-11-26 23:22:24 +00:00
|
|
|
|
|
|
|
$this->setHeaders();
|
|
|
|
|
|
|
|
$page = isset( $par ) ? $par : $wgRequest->getText( 'page' );
|
|
|
|
|
|
|
|
$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 );
|
|
|
|
$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 {
|
2005-11-27 00:02:21 +00:00
|
|
|
var $mTitle, $mArticle, $mParserOptions;
|
2005-11-26 23:22:24 +00:00
|
|
|
var $mParser;
|
|
|
|
|
|
|
|
function CiteOutput( $title, $article ) {
|
|
|
|
global $wgHooks, $wgParser;
|
|
|
|
|
|
|
|
$this->mTitle =& $title;
|
|
|
|
$this->mArticle =& $article;
|
|
|
|
|
|
|
|
$wgHooks['ParserGetVariableValueRevid'][] = array( $this, 'revid' );
|
|
|
|
$wgHooks['ParserGetVariableValueVarCache'][] = array( $this, 'varCache' );
|
|
|
|
|
|
|
|
$this->genParserOptions();
|
|
|
|
$this->genParser();
|
|
|
|
|
2005-11-27 02:55:12 +00:00
|
|
|
$wgParser->setHook( 'cite', array( $this, 'CiteParse' ) );
|
2005-11-26 23:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function execute() {
|
|
|
|
global $wgOut, $wgUser, $wgParser, $wgHooks;
|
|
|
|
|
|
|
|
$wgHooks['ParserGetVariableValueTs'][] = array( $this, 'timestamp' );
|
|
|
|
|
2005-11-27 00:02:21 +00:00
|
|
|
$msg = wfMsgForContentNoTrans( 'cite_text' );
|
|
|
|
$ret = $wgParser->parse( $msg, &$this->mTitle, $this->mParserOptions );
|
2005-11-26 23:22:24 +00:00
|
|
|
$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['cite'] ) )
|
|
|
|
$ts = wfTimestamp( TS_UNIX, $this->mArticle->getTimestamp() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function revid( &$parser, &$revid ) {
|
|
|
|
$this->mArticle->fetchContent();
|
|
|
|
$revid = $this->mArticle->getRevIdFetched();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpecialPage::addPage( new Cite );
|
|
|
|
}
|
|
|
|
|
|
|
|
function wfSpecialCiteNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) {
|
2005-11-27 02:55:12 +00:00
|
|
|
if ( $skintemplate->mTitle->getNamespace() === NS_MAIN ) {
|
|
|
|
if ( (int)$oldid )
|
|
|
|
$nav_urls['cite'] = array(
|
|
|
|
'text' => wfMsg( 'cite_article_link' ),
|
|
|
|
'href' => ''
|
|
|
|
);
|
|
|
|
else if ( $revid !== 0 )
|
|
|
|
$nav_urls['cite'] = array(
|
|
|
|
'text' => wfMsg( 'cite_article_link' ),
|
|
|
|
'href' => $skintemplate->makeSpecialUrl( 'Cite/' . $skintemplate->thispage )
|
|
|
|
);
|
|
|
|
}
|
2005-11-26 23:22:24 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function wfSpecialCiteToolbox( &$monobook ) {
|
|
|
|
if ( isset( $monobook->data['nav_urls']['cite'] ) )
|
|
|
|
if ( $monobook->data['nav_urls']['cite']['href'] == '' ) {
|
2005-11-27 02:55:12 +00:00
|
|
|
?><li id="t-iscite"><?php echo $monobook->msg( 'cite_article_link' ); ?></li><?php
|
2005-11-26 23:22:24 +00:00
|
|
|
} else {
|
|
|
|
?><li id="t-cite">
|
|
|
|
<a href="<?php echo htmlspecialchars( $monobook->data['nav_urls']['cite']['href'] ) ?>">
|
2005-11-27 02:55:12 +00:00
|
|
|
<?php echo $monobook->msg( 'cite_article_link' ); ?>
|
2005-11-26 23:22:24 +00:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|