2006-06-29 08:07:00 +00:00
|
|
|
<?php
|
|
|
|
|
2014-07-26 21:44:55 +00:00
|
|
|
class SpecialCiteThisPage extends SpecialPage {
|
2014-09-22 16:54:40 +00:00
|
|
|
public function __construct() {
|
2014-07-26 21:44:55 +00:00
|
|
|
parent::__construct( 'CiteThisPage' );
|
2006-06-29 08:07:00 +00:00
|
|
|
}
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2014-09-22 16:54:40 +00:00
|
|
|
public function execute( $par ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
global $wgUseTidy;
|
2006-06-29 08:07:00 +00:00
|
|
|
|
|
|
|
// Having tidy on causes whitespace and <pre> tags to
|
2014-07-26 21:44:55 +00:00
|
|
|
// be generated around the output of the CiteThisPageOutput
|
2006-06-29 08:07:00 +00:00
|
|
|
// class TODO FIXME.
|
|
|
|
$wgUseTidy = false;
|
|
|
|
|
|
|
|
$this->setHeaders();
|
|
|
|
$this->outputHeader();
|
|
|
|
|
2012-08-30 08:41:27 +00:00
|
|
|
$page = $par !== null ? $par : $this->getRequest()->getText( 'page' );
|
2006-06-29 08:07:00 +00:00
|
|
|
$title = Title::newFromText( $page );
|
|
|
|
|
2014-09-22 16:53:11 +00:00
|
|
|
$this->showForm( $title );
|
2008-01-09 20:52:38 +00:00
|
|
|
|
2011-11-13 14:22:24 +00:00
|
|
|
if ( $title && $title->exists() ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
$id = $this->getRequest()->getInt( 'id' );
|
2014-07-26 21:44:55 +00:00
|
|
|
$cout = new CiteThisPageOutput( $title, $id );
|
2006-06-29 08:07:00 +00:00
|
|
|
$cout->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 16:53:11 +00:00
|
|
|
private function showForm( Title $title = null ) {
|
|
|
|
$this->getOutput()->addHTML(
|
2011-01-12 15:13:06 +00:00
|
|
|
Xml::openElement( 'form',
|
2006-06-29 08:07:00 +00:00
|
|
|
array(
|
2014-07-26 21:44:55 +00:00
|
|
|
'id' => 'specialCiteThisPage',
|
2006-06-29 08:07:00 +00:00
|
|
|
'method' => 'get',
|
2014-09-22 16:53:11 +00:00
|
|
|
'action' => wfScript(),
|
2011-01-12 15:13:06 +00:00
|
|
|
) ) .
|
2014-09-22 16:53:11 +00:00
|
|
|
Html::hidden( 'title', SpecialPage::getTitleFor( 'CiteThisPage' )->getPrefixedDBkey() ) .
|
|
|
|
Xml::openElement( 'label' ) .
|
|
|
|
$this->msg( 'citethispage-change-target' )->escaped() . ' ' .
|
|
|
|
Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'text',
|
|
|
|
'size' => 30,
|
|
|
|
'name' => 'page',
|
|
|
|
'value' => $title ? $title->getPrefixedText() : ''
|
|
|
|
),
|
|
|
|
''
|
|
|
|
) .
|
|
|
|
' ' .
|
|
|
|
Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'value' => $this->msg( 'citethispage-change-submit' )->escaped()
|
|
|
|
),
|
|
|
|
''
|
|
|
|
) .
|
|
|
|
Xml::closeElement( 'label' ) .
|
2008-12-20 09:32:47 +00:00
|
|
|
Xml::closeElement( 'form' )
|
2006-06-29 08:07:00 +00:00
|
|
|
);
|
|
|
|
}
|
2015-05-15 20:00:37 +00:00
|
|
|
|
2016-01-30 20:08:53 +00:00
|
|
|
/**
|
|
|
|
* Return an array of subpages beginning with $search that this special page will accept.
|
|
|
|
*
|
|
|
|
* @param string $search Prefix to search for
|
|
|
|
* @param int $limit Maximum number of results to return (usually 10)
|
|
|
|
* @param int $offset Number of results to skip (usually 0)
|
|
|
|
* @return string[] Matching subpages
|
|
|
|
*/
|
|
|
|
public function prefixSearchSubpages( $search, $limit, $offset ) {
|
|
|
|
$title = Title::newFromText( $search );
|
|
|
|
if ( !$title || !$title->canExist() ) {
|
|
|
|
// No prefix suggestion in special and media namespace
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
// Autocomplete subpage the same as a normal search
|
|
|
|
$prefixSearcher = new StringPrefixSearch;
|
|
|
|
$result = $prefixSearcher->search( $search, $limit, array(), $offset );
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2015-05-15 20:00:37 +00:00
|
|
|
protected function getGroupName() {
|
|
|
|
return 'pagetools';
|
|
|
|
}
|
2006-06-29 08:07:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 21:44:55 +00:00
|
|
|
class CiteThisPageOutput {
|
2011-05-28 20:44:24 +00:00
|
|
|
/**
|
|
|
|
* @var Title
|
|
|
|
*/
|
2014-08-17 21:04:22 +00:00
|
|
|
public $mTitle;
|
2011-05-28 20:44:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Article
|
|
|
|
*/
|
2014-08-17 21:04:22 +00:00
|
|
|
public $mArticle;
|
2011-05-28 20:44:24 +00:00
|
|
|
|
2014-08-17 21:04:22 +00:00
|
|
|
public $mId;
|
2011-05-28 20:44:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Parser
|
|
|
|
*/
|
2014-08-17 21:04:22 +00:00
|
|
|
public $mParser;
|
2011-05-28 20:44:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ParserOptions
|
|
|
|
*/
|
2014-08-17 21:04:22 +00:00
|
|
|
public $mParserOptions;
|
2011-05-28 20:44:24 +00:00
|
|
|
|
2014-08-17 21:04:22 +00:00
|
|
|
public $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();
|
|
|
|
|
2014-07-26 21:44:55 +00:00
|
|
|
$wgParser->setHook( 'citation', array( $this, 'citationTagParse' ) );
|
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() {
|
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' );
|
|
|
|
|
2014-07-26 21:44:55 +00:00
|
|
|
$msg = wfMessage( 'citethispage-content' )->inContentLanguage()->plain();
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $msg == '' ) {
|
2016-01-16 12:41:27 +00:00
|
|
|
# With MediaWiki 1.20 the plain text files were deleted
|
|
|
|
# and the text moved into SpecialCite.i18n.php
|
2014-07-26 21:44:55 +00:00
|
|
|
# This code is kept for b/c in case an installation has its own file "citethispage-content-xx"
|
2012-04-26 10:13:54 +00:00
|
|
|
# for a previously not supported language.
|
|
|
|
global $wgContLang, $wgContLanguageCode;
|
2016-01-16 12:41:27 +00:00
|
|
|
$dir = __DIR__ . DIRECTORY_SEPARATOR;
|
2012-04-26 10:13:54 +00:00
|
|
|
$code = $wgContLang->lc( $wgContLanguageCode );
|
2014-07-26 21:44:55 +00:00
|
|
|
if ( file_exists( "${dir}citethispage-content-$code" ) ) {
|
|
|
|
$msg = file_get_contents( "${dir}citethispage-content-$code" );
|
|
|
|
} elseif( file_exists( "${dir}citethispage-content" ) ){
|
|
|
|
$msg = file_get_contents( "${dir}citethispage-content" );
|
2012-04-26 10:13:54 +00:00
|
|
|
}
|
2006-07-03 13:11:35 +00:00
|
|
|
}
|
2016-01-16 12:41:27 +00:00
|
|
|
$ret = $wgParser->parse(
|
|
|
|
$msg, $this->mTitle, $this->mParserOptions, false, true, $this->getRevId()
|
|
|
|
);
|
2014-09-22 17:09:10 +00:00
|
|
|
$wgOut->addModuleStyles( 'ext.citeThisPage' );
|
2014-05-04 23:14:55 +00:00
|
|
|
|
|
|
|
# Introduced in 1.24
|
2016-01-16 12:41:27 +00:00
|
|
|
if ( method_exists( $wgOut, 'addParserOutputContent' ) ) {
|
2014-05-04 23:14:55 +00:00
|
|
|
$wgOut->addParserOutputContent( $ret );
|
|
|
|
} else {
|
|
|
|
$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 );
|
2015-01-24 16:43:35 +00:00
|
|
|
$this->mParserOptions->setDateFormat( 'default' );
|
2006-06-29 08:07:00 +00:00
|
|
|
$this->mParserOptions->setEditSection( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
function genParser() {
|
|
|
|
$this->mParser = new Parser;
|
2014-07-26 21:44:55 +00:00
|
|
|
$this->mSpTitle = SpecialPage::getTitleFor( 'CiteThisPage' );
|
2006-06-29 08:07:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 21:44:55 +00:00
|
|
|
function citationTagParse( $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
|
|
|
}
|