* Support id= for citing a revisison with a given id

* link to title=Special:Cite&page=foo&id=bar in the sidebar rather than Special:Cite/Foo
* Don't gray out the cite link on revision browsing, allows for citing an old revision
* Follow redirects
* Inserting things into the message cache based on the user language is probably going to cause problems
This commit is contained in:
Ævar Arnfjörð Bjarmason 2005-11-28 03:05:00 +00:00
parent e81423104e
commit f3242ae380

View file

@ -26,31 +26,22 @@ $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'wfSpecialCiteNav
$wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfSpecialCiteToolbox'; $wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfSpecialCiteToolbox';
function wfSpecialCite() { function wfSpecialCite() {
global $IP, $wgMessageCache, $wgHooks, $wgLanguageCode; global $IP, $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( $wgMessageCache->addMessages(
array( array(
'cite' => 'Cite', 'cite' => 'Cite',
'cite_page' => 'Page: ', 'cite_page' => 'Page: ',
'cite_submit' => 'Cite', 'cite_submit' => 'Cite',
'cite_article_link' => 'Cite this article', 'cite_article_link' => 'Cite this article',
'cite_text' => file_get_contents( $file )
) )
); );
# FIXME long lines of code -- Hashar
# Do we have a translated text for the current language ?
if($wgLanguageCode && file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'cite_text'. '-' . strtolower($wgLanguageCode) ) ) {
$wgMessageCache->addMessages(
array( 'cite_text' => file_get_contents( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'cite_text' . '-' . strtolower($wgLanguageCode) ) )
);
} else {
# Add default text (english)
$wgMessageCache->addMessages(
array( 'cite_text' => file_get_contents( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'cite_text' ) )
);
}
require_once "$IP/includes/SpecialPage.php"; require_once "$IP/includes/SpecialPage.php";
class Cite extends SpecialPage { class Cite extends SpecialPage {
function Cite() { function Cite() {
@ -68,6 +59,7 @@ function wfSpecialCite() {
$this->setHeaders(); $this->setHeaders();
$page = isset( $par ) ? $par : $wgRequest->getText( 'page' ); $page = isset( $par ) ? $par : $wgRequest->getText( 'page' );
$id = $wgRequest->getInt( 'id' );
$title = Title::newFromText( $page ); $title = Title::newFromText( $page );
$article = new Article( $title ); $article = new Article( $title );
@ -79,7 +71,7 @@ function wfSpecialCite() {
else { else {
$cform->execute(); $cform->execute();
$cout = new CiteOutput( $title, $article ); $cout = new CiteOutput( $title, $article, $id );
$cout->execute(); $cout->execute();
} }
} }
@ -131,14 +123,15 @@ function wfSpecialCite() {
} }
class CiteOutput { class CiteOutput {
var $mTitle, $mArticle, $mParserOptions; var $mTitle, $mArticle, $mId;
var $mParser; var $mParser, $mParserOptions;
function CiteOutput( &$title, &$article ) { function CiteOutput( &$title, &$article, $id ) {
global $wgHooks, $wgParser; global $wgHooks, $wgParser;
$this->mTitle =& $title; $this->mTitle =& $title;
$this->mArticle =& $article; $this->mArticle =& $article;
$this->mId = $id;
$wgHooks['ParserGetVariableValueVarCache'][] = array( $this, 'varCache' ); $wgHooks['ParserGetVariableValueVarCache'][] = array( $this, 'varCache' );
@ -154,7 +147,7 @@ function wfSpecialCite() {
$wgHooks['ParserGetVariableValueTs'][] = array( $this, 'timestamp' ); $wgHooks['ParserGetVariableValueTs'][] = array( $this, 'timestamp' );
$msg = wfMsgForContentNoTrans( 'cite_text' ); $msg = wfMsgForContentNoTrans( 'cite_text' );
$this->mArticle->fetchContent(); $this->mArticle->fetchContent( $this->mId, false );
$ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->mArticle->getRevIdFetched() ); $ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->mArticle->getRevIdFetched() );
$wgOut->addHtml( $ret->getText() ); $wgOut->addHtml( $ret->getText() );
} }
@ -191,19 +184,12 @@ function wfSpecialCite() {
} }
function wfSpecialCiteNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) { function wfSpecialCiteNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) {
if ( $skintemplate->mTitle->getNamespace() === NS_MAIN ) { if ( $skintemplate->mTitle->getNamespace() === NS_MAIN && $revid !== 0 )
if ( (int)$oldid ) $nav_urls['cite'] = array(
$nav_urls['cite'] = array( 'text' => wfMsg( 'cite_article_link' ),
'text' => wfMsg( 'cite_article_link' ), 'href' => $skintemplate->makeSpecialUrl( 'Cite', "page=" . wfUrlencode( "{$skintemplate->thispage}" ) . "&id=$revid" )
'href' => '' );
);
else if ( $revid !== 0 )
$nav_urls['cite'] = array(
'text' => wfMsg( 'cite_article_link' ),
'href' => $skintemplate->makeSpecialUrl( 'Cite/' . $skintemplate->thispage )
);
}
return true; return true;
} }
@ -212,12 +198,11 @@ function wfSpecialCiteToolbox( &$monobook ) {
if ( $monobook->data['nav_urls']['cite']['href'] == '' ) { if ( $monobook->data['nav_urls']['cite']['href'] == '' ) {
?><li id="t-iscite"><?php echo $monobook->msg( 'cite_article_link' ); ?></li><?php ?><li id="t-iscite"><?php echo $monobook->msg( 'cite_article_link' ); ?></li><?php
} else { } else {
?><li id="t-cite"> ?><li id="t-cite"><?php
<a href="<?php echo htmlspecialchars( $monobook->data['nav_urls']['cite']['href'] ) ?>"> ?><a href="<?php echo htmlspecialchars( $monobook->data['nav_urls']['cite']['href'] ) ?>"><?php
<?php echo $monobook->msg( 'cite_article_link' ); ?> echo $monobook->msg( 'cite_article_link' );
</a> ?></a><?php
</li> ?></li><?php
<?php
} }
return true; return true;