2008-06-06 20:38:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**#@+
|
|
|
|
* A parser extension that adds two tags, <ref> and <references> for adding
|
|
|
|
* citations to pages
|
|
|
|
*
|
2010-06-06 15:12:22 +00:00
|
|
|
* @ingroup Extensions
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
2009-12-05 14:28:24 +00:00
|
|
|
* @link http://www.mediawiki.org/wiki/Extension:Cite/Cite.php Documentation
|
2008-06-06 20:38:04 +00:00
|
|
|
* @link http://www.w3.org/TR/html4/struct/text.html#edef-CITE <cite> definition in HTML
|
|
|
|
* @link http://www.w3.org/TR/2005/WD-xhtml2-20050527/mod-text.html#edef_text_cite <cite> definition in XHTML 2.0
|
|
|
|
*
|
|
|
|
* @bug 4579
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2008-08-08 19:11:31 +00:00
|
|
|
class Cite {
|
2008-06-06 20:38:04 +00:00
|
|
|
/**#@+
|
|
|
|
* @access private
|
|
|
|
*/
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Datastructure representing <ref> input, in the format of:
|
|
|
|
* <code>
|
|
|
|
* array(
|
|
|
|
* 'user supplied' => array(
|
|
|
|
* 'text' => 'user supplied reference & key',
|
|
|
|
* 'count' => 1, // occurs twice
|
|
|
|
* 'number' => 1, // The first reference, we want
|
|
|
|
* // all occourances of it to
|
|
|
|
* // use the same number
|
|
|
|
* ),
|
|
|
|
* 0 => 'Anonymous reference',
|
|
|
|
* 1 => 'Another anonymous reference',
|
|
|
|
* 'some key' => array(
|
|
|
|
* 'text' => 'this one occurs once'
|
|
|
|
* 'count' => 0,
|
|
|
|
* 'number' => 4
|
|
|
|
* ),
|
|
|
|
* 3 => 'more stuff'
|
|
|
|
* );
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* This works because:
|
2011-02-26 22:39:53 +00:00
|
|
|
* * PHP's datastructures are guaranteed to be returned in the
|
2008-06-06 20:38:04 +00:00
|
|
|
* order that things are inserted into them (unless you mess
|
|
|
|
* with that)
|
|
|
|
* * User supplied keys can't be integers, therefore avoiding
|
|
|
|
* conflict with anonymous keys
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
**/
|
|
|
|
var $mRefs = array();
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Count for user displayed output (ref[1], ref[2], ...)
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2008-08-08 19:11:31 +00:00
|
|
|
var $mOutCnt = 0;
|
2008-06-06 20:38:04 +00:00
|
|
|
var $mGroupCnt = array();
|
|
|
|
|
2011-03-04 11:45:22 +00:00
|
|
|
/**
|
|
|
|
* Counter to track the total number of (useful) calls to either the
|
|
|
|
* ref or references tag hook
|
|
|
|
*/
|
|
|
|
var $mCallCnt = 0;
|
2008-06-06 20:38:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The backlinks, in order, to pass as $3 to
|
|
|
|
* 'cite_references_link_many_format', defined in
|
|
|
|
* 'cite_references_link_many_format_backlink_labels
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $mBacklinkLabels;
|
2010-05-22 14:28:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The links to use per group, in order.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $mLinkLabels = array();
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
2011-05-28 20:44:24 +00:00
|
|
|
* @var Parser
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
|
|
|
var $mParser;
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2012-06-17 00:34:38 +00:00
|
|
|
/**
|
|
|
|
* True when the ParserAfterParse hook has been called.
|
|
|
|
* Used to avoid doing anything in ParserBeforeTidy.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
var $mHaveAfterParse = false;
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
2009-07-26 22:15:13 +00:00
|
|
|
* True when a <ref> tag is being processed.
|
2008-06-06 20:38:04 +00:00
|
|
|
* Used to avoid infinite recursion
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2008-06-06 20:38:04 +00:00
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
var $mInCite = false;
|
2009-07-26 22:15:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True when a <references> tag is being processed.
|
|
|
|
* Used to detect the use of <references> to define refs
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2009-07-26 22:15:13 +00:00
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
var $mInReferences = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error stack used when defining refs in <references>
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2009-07-26 22:15:13 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $mReferencesErrors = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Group used when in <references> block
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2009-07-26 22:15:13 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $mReferencesGroup = '';
|
|
|
|
|
|
|
|
/**
|
2011-02-22 00:07:21 +00:00
|
|
|
* <ref> call stack
|
2009-07-26 22:15:13 +00:00
|
|
|
* Used to cleanup out of sequence ref calls created by #tag
|
|
|
|
* See description of function rollbackRef.
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2009-07-26 22:15:13 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $mRefCallStack = array();
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
2011-05-31 17:49:22 +00:00
|
|
|
* Did we install us into $wgHooks yet?
|
|
|
|
* @var Boolean
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2011-05-31 17:49:22 +00:00
|
|
|
static protected $hooksInstalled = false;
|
2008-06-06 20:38:04 +00:00
|
|
|
|
|
|
|
/**#@+ @access private */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback function for <ref>
|
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $str string Input
|
|
|
|
* @param $argv array Arguments
|
|
|
|
* @param $parser Parser
|
2013-12-06 23:43:45 +00:00
|
|
|
* @param $frame PPFrame
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-06 23:43:45 +00:00
|
|
|
function ref( $str, $argv, $parser, $frame ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
if ( $this->mInCite ) {
|
|
|
|
return htmlspecialchars( "<ref>$str</ref>" );
|
|
|
|
} else {
|
2011-03-04 11:45:22 +00:00
|
|
|
$this->mCallCnt++;
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mInCite = true;
|
|
|
|
$ret = $this->guardedRef( $str, $argv, $parser );
|
|
|
|
$this->mInCite = false;
|
2013-10-14 04:28:41 +00:00
|
|
|
$parserOutput = $parser->getOutput();
|
|
|
|
$parserOutput->addModules( 'ext.cite' );
|
|
|
|
$parserOutput->addModuleStyles( 'ext.rtlcite' );
|
2013-12-06 23:43:45 +00:00
|
|
|
if ( is_callable( array( $frame, 'setVolatile' ) ) ) {
|
|
|
|
$frame->setVolatile();
|
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
2009-02-11 06:34:39 +00:00
|
|
|
|
2011-05-28 20:44:24 +00:00
|
|
|
/**
|
|
|
|
* @param $str string Input
|
|
|
|
* @param $argv array Arguments
|
|
|
|
* @param $parser Parser
|
|
|
|
* @param $default_group string
|
|
|
|
* @return string
|
|
|
|
*/
|
2010-04-17 21:07:37 +00:00
|
|
|
function guardedRef( $str, $argv, $parser, $default_group = CITE_DEFAULT_GROUP ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mParser = $parser;
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
# The key here is the "name" attribute.
|
2010-08-16 12:05:57 +00:00
|
|
|
list( $key, $group, $follow ) = $this->refArg( $argv );
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-07-26 22:15:13 +00:00
|
|
|
# Split these into groups.
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $group === null ) {
|
|
|
|
if ( $this->mInReferences ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
$group = $this->mReferencesGroup;
|
|
|
|
} else {
|
|
|
|
$group = $default_group;
|
|
|
|
}
|
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
|
|
|
# This section deals with constructions of the form
|
2009-07-26 22:15:13 +00:00
|
|
|
#
|
|
|
|
# <references>
|
|
|
|
# <ref name="foo"> BAR </ref>
|
|
|
|
# </references>
|
|
|
|
#
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $this->mInReferences ) {
|
|
|
|
if ( $group != $this->mReferencesGroup ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
# <ref> and <references> have conflicting group attributes.
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mReferencesErrors[] =
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->error( 'cite_error_references_group_mismatch', htmlspecialchars( $group ) );
|
2010-04-17 21:07:37 +00:00
|
|
|
} elseif ( $str !== '' ) {
|
|
|
|
if ( !isset( $this->mRefs[$group] ) ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
# Called with group attribute not defined in text.
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mReferencesErrors[] =
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->error( 'cite_error_references_missing_group', htmlspecialchars( $group ) );
|
2010-04-17 21:07:37 +00:00
|
|
|
} elseif ( $key === null || $key === '' ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
# <ref> calls inside <references> must be named
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mReferencesErrors[] =
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->error( 'cite_error_references_no_key' );
|
2010-04-17 21:07:37 +00:00
|
|
|
} elseif ( !isset( $this->mRefs[$group][$key] ) ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
# Called with name attribute not defined in text.
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mReferencesErrors[] =
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->error( 'cite_error_references_missing_key', $key );
|
|
|
|
} else {
|
|
|
|
# Assign the text to corresponding ref
|
|
|
|
$this->mRefs[$group][$key]['text'] = $str;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# <ref> called in <references> has no content.
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mReferencesErrors[] =
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->error( 'cite_error_empty_references_define', $key );
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $str === '' ) {
|
2008-10-04 22:26:45 +00:00
|
|
|
# <ref ...></ref>. This construct is invalid if
|
|
|
|
# it's a contentful ref, but OK if it's a named duplicate and should
|
|
|
|
# be equivalent <ref ... />, for compatability with #tag.
|
2009-07-26 22:15:13 +00:00
|
|
|
if ( $key == false ) {
|
|
|
|
$this->mRefCallStack[] = false;
|
2008-10-01 19:56:40 +00:00
|
|
|
return $this->error( 'cite_error_ref_no_input' );
|
2009-07-26 22:15:13 +00:00
|
|
|
} else {
|
2008-10-01 19:56:40 +00:00
|
|
|
$str = null;
|
2009-07-26 22:15:13 +00:00
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $key === false ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
# TODO: Comment this case; what does this condition mean?
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mRefCallStack[] = false;
|
2008-06-06 20:38:04 +00:00
|
|
|
return $this->error( 'cite_error_ref_too_many_keys' );
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:11:54 +00:00
|
|
|
if ( $str === null && $key === null ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
# Something like <ref />; this makes no sense.
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mRefCallStack[] = false;
|
2008-06-06 20:38:04 +00:00
|
|
|
return $this->error( 'cite_error_ref_no_key' );
|
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2010-08-16 12:05:57 +00:00
|
|
|
if ( preg_match( '/^[0-9]+$/', $key ) || preg_match( '/^[0-9]+$/', $follow ) ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
# Numeric names mess up the resulting id's, potentially produ-
|
|
|
|
# cing duplicate id's in the XHTML. The Right Thing To Do
|
|
|
|
# would be to mangle them, but it's not really high-priority
|
|
|
|
# (and would produce weird id's anyway).
|
2009-07-26 22:15:13 +00:00
|
|
|
|
|
|
|
$this->mRefCallStack[] = false;
|
2008-06-06 20:38:04 +00:00
|
|
|
return $this->error( 'cite_error_ref_numeric_key' );
|
|
|
|
}
|
|
|
|
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( preg_match(
|
2008-09-18 17:21:13 +00:00
|
|
|
'/<ref\b[^<]*?>/',
|
|
|
|
preg_replace( '#<([^ ]+?).*?>.*?</\\1 *>|<!--.*?-->#', '', $str )
|
|
|
|
) ) {
|
2008-09-18 17:16:10 +00:00
|
|
|
# (bug 6199) This most likely implies that someone left off the
|
|
|
|
# closing </ref> tag, which will cause the entire article to be
|
|
|
|
# eaten up until the next <ref>. So we bail out early instead.
|
|
|
|
# The fancy regex above first tries chopping out anything that
|
|
|
|
# looks like a comment or SGML tag, which is a crude way to avoid
|
|
|
|
# false alarms for <nowiki>, <pre>, etc.
|
|
|
|
#
|
|
|
|
# Possible improvement: print the warning, followed by the contents
|
|
|
|
# of the <ref> tag. This way no part of the article will be eaten
|
|
|
|
# even temporarily.
|
2009-07-26 22:15:13 +00:00
|
|
|
|
|
|
|
$this->mRefCallStack[] = false;
|
2008-09-18 17:16:10 +00:00
|
|
|
return $this->error( 'cite_error_included_ref' );
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:11:54 +00:00
|
|
|
if ( is_string( $key ) || is_string( $str ) ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
# We don't care about the content: if the key exists, the ref
|
|
|
|
# is presumptively valid. Either it stores a new ref, or re-
|
|
|
|
# fers to an existing one. If it refers to a nonexistent ref,
|
|
|
|
# we'll figure that out later. Likewise it's definitely valid
|
|
|
|
# if there's any content, regardless of key.
|
2009-07-26 22:15:13 +00:00
|
|
|
|
2010-08-16 12:05:57 +00:00
|
|
|
return $this->stack( $str, $key, $group, $follow, $argv );
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Not clear how we could get here, but something is probably
|
|
|
|
# wrong with the types. Let's fail fast.
|
2013-09-28 18:33:10 +00:00
|
|
|
throw new MWException( 'Invalid $str and/or $key: ' . serialize( array( $str, $key ) ) );
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the arguments to the <ref> tag
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2010-08-16 12:05:57 +00:00
|
|
|
* "name" : Key of the reference.
|
|
|
|
* "group" : Group to which it belongs. Needs to be passed to <references /> too.
|
|
|
|
* "follow" : If the current reference is the continuation of another, key of that reference.
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $argv array The argument vector
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return mixed false on invalid input, a string on valid
|
|
|
|
* input and null on no input
|
|
|
|
*/
|
|
|
|
function refArg( $argv ) {
|
|
|
|
global $wgAllowCiteGroups;
|
|
|
|
$cnt = count( $argv );
|
|
|
|
$group = null;
|
|
|
|
$key = null;
|
2010-08-16 12:05:57 +00:00
|
|
|
$follow = null;
|
2008-06-06 20:38:04 +00:00
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $cnt > 2 ) {
|
2010-08-16 12:05:57 +00:00
|
|
|
// There should only be one key or follow parameter, and one group parameter
|
2011-02-22 00:07:21 +00:00
|
|
|
// FIXME : this looks inconsistent, it should probably return a tuple
|
2008-06-06 20:38:04 +00:00
|
|
|
return false;
|
2011-02-22 00:07:21 +00:00
|
|
|
} elseif ( $cnt >= 1 ) {
|
2010-08-16 12:05:57 +00:00
|
|
|
if ( isset( $argv['name'] ) && isset( $argv['follow'] ) ) {
|
|
|
|
return array( false, false, false );
|
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
if ( isset( $argv['name'] ) ) {
|
|
|
|
// Key given.
|
2008-12-30 00:22:14 +00:00
|
|
|
$key = Sanitizer::escapeId( $argv['name'], 'noninitial' );
|
2010-04-17 21:07:37 +00:00
|
|
|
unset( $argv['name'] );
|
2008-06-06 20:38:04 +00:00
|
|
|
--$cnt;
|
|
|
|
}
|
2010-08-16 12:05:57 +00:00
|
|
|
if ( isset( $argv['follow'] ) ) {
|
|
|
|
// Follow given.
|
|
|
|
$follow = Sanitizer::escapeId( $argv['follow'], 'noninitial' );
|
|
|
|
unset( $argv['follow'] );
|
|
|
|
--$cnt;
|
|
|
|
}
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( isset( $argv['group'] ) ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( !$wgAllowCiteGroups ) {
|
|
|
|
// remove when groups are fully tested.
|
|
|
|
return array( false );
|
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
// Group given.
|
2008-07-30 21:23:43 +00:00
|
|
|
$group = $argv['group'];
|
2010-04-17 21:07:37 +00:00
|
|
|
unset( $argv['group'] );
|
2008-06-06 20:38:04 +00:00
|
|
|
--$cnt;
|
|
|
|
}
|
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $cnt == 0 ) {
|
2010-08-16 12:05:57 +00:00
|
|
|
return array ( $key, $group, $follow );
|
2011-02-22 00:07:21 +00:00
|
|
|
} else {
|
2008-06-06 20:38:04 +00:00
|
|
|
// Invalid key
|
2010-08-16 12:05:57 +00:00
|
|
|
return array( false, false, false );
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-06-06 20:38:04 +00:00
|
|
|
// No key
|
2010-08-16 12:05:57 +00:00
|
|
|
return array( null, $group, false );
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate $this->mRefs based on input and arguments to <ref>
|
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $str string Input from the <ref> tag
|
|
|
|
* @param $key mixed Argument to the <ref> tag as returned by $this->refArg()
|
|
|
|
* @param $group
|
|
|
|
* @param $follow
|
|
|
|
* @param $call
|
|
|
|
*
|
2011-02-22 00:07:21 +00:00
|
|
|
* @return string
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2010-08-16 12:05:57 +00:00
|
|
|
function stack( $str, $key = null, $group, $follow, $call ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( !isset( $this->mRefs[$group] ) ) {
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mRefs[$group] = array();
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
if ( !isset( $this->mGroupCnt[$group] ) ) {
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mGroupCnt[$group] = 0;
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
|
2010-08-16 12:05:57 +00:00
|
|
|
if ( $follow != null ) {
|
|
|
|
if ( isset( $this->mRefs[$group][$follow] ) && is_array( $this->mRefs[$group][$follow] ) ) {
|
|
|
|
// add text to the note that is being followed
|
2011-02-22 00:07:21 +00:00
|
|
|
$this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' ' . $str;
|
2010-08-16 12:05:57 +00:00
|
|
|
} else {
|
|
|
|
// insert part of note at the beginning of the group
|
2011-02-22 00:07:21 +00:00
|
|
|
for ( $k = 0 ; $k < count( $this->mRefs[$group] ) ; $k++ ) {
|
|
|
|
if ( $this->mRefs[$group][$k]['follow'] == null ) {
|
|
|
|
break;
|
|
|
|
}
|
2010-08-16 12:05:57 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
array_splice( $this->mRefs[$group], $k, 0,
|
2011-02-24 23:05:22 +00:00
|
|
|
array( array( 'count' => - 1,
|
|
|
|
'text' => $str,
|
|
|
|
'key' => ++$this->mOutCnt ,
|
|
|
|
'follow' => $follow ) ) );
|
2011-02-22 00:07:21 +00:00
|
|
|
array_splice( $this->mRefCallStack, $k, 0,
|
2011-02-24 23:05:22 +00:00
|
|
|
array( array( 'new', $call, $str, $key, $group, $this->mOutCnt ) ) );
|
2010-08-16 12:05:57 +00:00
|
|
|
}
|
|
|
|
// return an empty string : this is not a reference
|
|
|
|
return '';
|
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
if ( $key === null ) {
|
|
|
|
// No key
|
2010-04-17 21:07:37 +00:00
|
|
|
// $this->mRefs[$group][] = $str;
|
|
|
|
$this->mRefs[$group][] = array( 'count' => - 1, 'text' => $str, 'key' => ++$this->mOutCnt );
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mRefCallStack[] = array( 'new', $call, $str, $key, $group, $this->mOutCnt );
|
2008-06-06 20:38:04 +00:00
|
|
|
|
2012-10-17 22:58:55 +00:00
|
|
|
return $this->linkRef( $group, $this->mOutCnt );
|
2011-02-22 00:07:21 +00:00
|
|
|
} elseif ( is_string( $key ) ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
// Valid key
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( !isset( $this->mRefs[$group][$key] ) || !is_array( $this->mRefs[$group][$key] ) ) {
|
|
|
|
// First occurrence
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mRefs[$group][$key] = array(
|
|
|
|
'text' => $str,
|
|
|
|
'count' => 0,
|
2008-08-08 19:11:31 +00:00
|
|
|
'key' => ++$this->mOutCnt,
|
2008-06-06 20:38:04 +00:00
|
|
|
'number' => ++$this->mGroupCnt[$group]
|
|
|
|
);
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mRefCallStack[] = array( 'new', $call, $str, $key, $group, $this->mOutCnt );
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
return
|
|
|
|
$this->linkRef(
|
|
|
|
$group,
|
|
|
|
$key,
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mRefs[$group][$key]['key'] . "-" . $this->mRefs[$group][$key]['count'],
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mRefs[$group][$key]['number'],
|
2010-04-17 21:07:37 +00:00
|
|
|
"-" . $this->mRefs[$group][$key]['key']
|
2008-06-06 20:38:04 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// We've been here before
|
|
|
|
if ( $this->mRefs[$group][$key]['text'] === null && $str !== '' ) {
|
|
|
|
// If no text found before, use this text
|
|
|
|
$this->mRefs[$group][$key]['text'] = $str;
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mRefCallStack[] = array( 'assign', $call, $str, $key, $group,
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mRefs[$group][$key]['key'] );
|
|
|
|
} else {
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mRefCallStack[] = array( 'increment', $call, $str, $key, $group,
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mRefs[$group][$key]['key'] );
|
|
|
|
}
|
2010-04-17 21:07:37 +00:00
|
|
|
return
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->linkRef(
|
|
|
|
$group,
|
|
|
|
$key,
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->mRefs[$group][$key]['key'] . "-" . ++$this->mRefs[$group][$key]['count'],
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mRefs[$group][$key]['number'],
|
2010-04-17 21:07:37 +00:00
|
|
|
"-" . $this->mRefs[$group][$key]['key']
|
2011-02-22 00:07:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2013-09-28 18:33:10 +00:00
|
|
|
throw new MWException( 'Invalid stack key: ' . serialize( $key ) );
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-07-26 22:15:13 +00:00
|
|
|
/**
|
|
|
|
* Partially undoes the effect of calls to stack()
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2009-07-26 22:15:13 +00:00
|
|
|
* Called by guardedReferences()
|
|
|
|
*
|
2011-02-22 00:07:21 +00:00
|
|
|
* The option to define <ref> within <references> makes the
|
2009-07-26 22:15:13 +00:00
|
|
|
* behavior of <ref> context dependent. This is normally fine
|
|
|
|
* but certain operations (especially #tag) lead to out-of-order
|
|
|
|
* parser evaluation with the <ref> tags being processed before
|
|
|
|
* their containing <reference> element is read. This leads to
|
|
|
|
* stack corruption that this function works to fix.
|
|
|
|
*
|
|
|
|
* This function is not a total rollback since some internal
|
|
|
|
* counters remain incremented. Doing so prevents accidentally
|
|
|
|
* corrupting certain links.
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* @param $key
|
|
|
|
* @param $group
|
|
|
|
* @param $index
|
2009-07-26 22:15:13 +00:00
|
|
|
*/
|
|
|
|
function rollbackRef( $type, $key, $group, $index ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( !isset( $this->mRefs[$group] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-07-26 22:15:13 +00:00
|
|
|
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $key === null ) {
|
|
|
|
foreach ( $this->mRefs[$group] as $k => $v ) {
|
|
|
|
if ( $this->mRefs[$group][$k]['key'] === $index ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
$key = $k;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sanity checks that specified element exists.
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $key === null ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( !isset( $this->mRefs[$group][$key] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( $this->mRefs[$group][$key]['key'] != $index ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-07-26 22:15:13 +00:00
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
switch ( $type ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
case 'new':
|
|
|
|
# Rollback the addition of new elements to the stack.
|
|
|
|
unset( $this->mRefs[$group][$key] );
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( count( $this->mRefs[$group] ) == 0 ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
unset( $this->mRefs[$group] );
|
|
|
|
unset( $this->mGroupCnt[$group] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'assign':
|
|
|
|
# Rollback assignment of text to pre-existing elements.
|
|
|
|
$this->mRefs[$group][$key]['text'] = null;
|
|
|
|
# continue without break
|
|
|
|
case 'increment':
|
2012-03-19 14:59:29 +00:00
|
|
|
# Rollback increase in named ref occurrences.
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mRefs[$group][$key]['count']--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Callback function for <references>
|
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $str string Input
|
|
|
|
* @param $argv array Arguments
|
|
|
|
* @param $parser Parser
|
2013-12-06 23:43:45 +00:00
|
|
|
* @param $frame PPFrame
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-06 23:43:45 +00:00
|
|
|
function references( $str, $argv, $parser, $frame ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
if ( $this->mInCite || $this->mInReferences ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
if ( is_null( $str ) ) {
|
|
|
|
return htmlspecialchars( "<references/>" );
|
|
|
|
} else {
|
|
|
|
return htmlspecialchars( "<references>$str</references>" );
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-04 11:45:22 +00:00
|
|
|
$this->mCallCnt++;
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mInReferences = true;
|
2008-06-06 20:38:04 +00:00
|
|
|
$ret = $this->guardedReferences( $str, $argv, $parser );
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mInReferences = false;
|
2013-12-06 23:43:45 +00:00
|
|
|
if ( is_callable( array( $frame, 'setVolatile' ) ) ) {
|
|
|
|
$frame->setVolatile();
|
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-28 20:44:24 +00:00
|
|
|
/**
|
|
|
|
* @param $str string
|
|
|
|
* @param $argv array
|
|
|
|
* @param $parser Parser
|
|
|
|
* @param $group string
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-06-06 20:38:04 +00:00
|
|
|
function guardedReferences( $str, $argv, $parser, $group = CITE_DEFAULT_GROUP ) {
|
|
|
|
global $wgAllowCiteGroups;
|
|
|
|
|
|
|
|
$this->mParser = $parser;
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2011-04-27 11:11:54 +00:00
|
|
|
if ( isset( $argv['group'] ) && $wgAllowCiteGroups ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
$group = $argv['group'];
|
2010-04-17 21:07:37 +00:00
|
|
|
unset ( $argv['group'] );
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-07-26 22:15:13 +00:00
|
|
|
if ( strval( $str ) !== '' ) {
|
|
|
|
$this->mReferencesGroup = $group;
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-07-26 22:15:13 +00:00
|
|
|
# Detect whether we were sent already rendered <ref>s
|
|
|
|
# Mostly a side effect of using #tag to call references
|
|
|
|
$count = substr_count( $str, $parser->uniqPrefix() . "-ref-" );
|
2010-04-17 21:07:37 +00:00
|
|
|
for ( $i = 1; $i <= $count; $i++ ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( count( $this->mRefCallStack ) < 1 ) {
|
|
|
|
break;
|
|
|
|
}
|
2009-07-26 22:15:13 +00:00
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
# The following assumes that the parsed <ref>s sent within
|
2009-07-26 22:15:13 +00:00
|
|
|
# the <references> block were the most recent calls to
|
|
|
|
# <ref>. This assumption is true for all known use cases,
|
|
|
|
# but not strictly enforced by the parser. It is possible
|
|
|
|
# that some unusual combination of #tag, <references> and
|
|
|
|
# conditional parser functions could be created that would
|
|
|
|
# lead to malformed references here.
|
|
|
|
$call = array_pop( $this->mRefCallStack );
|
2010-04-17 21:07:37 +00:00
|
|
|
if ( $call !== false ) {
|
|
|
|
list( $type, $ref_argv, $ref_str,
|
|
|
|
$ref_key, $ref_group, $ref_index ) = $call;
|
2009-07-26 22:15:13 +00:00
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
# Undo effects of calling <ref> while unaware of containing <references>
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->rollbackRef( $type, $ref_key, $ref_group, $ref_index );
|
|
|
|
|
|
|
|
# Rerun <ref> call now that mInReferences is set.
|
|
|
|
$this->guardedRef( $ref_str, $ref_argv, $parser );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse $str to process any unparsed <ref> tags.
|
|
|
|
$parser->recursiveTagParse( $str );
|
|
|
|
|
|
|
|
# Reset call stack
|
|
|
|
$this->mRefCallStack = array();
|
|
|
|
}
|
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( count( $argv ) && $wgAllowCiteGroups ) {
|
2008-09-09 03:55:54 +00:00
|
|
|
return $this->error( 'cite_error_references_invalid_parameters_group' );
|
2011-02-22 00:07:21 +00:00
|
|
|
} elseif ( count( $argv ) ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
return $this->error( 'cite_error_references_invalid_parameters' );
|
2011-02-22 00:07:21 +00:00
|
|
|
} else {
|
2009-07-26 22:15:13 +00:00
|
|
|
$s = $this->referencesFormat( $group );
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $parser->getOptions()->getIsSectionPreview() ) {
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
2009-07-26 22:15:13 +00:00
|
|
|
# Append errors generated while processing <references>
|
|
|
|
if ( count( $this->mReferencesErrors ) > 0 ) {
|
|
|
|
$s .= "\n" . implode( "<br />\n", $this->mReferencesErrors );
|
|
|
|
$this->mReferencesErrors = array();
|
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make output to be returned from the references() function
|
2011-09-14 15:07:20 +00:00
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $group
|
2011-09-14 15:07:20 +00:00
|
|
|
*
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string XHTML ready for output
|
|
|
|
*/
|
2010-04-17 21:07:37 +00:00
|
|
|
function referencesFormat( $group ) {
|
2011-04-27 11:11:54 +00:00
|
|
|
if ( ( count( $this->mRefs ) == 0 ) || ( empty( $this->mRefs[$group] ) ) ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
return '';
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-04-17 21:07:37 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-entries' );
|
2008-06-06 20:38:04 +00:00
|
|
|
$ent = array();
|
2011-02-22 00:07:21 +00:00
|
|
|
foreach ( $this->mRefs[$group] as $k => $v ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
$ent[] = $this->referencesFormatEntry( $k, $v );
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 08:41:27 +00:00
|
|
|
$prefix = wfMessage( 'cite_references_prefix' )->inContentLanguage()->plain();
|
|
|
|
$suffix = wfMessage( 'cite_references_suffix' )->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
$content = implode( "\n", $ent );
|
2009-02-03 04:57:28 +00:00
|
|
|
|
2012-10-30 16:22:47 +00:00
|
|
|
// Prepare the parser input. We add new lines between the pieces to avoid a confused tidy (bug 13073)
|
|
|
|
$parserInput = $prefix . "\n" . $content . "\n" . $suffix;
|
|
|
|
|
2009-02-03 04:57:28 +00:00
|
|
|
// Let's try to cache it.
|
|
|
|
global $wgMemc;
|
2010-04-17 21:07:37 +00:00
|
|
|
$cacheKey = wfMemcKey( 'citeref', md5( $parserInput ), $this->mParser->Title()->getArticleID() );
|
2009-02-03 04:57:28 +00:00
|
|
|
|
2010-04-17 21:07:37 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-entries' );
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-02-12 18:02:27 +00:00
|
|
|
global $wgCiteCacheReferences;
|
2011-02-23 07:03:26 +00:00
|
|
|
$data = false;
|
2009-02-12 18:02:27 +00:00
|
|
|
if ( $wgCiteCacheReferences ) {
|
2010-04-17 21:07:37 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-cache-get' );
|
2009-02-12 18:02:27 +00:00
|
|
|
$data = $wgMemc->get( $cacheKey );
|
2010-04-17 21:07:37 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-cache-get' );
|
2009-02-12 18:02:27 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2011-02-24 23:06:12 +00:00
|
|
|
if ( !$data || !$this->mParser->isValidHalfParsedText( $data ) ) {
|
2010-04-17 21:07:37 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-parse' );
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-02-03 04:57:28 +00:00
|
|
|
// Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar
|
2014-06-05 17:51:48 +00:00
|
|
|
$ret = rtrim( $this->mParser->recursiveTagParse( $parserInput ), "\n" );
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-02-12 18:02:27 +00:00
|
|
|
if ( $wgCiteCacheReferences ) {
|
2011-02-23 07:03:26 +00:00
|
|
|
$serData = $this->mParser->serializeHalfParsedText( $ret );
|
2009-02-12 18:02:27 +00:00
|
|
|
$wgMemc->set( $cacheKey, $serData, 86400 );
|
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2010-04-17 21:07:37 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-parse' );
|
2009-02-03 04:58:08 +00:00
|
|
|
} else {
|
2011-02-23 07:03:26 +00:00
|
|
|
$ret = $this->mParser->unserializeHalfParsedText( $data );
|
2009-02-03 04:57:28 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2010-04-17 21:07:37 +00:00
|
|
|
// done, clean up so we can reuse the group
|
2011-02-22 00:07:21 +00:00
|
|
|
unset( $this->mRefs[$group] );
|
2010-04-17 21:07:37 +00:00
|
|
|
unset( $this->mGroupCnt[$group] );
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a single entry for the referencesFormat() function
|
|
|
|
*
|
|
|
|
* @param string $key The key of the reference
|
|
|
|
* @param mixed $val The value of the reference, string for anonymous
|
|
|
|
* references, array for user-suppplied
|
|
|
|
* @return string Wikitext
|
|
|
|
*/
|
|
|
|
function referencesFormatEntry( $key, $val ) {
|
|
|
|
// Anonymous reference
|
2011-02-03 21:40:55 +00:00
|
|
|
if ( !is_array( $val ) ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
return wfMessage(
|
2008-06-06 20:38:04 +00:00
|
|
|
'cite_references_link_one',
|
|
|
|
$this->referencesKey( $key ),
|
|
|
|
$this->refKey( $key ),
|
2012-01-04 15:00:01 +00:00
|
|
|
$this->referenceText( $key, $val )
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2012-01-04 15:00:01 +00:00
|
|
|
}
|
|
|
|
$text = $this->referenceText( $key, $val['text'] );
|
|
|
|
if ( isset( $val['follow'] ) ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
return wfMessage(
|
2010-08-16 12:05:57 +00:00
|
|
|
'cite_references_no_link',
|
|
|
|
$this->referencesKey( $val['follow'] ),
|
2012-01-04 15:00:01 +00:00
|
|
|
$text
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2011-02-22 00:07:21 +00:00
|
|
|
} elseif ( $val['text'] == '' ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
return wfMessage(
|
2011-02-03 21:40:55 +00:00
|
|
|
'cite_references_link_one',
|
|
|
|
$this->referencesKey( $key ),
|
|
|
|
$this->refKey( $key, $val['count'] ),
|
2012-01-04 15:00:01 +00:00
|
|
|
$text
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2011-02-03 21:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $val['count'] < 0 ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
return wfMessage(
|
2008-06-06 20:38:04 +00:00
|
|
|
'cite_references_link_one',
|
|
|
|
$this->referencesKey( $val['key'] ),
|
2010-04-17 21:07:37 +00:00
|
|
|
# $this->refKey( $val['key'], $val['count'] ),
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->refKey( $val['key'] ),
|
2012-01-04 15:00:01 +00:00
|
|
|
$text
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2011-02-03 21:40:55 +00:00
|
|
|
// Standalone named reference, I want to format this like an
|
|
|
|
// anonymous reference because displaying "1. 1.1 Ref text" is
|
|
|
|
// overkill and users frequently use named references when they
|
|
|
|
// don't need them for convenience
|
2011-02-22 00:07:21 +00:00
|
|
|
} elseif ( $val['count'] === 0 ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
return wfMessage(
|
2008-06-06 20:38:04 +00:00
|
|
|
'cite_references_link_one',
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->referencesKey( $key . "-" . $val['key'] ),
|
|
|
|
# $this->refKey( $key, $val['count'] ),
|
|
|
|
$this->refKey( $key, $val['key'] . "-" . $val['count'] ),
|
2012-01-04 15:00:01 +00:00
|
|
|
$text
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
// Named references with >1 occurrences
|
2011-02-03 21:40:55 +00:00
|
|
|
} else {
|
2008-06-06 20:38:04 +00:00
|
|
|
$links = array();
|
2011-02-03 21:40:55 +00:00
|
|
|
// for group handling, we have an extra key here.
|
2008-06-06 20:38:04 +00:00
|
|
|
for ( $i = 0; $i <= $val['count']; ++$i ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
$links[] = wfMessage(
|
2008-08-08 19:11:31 +00:00
|
|
|
'cite_references_link_many_format',
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->refKey( $key, $val['key'] . "-$i" ),
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $i, $val['count'] ),
|
|
|
|
$this->referencesFormatEntryAlternateBacklinkLabel( $i )
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$list = $this->listToText( $links );
|
|
|
|
|
2012-08-30 08:41:27 +00:00
|
|
|
return wfMessage( 'cite_references_link_many',
|
2010-04-17 21:07:37 +00:00
|
|
|
$this->referencesKey( $key . "-" . $val['key'] ),
|
2008-06-06 20:38:04 +00:00
|
|
|
$list,
|
2012-01-04 15:00:01 +00:00
|
|
|
$text
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-04 15:00:01 +00:00
|
|
|
/**
|
|
|
|
* Returns formatted reference text
|
|
|
|
* @param String $key
|
|
|
|
* @param String $text
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
function referenceText( $key, $text ) {
|
|
|
|
if ( $text == '' ) {
|
|
|
|
return $this->error( 'cite_error_references_no_text', $key, 'noparse' );
|
|
|
|
}
|
|
|
|
return '<span class="reference-text">' . rtrim( $text, "\n" ) . "</span>\n";
|
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Generate a numeric backlink given a base number and an
|
|
|
|
* offset, e.g. $base = 1, $offset = 2; = 1.2
|
|
|
|
* Since bug #5525, it correctly does 1.9 -> 1.10 as well as 1.099 -> 1.100
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*
|
|
|
|
* @param int $base The base
|
|
|
|
* @param int $offset The offset
|
|
|
|
* @param int $max Maximum value expected.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function referencesFormatEntryNumericBacklinkLabel( $base, $offset, $max ) {
|
|
|
|
global $wgContLang;
|
|
|
|
$scope = strlen( $max );
|
|
|
|
$ret = $wgContLang->formatNum(
|
2010-04-17 21:07:37 +00:00
|
|
|
sprintf( "%s.%0{$scope}s", $base, $offset )
|
2008-06-06 20:38:04 +00:00
|
|
|
);
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a custom format backlink given an offset, e.g.
|
|
|
|
* $offset = 2; = c if $this->mBacklinkLabels = array( 'a',
|
|
|
|
* 'b', 'c', ...). Return an error if the offset > the # of
|
|
|
|
* array items
|
|
|
|
*
|
|
|
|
* @param int $offset The offset
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function referencesFormatEntryAlternateBacklinkLabel( $offset ) {
|
|
|
|
if ( !isset( $this->mBacklinkLabels ) ) {
|
|
|
|
$this->genBacklinkLabels();
|
|
|
|
}
|
|
|
|
if ( isset( $this->mBacklinkLabels[$offset] ) ) {
|
|
|
|
return $this->mBacklinkLabels[$offset];
|
|
|
|
} else {
|
|
|
|
// Feed me!
|
2011-11-14 12:22:07 +00:00
|
|
|
return $this->error( 'cite_error_references_no_backlink_label', null, 'noparse' );
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-22 14:28:48 +00:00
|
|
|
/**
|
|
|
|
* Generate a custom format link for a group given an offset, e.g.
|
2011-02-22 00:07:21 +00:00
|
|
|
* the second <ref group="foo"> is b if $this->mLinkLabels["foo"] =
|
|
|
|
* array( 'a', 'b', 'c', ...).
|
2010-05-22 14:28:48 +00:00
|
|
|
* Return an error if the offset > the # of array items
|
|
|
|
*
|
|
|
|
* @param int $offset The offset
|
|
|
|
* @param string $group The group name
|
|
|
|
* @param string $label The text to use if there's no message for them.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-02-22 00:07:21 +00:00
|
|
|
function getLinkLabel( $offset, $group, $label ) {
|
2010-05-22 14:28:48 +00:00
|
|
|
$message = "cite_link_label_group-$group";
|
|
|
|
if ( !isset( $this->mLinkLabels[$group] ) ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
$this->genLinkLabels( $group, $message );
|
2010-05-22 14:28:48 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $this->mLinkLabels[$group] === false ) {
|
2010-05-22 14:28:48 +00:00
|
|
|
// Use normal representation, ie. "$group 1", "$group 2"...
|
|
|
|
return $label;
|
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2010-05-22 14:28:48 +00:00
|
|
|
if ( isset( $this->mLinkLabels[$group][$offset - 1] ) ) {
|
|
|
|
return $this->mLinkLabels[$group][$offset - 1];
|
|
|
|
} else {
|
|
|
|
// Feed me!
|
2011-11-14 12:22:07 +00:00
|
|
|
return $this->error( 'cite_error_no_link_label_group', array( $group, $message ), 'noparse' );
|
2010-05-22 14:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Return an id for use in wikitext output based on a key and
|
|
|
|
* optionally the number of it, used in <references>, not <ref>
|
|
|
|
* (since otherwise it would link to itself)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*
|
|
|
|
* @param string $key The key
|
|
|
|
* @param int $num The number of the key
|
|
|
|
* @return string A key for use in wikitext
|
|
|
|
*/
|
|
|
|
function refKey( $key, $num = null ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
$prefix = wfMessage( 'cite_reference_link_prefix' )->inContentLanguage()->text();
|
|
|
|
$suffix = wfMessage( 'cite_reference_link_suffix' )->inContentLanguage()->text();
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( isset( $num ) ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
$key = wfMessage( 'cite_reference_link_key_with_num', $key, $num )
|
|
|
|
->inContentLanguage()->plain();
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "$prefix$key$suffix";
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an id for use in wikitext output based on a key and
|
|
|
|
* optionally the number of it, used in <ref>, not <references>
|
|
|
|
* (since otherwise it would link to itself)
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*
|
|
|
|
* @param string $key The key
|
|
|
|
* @param int $num The number of the key
|
|
|
|
* @return string A key for use in wikitext
|
|
|
|
*/
|
|
|
|
function referencesKey( $key, $num = null ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
$prefix = wfMessage( 'cite_references_link_prefix' )->inContentLanguage()->text();
|
|
|
|
$suffix = wfMessage( 'cite_references_link_suffix' )->inContentLanguage()->text();
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( isset( $num ) ) {
|
2012-08-30 08:41:27 +00:00
|
|
|
$key = wfMessage( 'cite_reference_link_key_with_num', $key, $num )
|
|
|
|
->inContentLanguage()->plain();
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "$prefix$key$suffix";
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a link (<sup ...) for the <ref> element from a key
|
|
|
|
* and return XHTML ready for output
|
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $group
|
|
|
|
* @param $key string The key for the link
|
|
|
|
* @param $count int The index of the key, used for distinguishing
|
2012-03-19 14:59:29 +00:00
|
|
|
* multiple occurrences of the same key
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $label int The label to use for the link, I want to
|
2008-06-06 20:38:04 +00:00
|
|
|
* use the same label for all occourances of
|
|
|
|
* the same named reference.
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $subkey string
|
|
|
|
*
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) {
|
|
|
|
global $wgContLang;
|
2010-05-22 14:28:48 +00:00
|
|
|
$label = is_null( $label ) ? ++$this->mGroupCnt[$group] : $label;
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
return
|
2014-06-05 17:51:48 +00:00
|
|
|
$this->mParser->recursiveTagParse(
|
2012-08-30 08:41:27 +00:00
|
|
|
wfMessage(
|
2008-06-06 20:38:04 +00:00
|
|
|
'cite_reference_link',
|
|
|
|
$this->refKey( $key, $count ),
|
|
|
|
$this->referencesKey( $key . $subkey ),
|
2011-02-22 00:07:21 +00:00
|
|
|
$this->getLinkLabel( $label, $group,
|
2011-05-28 20:44:24 +00:00
|
|
|
( ( $group == CITE_DEFAULT_GROUP ) ? '' : "$group " ) . $wgContLang->formatNum( $label ) )
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain()
|
2008-06-06 20:38:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This does approximately the same thing as
|
|
|
|
* Language::listToText() but due to this being used for a
|
|
|
|
* slightly different purpose (people might not want , as the
|
2008-09-15 20:28:25 +00:00
|
|
|
* first separator and not 'and' as the second, and this has to
|
2008-06-06 20:38:04 +00:00
|
|
|
* use messages from the content language) I'm rolling my own.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*
|
|
|
|
* @param array $arr The array to format
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function listToText( $arr ) {
|
|
|
|
$cnt = count( $arr );
|
|
|
|
|
2012-08-30 08:41:27 +00:00
|
|
|
$sep = wfMessage( 'cite_references_link_many_sep' )->inContentLanguage()->plain();
|
|
|
|
$and = wfMessage( 'cite_references_link_many_and' )->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $cnt == 1 ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
// Enforce always returning a string
|
|
|
|
return (string)$arr[0];
|
2011-02-22 00:07:21 +00:00
|
|
|
} else {
|
2008-06-06 20:38:04 +00:00
|
|
|
$t = array_slice( $arr, 0, $cnt - 1 );
|
|
|
|
return implode( $sep, $t ) . $and . $arr[$cnt - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the labels to pass to the
|
|
|
|
* 'cite_references_link_many_format' message, the format is an
|
2010-05-22 14:28:48 +00:00
|
|
|
* arbitrary number of tokens separated by [\t\n ]
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
|
|
|
function genBacklinkLabels() {
|
|
|
|
wfProfileIn( __METHOD__ );
|
2012-08-30 08:41:27 +00:00
|
|
|
$text = wfMessage( 'cite_references_link_many_format_backlink_labels' )
|
|
|
|
->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mBacklinkLabels = preg_split( '#[\n\t ]#', $text );
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
|
|
|
|
2010-05-22 14:28:48 +00:00
|
|
|
/**
|
|
|
|
* Generate the labels to pass to the
|
|
|
|
* 'cite_reference_link' message instead of numbers, the format is an
|
|
|
|
* arbitrary number of tokens separated by [\t\n ]
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
|
|
|
* @param $group
|
|
|
|
* @param $message
|
2010-05-22 14:28:48 +00:00
|
|
|
*/
|
2011-02-22 00:07:21 +00:00
|
|
|
function genLinkLabels( $group, $message ) {
|
2010-05-22 14:28:48 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
$text = false;
|
2011-01-17 08:04:14 +00:00
|
|
|
$msg = wfMessage( $message )->inContentLanguage();
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $msg->exists() ) {
|
2011-01-17 08:04:14 +00:00
|
|
|
$text = $msg->plain();
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
$this->mLinkLabels[$group] = ( $text == '' ) ? false : preg_split( '#[\n\t ]#', $text );
|
2010-05-22 14:28:48 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Gets run when Parser::clearState() gets run, since we don't
|
|
|
|
* want the counts to transcend pages and other instances
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
|
|
|
* @param $parser Parser
|
|
|
|
*
|
|
|
|
* @return bool
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2011-09-14 15:07:20 +00:00
|
|
|
function clearState( &$parser ) {
|
2011-05-31 17:49:22 +00:00
|
|
|
if ( $parser->extCite !== $this ) {
|
|
|
|
return $parser->extCite->clearState( $parser );
|
|
|
|
}
|
2011-09-14 15:07:20 +00:00
|
|
|
|
2008-06-16 14:04:39 +00:00
|
|
|
# Don't clear state when we're in the middle of parsing
|
2011-05-31 17:51:30 +00:00
|
|
|
# a <ref> tag
|
2011-05-31 17:49:22 +00:00
|
|
|
if ( $this->mInCite || $this->mInReferences ) {
|
2008-06-16 14:04:39 +00:00
|
|
|
return true;
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mGroupCnt = array();
|
2012-10-17 22:58:55 +00:00
|
|
|
$this->mOutCnt = 0;
|
2011-03-04 11:45:22 +00:00
|
|
|
$this->mCallCnt = 0;
|
2008-06-06 20:38:04 +00:00
|
|
|
$this->mRefs = array();
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mReferencesErrors = array();
|
|
|
|
$this->mRefCallStack = array();
|
2008-06-06 20:38:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-15 00:11:20 +00:00
|
|
|
/**
|
|
|
|
* Gets run when the parser is cloned.
|
|
|
|
*
|
|
|
|
* @param $parser Parser
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function cloneState( $parser ) {
|
|
|
|
if ( $parser->extCite !== $this ) {
|
|
|
|
return $parser->extCite->cloneState( $parser );
|
|
|
|
}
|
|
|
|
|
|
|
|
$parser->extCite = clone $this;
|
|
|
|
$parser->setHook( 'ref' , array( $parser->extCite, 'ref' ) );
|
|
|
|
$parser->setHook( 'references' , array( $parser->extCite, 'references' ) );
|
2013-04-16 19:38:05 +00:00
|
|
|
|
|
|
|
// Clear the state, making sure it will actually work.
|
|
|
|
$parser->extCite->mInCite = false;
|
|
|
|
$parser->extCite->mInReferences = false;
|
2012-11-15 00:11:20 +00:00
|
|
|
$parser->extCite->clearState( $parser );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-26 18:02:28 +00:00
|
|
|
/**
|
2011-02-22 00:07:21 +00:00
|
|
|
* Called at the end of page processing to append an error if refs were
|
2009-01-26 18:02:28 +00:00
|
|
|
* used without a references tag.
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2012-06-17 00:34:38 +00:00
|
|
|
* @param $afterParse bool true if called from the ParserAfterParse hook
|
2011-05-28 20:44:24 +00:00
|
|
|
* @param $parser Parser
|
|
|
|
* @param $text string
|
|
|
|
*
|
|
|
|
* @return bool
|
2009-01-26 18:02:28 +00:00
|
|
|
*/
|
2012-06-17 00:34:38 +00:00
|
|
|
function checkRefsNoReferences( $afterParse, &$parser, &$text ) {
|
2011-05-31 17:49:22 +00:00
|
|
|
if ( $parser->extCite !== $this ) {
|
2012-06-17 00:34:38 +00:00
|
|
|
return $parser->extCite->checkRefsNoReferences( $afterParse, $parser, $text );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $afterParse ) {
|
|
|
|
$this->mHaveAfterParse = true;
|
|
|
|
} elseif ( $this->mHaveAfterParse ) {
|
|
|
|
return true;
|
2011-05-31 17:49:22 +00:00
|
|
|
}
|
2011-09-14 15:07:20 +00:00
|
|
|
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( $parser->getOptions()->getIsSectionPreview() ) {
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-26 18:02:28 +00:00
|
|
|
|
|
|
|
foreach ( $this->mRefs as $group => $refs ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( count( $refs ) == 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-01-26 18:02:28 +00:00
|
|
|
if ( $group == CITE_DEFAULT_GROUP ) {
|
2014-06-23 21:42:17 +00:00
|
|
|
$text .= $this->referencesFormat( $group, '', '' );
|
2009-01-26 18:02:28 +00:00
|
|
|
} else {
|
2014-06-23 21:42:17 +00:00
|
|
|
$text .= "\n<br />" . $this->error( 'cite_error_group_refs_without_references', htmlspecialchars( $group ) );
|
2009-01-26 18:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-14 15:07:20 +00:00
|
|
|
|
2011-02-27 14:50:56 +00:00
|
|
|
/**
|
2011-03-04 11:45:22 +00:00
|
|
|
* Hook for the InlineEditor extension. If any ref or reference reference tag is in the text, the entire
|
2011-02-27 14:50:56 +00:00
|
|
|
* page should be reparsed, so we return false in that case.
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
|
|
|
* @param $output
|
2011-09-14 15:07:20 +00:00
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @return bool
|
2011-02-27 14:50:56 +00:00
|
|
|
*/
|
2011-03-04 11:45:22 +00:00
|
|
|
function checkAnyCalls( &$output ) {
|
2011-05-31 17:49:22 +00:00
|
|
|
global $wgParser;
|
|
|
|
/* InlineEditor always uses $wgParser */
|
|
|
|
return ( $wgParser->extCite->mCallCnt <= 0 );
|
2011-02-27 14:50:56 +00:00
|
|
|
}
|
2009-01-26 18:02:28 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Initialize the parser hooks
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
|
|
|
* @param $parser Parser
|
|
|
|
*
|
|
|
|
* @return bool
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2011-02-26 22:39:53 +00:00
|
|
|
static function setHooks( $parser ) {
|
|
|
|
global $wgHooks;
|
2009-02-11 06:34:39 +00:00
|
|
|
|
2011-05-31 17:49:22 +00:00
|
|
|
$parser->extCite = new self();
|
2011-09-14 15:07:20 +00:00
|
|
|
|
2011-05-31 17:49:22 +00:00
|
|
|
if ( !Cite::$hooksInstalled ) {
|
|
|
|
$wgHooks['ParserClearState'][] = array( $parser->extCite, 'clearState' );
|
2012-11-15 00:11:20 +00:00
|
|
|
$wgHooks['ParserCloned'][] = array( $parser->extCite, 'cloneState' );
|
2012-06-17 00:34:38 +00:00
|
|
|
$wgHooks['ParserAfterParse'][] = array( $parser->extCite, 'checkRefsNoReferences', true );
|
|
|
|
$wgHooks['ParserBeforeTidy'][] = array( $parser->extCite, 'checkRefsNoReferences', false );
|
2011-05-31 17:49:22 +00:00
|
|
|
$wgHooks['InlineEditorPartialAfterParse'][] = array( $parser->extCite, 'checkAnyCalls' );
|
|
|
|
Cite::$hooksInstalled = true;
|
2011-02-26 22:39:53 +00:00
|
|
|
}
|
2011-05-31 17:49:22 +00:00
|
|
|
$parser->setHook( 'ref' , array( $parser->extCite, 'ref' ) );
|
|
|
|
$parser->setHook( 'references' , array( $parser->extCite, 'references' ) );
|
2011-02-26 22:39:53 +00:00
|
|
|
|
|
|
|
return true;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an error message based on an error ID
|
|
|
|
*
|
|
|
|
* @param string $key Message name for the error
|
|
|
|
* @param string $param Parameter to pass to the message
|
2011-11-14 12:22:07 +00:00
|
|
|
* @param string $parse Whether to parse the message ('parse') or not ('noparse')
|
|
|
|
* @return string XHTML or wikitext ready for output
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2011-11-14 12:22:07 +00:00
|
|
|
function error( $key, $param = null, $parse = 'parse' ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
# We rely on the fact that PHP is okay with passing unused argu-
|
2012-08-30 08:41:27 +00:00
|
|
|
# ments to functions. If $1 is not used in the message, wfMessage will
|
2008-06-06 20:38:04 +00:00
|
|
|
# just ignore the extra parameter.
|
2013-07-10 21:48:31 +00:00
|
|
|
$ret = '<strong class="error mw-ext-cite-error">' .
|
2013-10-16 04:38:45 +00:00
|
|
|
wfMessage( 'cite_error', wfMessage( $key, $param )->inContentLanguage()->plain() )->inContentLanguage()->plain() .
|
2011-11-14 12:22:07 +00:00
|
|
|
'</strong>';
|
|
|
|
if ( $parse == 'parse' ) {
|
2014-06-05 17:51:48 +00:00
|
|
|
$ret = $this->mParser->recursiveTagParse( $ret );
|
2011-11-14 12:22:07 +00:00
|
|
|
}
|
|
|
|
return $ret;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**#@-*/
|
|
|
|
}
|