2008-06-06 20:38:04 +00:00
|
|
|
<?php
|
|
|
|
|
2016-09-21 11:01:25 +00:00
|
|
|
/**
|
2008-06-06 20:38:04 +00:00
|
|
|
* 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
|
|
|
*
|
2016-09-21 11:01:25 +00:00
|
|
|
* Documentation
|
2018-10-30 12:08:46 +00:00
|
|
|
* @link https://www.mediawiki.org/wiki/Extension:Cite/Cite.php
|
2016-09-21 11:01:25 +00:00
|
|
|
*
|
|
|
|
* <cite> definition in HTML
|
|
|
|
* @link http://www.w3.org/TR/html4/struct/text.html#edef-CITE
|
|
|
|
*
|
|
|
|
* <cite> definition in XHTML 2.0
|
|
|
|
* @link http://www.w3.org/TR/2005/WD-xhtml2-20050527/mod-text.html#edef_text_cite
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
2016-09-29 14:19:16 +00:00
|
|
|
* @bug https://phabricator.wikimedia.org/T6579
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
|
|
|
* @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
|
|
|
|
* @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
|
2017-12-29 12:12:35 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
|
|
|
|
2017-12-25 13:17:20 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-12-22 20:28:29 +00:00
|
|
|
|
2008-08-08 19:11:31 +00:00
|
|
|
class Cite {
|
2015-04-30 18:34:47 +00:00
|
|
|
|
2019-10-17 07:21:22 +00:00
|
|
|
private const DEFAULT_GROUP = '';
|
2015-04-30 18:34:47 +00:00
|
|
|
|
2016-01-25 16:52:46 +00:00
|
|
|
/**
|
2019-10-17 07:21:22 +00:00
|
|
|
* Maximum storage capacity for the pp_value field of the page_props table. 2^16-1 = 65535 is
|
|
|
|
* the size of a MySQL 'blob' field.
|
2016-01-25 16:52:46 +00:00
|
|
|
* @todo Find a way to retrieve this information from the DBAL
|
|
|
|
*/
|
2019-10-17 07:21:22 +00:00
|
|
|
public const MAX_STORAGE_LENGTH = 65535;
|
2016-01-25 16:52:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Key used for storage in parser output's ExtensionData and ObjectCache
|
|
|
|
*/
|
2019-10-17 07:21:22 +00:00
|
|
|
public const EXT_DATA_KEY = 'Cite:References';
|
2016-01-25 16:52:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Version number in case we change the data structure in the future
|
|
|
|
*/
|
2019-10-17 07:21:22 +00:00
|
|
|
private const DATA_VERSION_NUMBER = 1;
|
2016-01-25 16:52:46 +00:00
|
|
|
|
|
|
|
/**
|
2019-10-17 07:21:22 +00:00
|
|
|
* Cache duration when parsing a page with references, in seconds. 3,600 seconds = 1 hour.
|
2016-01-25 16:52:46 +00:00
|
|
|
*/
|
2019-10-17 07:21:22 +00:00
|
|
|
public const CACHE_DURATION_ONPARSE = 3600;
|
2016-01-25 16:52:46 +00:00
|
|
|
|
2019-10-24 09:23:44 +00:00
|
|
|
/**
|
|
|
|
* Wikitext attribute name for Book Referencing.
|
|
|
|
*/
|
2019-11-12 10:03:44 +00:00
|
|
|
public const BOOK_REF_ATTRIBUTE = 'extends';
|
2019-10-24 09:23:44 +00:00
|
|
|
|
2019-11-08 11:59:09 +00:00
|
|
|
/**
|
|
|
|
* Page property key for the Book Referencing `extends` attribute.
|
|
|
|
*/
|
|
|
|
public const BOOK_REF_PROPERTY = 'ref-extends';
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
|
|
|
* Datastructure representing <ref> input, in the format of:
|
|
|
|
* <code>
|
2017-01-07 09:08:35 +00:00
|
|
|
* [
|
|
|
|
* 'user supplied' => [
|
2008-06-06 20:38:04 +00:00
|
|
|
* '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
|
2017-01-07 09:08:35 +00:00
|
|
|
* ],
|
2008-06-06 20:38:04 +00:00
|
|
|
* 0 => 'Anonymous reference',
|
|
|
|
* 1 => 'Another anonymous reference',
|
2017-01-07 09:08:35 +00:00
|
|
|
* 'some key' => [
|
2008-06-06 20:38:04 +00:00
|
|
|
* 'text' => 'this one occurs once'
|
|
|
|
* 'count' => 0,
|
|
|
|
* 'number' => 4
|
2017-01-07 09:08:35 +00:00
|
|
|
* ],
|
2008-06-06 20:38:04 +00:00
|
|
|
* 3 => 'more stuff'
|
2017-01-07 09:08:35 +00:00
|
|
|
* ];
|
2008-06-06 20:38:04 +00:00
|
|
|
* </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
|
|
|
|
*
|
2016-09-21 11:01:25 +00:00
|
|
|
* @var array[]
|
|
|
|
*/
|
|
|
|
private $mRefs = [];
|
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
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mOutCnt = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int[]
|
|
|
|
*/
|
|
|
|
private $mGroupCnt = [];
|
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
|
|
|
|
*
|
2016-09-21 11:01:25 +00:00
|
|
|
* @var string[]
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mBacklinkLabels;
|
2010-05-22 14:28:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The links to use per group, in order.
|
|
|
|
*
|
2018-11-19 15:39:34 +00:00
|
|
|
* @var (string[]|false)[]
|
2010-05-22 14:28:48 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mLinkLabels = [];
|
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
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mParser;
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2015-06-08 14:05:06 +00:00
|
|
|
/**
|
|
|
|
* True when the ParserAfterParse hook has been called.
|
|
|
|
* Used to avoid doing anything in ParserBeforeTidy.
|
|
|
|
*
|
2019-10-25 08:34:35 +00:00
|
|
|
* @var bool
|
2015-06-08 14:05:06 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mHaveAfterParse = false;
|
2015-06-08 14:05:06 +00:00
|
|
|
|
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
|
|
|
*
|
2019-10-25 08:34:35 +00:00
|
|
|
* @var bool
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2014-08-17 21:04:15 +00:00
|
|
|
public $mInCite = false;
|
2009-07-26 22:15:13 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-08 14:05:06 +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
|
|
|
*
|
2019-10-25 08:34:35 +00:00
|
|
|
* @var bool
|
2009-07-26 22:15:13 +00:00
|
|
|
*/
|
2015-06-08 14:05:06 +00:00
|
|
|
public $mInReferences = false;
|
2009-07-26 22:15:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Error stack used when defining refs in <references>
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2016-09-21 11:01:25 +00:00
|
|
|
* @var string[]
|
2009-07-26 22:15:13 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mReferencesErrors = [];
|
2009-07-26 22:15:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Group used when in <references> block
|
2011-02-22 00:07:21 +00:00
|
|
|
*
|
2009-07-26 22:15:13 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mReferencesGroup = '';
|
2009-07-26 22:15:13 +00:00
|
|
|
|
2015-06-08 14:05:06 +00:00
|
|
|
/**
|
|
|
|
* <ref> call stack
|
|
|
|
* Used to cleanup out of sequence ref calls created by #tag
|
|
|
|
* See description of function rollbackRef.
|
|
|
|
*
|
2018-11-19 15:39:34 +00:00
|
|
|
* @var (array|false)[]
|
2015-06-08 14:05:06 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private $mRefCallStack = [];
|
2015-06-08 14:05:06 +00:00
|
|
|
|
2016-01-25 16:52:46 +00:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $mBumpRefData = false;
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
2015-06-08 14:05:06 +00:00
|
|
|
* Callback function for <ref>
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
2019-11-05 09:28:20 +00:00
|
|
|
* @param string|null $text Raw content of the <ref> tag.
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string[] $argv Arguments
|
|
|
|
* @param Parser $parser
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2019-11-12 12:06:39 +00:00
|
|
|
* @return string|false False in case a <ref> tag is not allowed in the current context
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2019-11-12 12:06:39 +00:00
|
|
|
public function ref( $text, array $argv, Parser $parser ) {
|
2015-06-08 14:05:06 +00:00
|
|
|
if ( $this->mInCite ) {
|
2019-11-12 12:06:39 +00:00
|
|
|
return false;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
2014-10-01 14:25:58 +00:00
|
|
|
|
2019-11-11 19:16:05 +00:00
|
|
|
$this->mParser = $parser;
|
2014-10-01 14:25:58 +00:00
|
|
|
$this->mInCite = true;
|
|
|
|
|
2019-11-05 09:28:20 +00:00
|
|
|
$ret = $this->guardedRef( $text, $argv, $parser );
|
2014-10-01 14:25:58 +00:00
|
|
|
|
|
|
|
$this->mInCite = false;
|
|
|
|
|
2016-01-25 16:52:46 +00:00
|
|
|
// new <ref> tag, we may need to bump the ref data counter
|
|
|
|
// to avoid overwriting a previous group
|
|
|
|
$this->mBumpRefData = true;
|
|
|
|
|
2015-06-08 14:05:06 +00:00
|
|
|
return $ret;
|
2014-12-19 18:38:37 +00:00
|
|
|
}
|
|
|
|
|
2011-05-28 20:44:24 +00:00
|
|
|
/**
|
2019-11-05 09:28:20 +00:00
|
|
|
* @param string|null $text Raw content of the <ref> tag.
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string[] $argv Arguments
|
|
|
|
* @param Parser $parser
|
|
|
|
*
|
|
|
|
* @throws Exception
|
2011-05-28 20:44:24 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function guardedRef(
|
2019-11-05 09:28:20 +00:00
|
|
|
$text,
|
2016-09-20 13:59:58 +00:00
|
|
|
array $argv,
|
2018-11-19 15:24:21 +00:00
|
|
|
Parser $parser
|
2016-09-20 13:59:58 +00:00
|
|
|
) {
|
2008-06-06 20:38:04 +00:00
|
|
|
# The key here is the "name" attribute.
|
2019-11-12 10:03:44 +00:00
|
|
|
list( $key, $group, $follow, $dir, $extends ) = $this->refArg( $argv );
|
2012-05-15 18:31:23 +00:00
|
|
|
// empty string indicate invalid dir
|
2019-11-05 09:28:20 +00:00
|
|
|
if ( $dir === '' && $text !== '' ) {
|
|
|
|
$text .= $this->plainError( 'cite_error_ref_invalid_dir', $argv['dir'] );
|
2012-05-15 18:31:23 +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 ) {
|
2019-11-04 15:04:42 +00:00
|
|
|
$group = $this->mInReferences ? $this->mReferencesGroup : self::DEFAULT_GROUP;
|
2009-07-26 22:15:13 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2019-11-08 11:59:09 +00:00
|
|
|
// Tag every page where Book Referencing has been used. This code and the properties
|
|
|
|
// will be removed once the feature is stable. See T237531.
|
2019-11-12 10:03:44 +00:00
|
|
|
if ( $extends ) {
|
2019-11-08 11:59:09 +00:00
|
|
|
$parser->getOutput()->setProperty( self::BOOK_REF_PROPERTY, true );
|
|
|
|
}
|
|
|
|
|
2015-06-08 14:05:06 +00:00
|
|
|
if ( $this->mInReferences ) {
|
2019-11-04 16:16:07 +00:00
|
|
|
$isSectionPreview = $parser->getOptions()->getIsSectionPreview();
|
|
|
|
$this->inReferencesGuardedRef( $key, $text, $group, $isSectionPreview );
|
2009-07-26 22:15:13 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-11-05 09:28:20 +00:00
|
|
|
if ( $text === '' ) {
|
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.
|
2015-07-07 12:26:35 +00:00
|
|
|
if ( is_string( $key ) && $key !== '' ) {
|
2019-11-05 09:28:20 +00:00
|
|
|
$text = null;
|
2015-07-07 12:26:35 +00:00
|
|
|
} else {
|
2015-06-08 14:05:06 +00:00
|
|
|
$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
|
|
|
}
|
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 ) {
|
2019-11-01 14:15:26 +00:00
|
|
|
# Invalid attribute in the tag like <ref no_valid_attr="foo" />
|
|
|
|
# or name and follow attribute used both in one tag checked in
|
|
|
|
# Cite::refArg that returns false for the key then.
|
2015-06-08 14:05:06 +00:00
|
|
|
$this->mRefCallStack[] = false;
|
2008-06-06 20:38:04 +00:00
|
|
|
return $this->error( 'cite_error_ref_too_many_keys' );
|
|
|
|
}
|
|
|
|
|
2019-11-05 09:28:20 +00:00
|
|
|
if ( $text === null && $key === null ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
# Something like <ref />; this makes no sense.
|
2015-06-08 14:05:06 +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
|
|
|
|
2019-10-25 08:10:57 +00:00
|
|
|
if ( ctype_digit( $key ) || ctype_digit( $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
|
|
|
|
2015-06-08 14:05:06 +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[^<]*?>/',
|
2019-11-05 09:28:20 +00:00
|
|
|
preg_replace( '#<([^ ]+?).*?>.*?</\\1 *>|<!--.*?-->#', '', $text )
|
2008-09-18 17:21:13 +00:00
|
|
|
) ) {
|
2015-12-16 13:03:54 +00:00
|
|
|
# (bug T8199) This most likely implies that someone left off the
|
2008-09-18 17:16:10 +00:00
|
|
|
# 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.
|
2015-12-16 13:03:54 +00:00
|
|
|
|
2008-09-18 17:16:10 +00:00
|
|
|
# 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
|
|
|
|
2015-06-08 14:05:06 +00:00
|
|
|
$this->mRefCallStack[] = false;
|
2008-09-18 17:16:10 +00:00
|
|
|
return $this->error( 'cite_error_included_ref' );
|
|
|
|
}
|
|
|
|
|
2019-11-05 09:28:20 +00:00
|
|
|
if ( is_string( $key ) || is_string( $text ) ) {
|
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
|
|
|
|
2019-11-04 16:16:07 +00:00
|
|
|
return $this->stack( $text, $key, $group, $follow, $argv, $dir, $parser->getStripState() );
|
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.
|
2019-11-05 09:28:20 +00:00
|
|
|
throw new Exception( 'Invalid $text and/or $key: ' . serialize( [ $text, $key ] ) );
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
2019-11-01 14:29:33 +00:00
|
|
|
/**
|
|
|
|
* Deals with references defined in the reference section
|
|
|
|
* <references>
|
|
|
|
* <ref name="foo"> BAR </ref>
|
|
|
|
* </references>
|
|
|
|
*
|
2019-11-05 12:03:32 +00:00
|
|
|
* @param string|false|null $key
|
|
|
|
* @param string|null $text Content from the <ref> tag
|
2019-11-01 14:29:33 +00:00
|
|
|
* @param string $group
|
2019-11-04 16:16:07 +00:00
|
|
|
* @param bool $isSectionPreview
|
2019-11-01 14:29:33 +00:00
|
|
|
*/
|
2019-11-04 16:16:07 +00:00
|
|
|
private function inReferencesGuardedRef( $key, $text, $group, $isSectionPreview ) {
|
2019-11-01 14:29:33 +00:00
|
|
|
if ( $group != $this->mReferencesGroup ) {
|
|
|
|
# <ref> and <references> have conflicting group attributes.
|
|
|
|
$this->mReferencesErrors[] =
|
|
|
|
$this->error(
|
|
|
|
'cite_error_references_group_mismatch',
|
|
|
|
Sanitizer::safeEncodeAttribute( $group )
|
|
|
|
);
|
2019-11-05 09:28:20 +00:00
|
|
|
} elseif ( $text !== '' ) {
|
2019-11-01 14:29:33 +00:00
|
|
|
if ( !$isSectionPreview && !isset( $this->mRefs[$group] ) ) {
|
|
|
|
# Called with group attribute not defined in text.
|
|
|
|
$this->mReferencesErrors[] =
|
|
|
|
$this->error(
|
|
|
|
'cite_error_references_missing_group',
|
|
|
|
Sanitizer::safeEncodeAttribute( $group )
|
|
|
|
);
|
|
|
|
} elseif ( $key === null || $key === '' ) {
|
|
|
|
# <ref> calls inside <references> must be named
|
|
|
|
$this->mReferencesErrors[] =
|
|
|
|
$this->error( 'cite_error_references_no_key' );
|
|
|
|
} elseif ( !$isSectionPreview && !isset( $this->mRefs[$group][$key] ) ) {
|
|
|
|
# Called with name attribute not defined in text.
|
|
|
|
$this->mReferencesErrors[] =
|
|
|
|
$this->error( 'cite_error_references_missing_key', Sanitizer::safeEncodeAttribute( $key ) );
|
|
|
|
} else {
|
|
|
|
if (
|
|
|
|
isset( $this->mRefs[$group][$key]['text'] ) &&
|
2019-11-05 09:28:20 +00:00
|
|
|
$text !== $this->mRefs[$group][$key]['text']
|
2019-11-01 14:29:33 +00:00
|
|
|
) {
|
|
|
|
// two refs with same key and different content
|
|
|
|
// add error message to the original ref
|
|
|
|
$this->mRefs[$group][$key]['text'] .= ' ' . $this->plainError(
|
|
|
|
'cite_error_references_duplicate_key', $key
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
# Assign the text to corresponding ref
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->mRefs[$group][$key]['text'] = $text;
|
2019-11-01 14:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# <ref> called in <references> has no content.
|
|
|
|
$this->mReferencesErrors[] =
|
|
|
|
$this->error( 'cite_error_empty_references_define', Sanitizer::safeEncodeAttribute( $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.
|
2012-05-15 18:31:23 +00:00
|
|
|
* "dir" : set direction of text (ltr/rtl)
|
2019-11-12 10:03:44 +00:00
|
|
|
* "extends": Points to a named reference which serves as the context for this reference.
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string[] $argv The argument vector
|
2018-11-19 15:29:16 +00:00
|
|
|
* @return (string|false|null)[] An array with exactly four elements, where each is a string on
|
|
|
|
* valid input, false on invalid input, or null on no input.
|
2018-09-13 00:32:00 +00:00
|
|
|
* @return-taint tainted
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function refArg( array $argv ) {
|
2019-10-24 09:23:44 +00:00
|
|
|
global $wgCiteBookReferencing;
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
$group = null;
|
|
|
|
$key = null;
|
2010-08-16 12:05:57 +00:00
|
|
|
$follow = null;
|
2012-05-15 18:31:23 +00:00
|
|
|
$dir = null;
|
2019-11-12 10:03:44 +00:00
|
|
|
$extends = null;
|
2018-11-19 15:29:16 +00:00
|
|
|
|
2012-05-15 18:31:23 +00:00
|
|
|
if ( isset( $argv['dir'] ) ) {
|
|
|
|
// compare the dir attribute value against an explicit whitelist.
|
|
|
|
$dir = '';
|
|
|
|
$isValidDir = in_array( strtolower( $argv['dir'] ), [ 'ltr', 'rtl' ] );
|
|
|
|
if ( $isValidDir ) {
|
|
|
|
$dir = Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . strtolower( $argv['dir'] ) ] );
|
|
|
|
}
|
2008-06-06 20:38:04 +00:00
|
|
|
|
2012-05-15 18:31:23 +00:00
|
|
|
unset( $argv['dir'] );
|
|
|
|
}
|
2018-11-19 15:29:16 +00:00
|
|
|
|
|
|
|
if ( $argv === [] ) {
|
|
|
|
// No key
|
2019-11-08 11:30:12 +00:00
|
|
|
return [ null, null, false, $dir, null ];
|
2018-11-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
2019-11-05 15:02:12 +00:00
|
|
|
if ( isset( $argv['follow'] ) &&
|
2019-11-12 10:03:44 +00:00
|
|
|
( isset( $argv['name'] ) || isset( $argv[self::BOOK_REF_ATTRIBUTE] ) )
|
2019-11-05 15:02:12 +00:00
|
|
|
) {
|
2019-11-08 11:30:12 +00:00
|
|
|
return [ false, false, false, false, false ];
|
2018-11-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $argv['name'] ) ) {
|
|
|
|
// Key given.
|
|
|
|
$key = trim( $argv['name'] );
|
|
|
|
unset( $argv['name'] );
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
2018-11-19 15:29:16 +00:00
|
|
|
if ( isset( $argv['follow'] ) ) {
|
|
|
|
// Follow given.
|
|
|
|
$follow = trim( $argv['follow'] );
|
|
|
|
unset( $argv['follow'] );
|
|
|
|
}
|
|
|
|
if ( isset( $argv['group'] ) ) {
|
|
|
|
// Group given.
|
|
|
|
$group = $argv['group'];
|
|
|
|
unset( $argv['group'] );
|
|
|
|
}
|
2019-11-12 10:03:44 +00:00
|
|
|
if ( $wgCiteBookReferencing && isset( $argv[self::BOOK_REF_ATTRIBUTE] ) ) {
|
|
|
|
$extends = trim( $argv[self::BOOK_REF_ATTRIBUTE] );
|
|
|
|
unset( $argv[self::BOOK_REF_ATTRIBUTE] );
|
2019-10-24 09:23:44 +00:00
|
|
|
}
|
2018-11-19 15:29:16 +00:00
|
|
|
|
|
|
|
if ( $argv !== [] ) {
|
2019-11-01 14:15:26 +00:00
|
|
|
// Unexpected invalid attribute.
|
2019-11-08 11:30:12 +00:00
|
|
|
return [ false, false, false, false, false ];
|
2018-11-19 15:29:16 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 10:03:44 +00:00
|
|
|
return [ $key, $group, $follow, $dir, $extends ];
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate $this->mRefs based on input and arguments to <ref>
|
|
|
|
*
|
2019-11-05 09:28:20 +00:00
|
|
|
* @param string|null $text Content from the <ref> tag
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string|null $key Argument to the <ref> tag as returned by $this->refArg()
|
|
|
|
* @param string $group
|
|
|
|
* @param string|null $follow
|
|
|
|
* @param string[] $call
|
2018-10-14 05:43:17 +00:00
|
|
|
* @param string $dir ref direction
|
2019-11-04 16:16:07 +00:00
|
|
|
* @param StripState $stripState
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2015-10-26 14:44:02 +00:00
|
|
|
* @throws Exception
|
2011-02-22 00:07:21 +00:00
|
|
|
* @return string
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2019-11-04 16:16:07 +00:00
|
|
|
private function stack( $text, $key, $group, $follow, array $call, $dir, StripState $stripState ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
if ( !isset( $this->mRefs[$group] ) ) {
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mRefs[$group] = [];
|
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
|
|
|
}
|
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
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->mRefs[$group][$follow]['text'] .= ' ' . $text;
|
2010-08-16 12:05:57 +00:00
|
|
|
} else {
|
|
|
|
// insert part of note at the beginning of the group
|
2014-09-27 16:49:28 +00:00
|
|
|
$groupsCount = count( $this->mRefs[$group] );
|
|
|
|
for ( $k = 0; $k < $groupsCount; $k++ ) {
|
2015-01-09 00:05:13 +00:00
|
|
|
if ( !isset( $this->mRefs[$group][$k]['follow'] ) ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-08-16 12:05:57 +00:00
|
|
|
}
|
2016-05-09 23:36:49 +00:00
|
|
|
array_splice( $this->mRefs[$group], $k, 0, [ [
|
2015-10-26 14:44:02 +00:00
|
|
|
'count' => -1,
|
2019-11-05 09:28:20 +00:00
|
|
|
'text' => $text,
|
2015-10-26 14:44:02 +00:00
|
|
|
'key' => ++$this->mOutCnt,
|
2012-05-15 18:31:23 +00:00
|
|
|
'follow' => $follow,
|
|
|
|
'dir' => $dir
|
2016-05-09 23:36:49 +00:00
|
|
|
] ] );
|
2015-06-08 14:05:06 +00:00
|
|
|
array_splice( $this->mRefCallStack, $k, 0,
|
2019-11-05 09:28:20 +00:00
|
|
|
[ [ 'new', $call, $text, $key, $group, $this->mOutCnt ] ] );
|
2010-08-16 12:05:57 +00:00
|
|
|
}
|
|
|
|
// return an empty string : this is not a reference
|
|
|
|
return '';
|
|
|
|
}
|
2015-07-18 20:55:32 +00:00
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
if ( $key === null ) {
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mRefs[$group][] = [
|
2015-10-26 14:44:02 +00:00
|
|
|
'count' => -1,
|
2019-11-05 09:28:20 +00:00
|
|
|
'text' => $text,
|
2012-05-15 18:31:23 +00:00
|
|
|
'key' => ++$this->mOutCnt,
|
|
|
|
'dir' => $dir
|
2016-05-09 23:36:49 +00:00
|
|
|
];
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->mRefCallStack[] = [ 'new', $call, $text, $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 );
|
2015-07-18 20:55:32 +00:00
|
|
|
}
|
|
|
|
if ( !is_string( $key ) ) {
|
2015-01-10 01:47:47 +00:00
|
|
|
throw new Exception( 'Invalid stack key: ' . serialize( $key ) );
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
2015-07-18 20:55:32 +00:00
|
|
|
|
2019-10-24 12:38:46 +00:00
|
|
|
// Valid key with first occurrence
|
2015-07-18 20:55:32 +00:00
|
|
|
if ( !isset( $this->mRefs[$group][$key] ) || !is_array( $this->mRefs[$group][$key] ) ) {
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mRefs[$group][$key] = [
|
2019-11-05 09:28:20 +00:00
|
|
|
'text' => $text,
|
2015-07-18 20:55:32 +00:00
|
|
|
'count' => 0,
|
|
|
|
'key' => ++$this->mOutCnt,
|
2012-05-15 18:31:23 +00:00
|
|
|
'number' => ++$this->mGroupCnt[$group],
|
|
|
|
'dir' => $dir
|
2016-05-09 23:36:49 +00:00
|
|
|
];
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->mRefCallStack[] = [ 'new', $call, $text, $key, $group, $this->mOutCnt ];
|
2015-07-18 20:55:32 +00:00
|
|
|
|
|
|
|
return $this->linkRef(
|
|
|
|
$group,
|
|
|
|
$key,
|
|
|
|
$this->mRefs[$group][$key]['key'] . "-" . $this->mRefs[$group][$key]['count'],
|
|
|
|
$this->mRefs[$group][$key]['number'],
|
|
|
|
"-" . $this->mRefs[$group][$key]['key']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-24 12:38:46 +00:00
|
|
|
// Valid key that is already known
|
2019-11-05 09:28:20 +00:00
|
|
|
if ( $this->mRefs[$group][$key]['text'] === null && $text !== '' ) {
|
2019-10-24 12:38:46 +00:00
|
|
|
// If no text was set before, use this text
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->mRefs[$group][$key]['text'] = $text;
|
2018-08-22 22:27:23 +00:00
|
|
|
// Use the dir parameter only from the full definition of a named ref tag
|
|
|
|
$this->mRefs[$group][$key]['dir'] = $dir;
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->mRefCallStack[] = [ 'assign', $call, $text, $key, $group,
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mRefs[$group][$key]['key'] ];
|
2015-07-18 20:55:32 +00:00
|
|
|
} else {
|
2019-11-05 09:28:20 +00:00
|
|
|
if ( $text != null && $text !== ''
|
2018-10-14 05:43:17 +00:00
|
|
|
// T205803 different strip markers might hide the same text
|
2019-11-04 16:16:07 +00:00
|
|
|
&& $stripState->unstripBoth( $text )
|
|
|
|
!== $stripState->unstripBoth( $this->mRefs[$group][$key]['text'] )
|
2018-10-14 05:43:17 +00:00
|
|
|
) {
|
2019-10-24 12:38:46 +00:00
|
|
|
// two refs with same key and different text
|
2015-10-07 15:32:28 +00:00
|
|
|
// add error message to the original ref
|
2018-09-13 00:32:00 +00:00
|
|
|
$this->mRefs[$group][$key]['text'] .= ' ' . $this->plainError(
|
|
|
|
'cite_error_references_duplicate_key', $key
|
2015-12-16 13:03:54 +00:00
|
|
|
);
|
2015-07-23 01:57:34 +00:00
|
|
|
}
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->mRefCallStack[] = [ 'increment', $call, $text, $key, $group,
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mRefs[$group][$key]['key'] ];
|
2015-07-18 20:55:32 +00:00
|
|
|
}
|
|
|
|
return $this->linkRef(
|
|
|
|
$group,
|
|
|
|
$key,
|
|
|
|
$this->mRefs[$group][$key]['key'] . "-" . ++$this->mRefs[$group][$key]['count'],
|
|
|
|
$this->mRefs[$group][$key]['number'],
|
|
|
|
"-" . $this->mRefs[$group][$key]['key']
|
|
|
|
);
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2009-07-26 22:15:13 +00:00
|
|
|
/**
|
2015-06-08 14:05:06 +00:00
|
|
|
* Partially undoes the effect of calls to stack()
|
|
|
|
*
|
|
|
|
* Called by guardedReferences()
|
|
|
|
*
|
|
|
|
* The option to define <ref> within <references> makes the
|
|
|
|
* 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.
|
|
|
|
*
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string $type
|
|
|
|
* @param string|null $key
|
|
|
|
* @param string $group
|
|
|
|
* @param int $index
|
2015-06-08 14:05:06 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function rollbackRef( $type, $key, $group, $index ) {
|
2015-06-08 14:05:06 +00:00
|
|
|
if ( !isset( $this->mRefs[$group] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $key === null ) {
|
|
|
|
foreach ( $this->mRefs[$group] as $k => $v ) {
|
|
|
|
if ( $this->mRefs[$group][$k]['key'] === $index ) {
|
|
|
|
$key = $k;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-18 20:55:32 +00:00
|
|
|
// Sanity checks that specified element exists.
|
2019-11-04 15:04:42 +00:00
|
|
|
if ( $key === null ||
|
|
|
|
!isset( $this->mRefs[$group][$key] ) ||
|
|
|
|
$this->mRefs[$group][$key]['key'] !== $index
|
|
|
|
) {
|
2015-06-08 14:05:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( $type ) {
|
|
|
|
case 'new':
|
|
|
|
# Rollback the addition of new elements to the stack.
|
|
|
|
unset( $this->mRefs[$group][$key] );
|
2016-05-09 23:36:49 +00:00
|
|
|
if ( $this->mRefs[$group] === [] ) {
|
2015-06-08 14:05:06 +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':
|
|
|
|
# Rollback increase in named ref occurrences.
|
|
|
|
$this->mRefs[$group][$key]['count']--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback function for <references>
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
2019-11-05 09:28:20 +00:00
|
|
|
* @param string|null $text Raw content of the <references> tag.
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string[] $argv Arguments
|
|
|
|
* @param Parser $parser
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2019-11-12 12:06:39 +00:00
|
|
|
* @return string|false False in case a <references> tag is not allowed in the current context
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2019-11-12 12:06:39 +00:00
|
|
|
public function references( $text, array $argv, Parser $parser ) {
|
2015-06-08 14:05:06 +00:00
|
|
|
if ( $this->mInCite || $this->mInReferences ) {
|
2019-11-12 12:06:39 +00:00
|
|
|
return false;
|
2015-07-18 20:55:32 +00:00
|
|
|
}
|
2019-11-11 19:16:05 +00:00
|
|
|
|
|
|
|
$this->mParser = $parser;
|
2015-07-18 20:55:32 +00:00
|
|
|
$this->mInReferences = true;
|
2019-11-05 09:28:20 +00:00
|
|
|
$ret = $this->guardedReferences( $text, $argv, $parser );
|
2015-07-18 20:55:32 +00:00
|
|
|
$this->mInReferences = false;
|
2019-11-11 19:16:05 +00:00
|
|
|
|
2015-07-18 20:55:32 +00:00
|
|
|
return $ret;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
2011-05-28 20:44:24 +00:00
|
|
|
/**
|
2018-07-24 23:08:25 +00:00
|
|
|
* Must only be called from references(). Use that to prevent recursion.
|
|
|
|
*
|
2019-11-05 09:28:20 +00:00
|
|
|
* @param string|null $text Raw content of the <references> tag.
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string[] $argv
|
|
|
|
* @param Parser $parser
|
2018-11-19 15:24:21 +00:00
|
|
|
*
|
2011-05-28 20:44:24 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function guardedReferences(
|
2019-11-05 09:28:20 +00:00
|
|
|
$text,
|
2016-09-20 13:59:58 +00:00
|
|
|
array $argv,
|
2018-11-19 15:24:21 +00:00
|
|
|
Parser $parser
|
2016-09-20 13:59:58 +00:00
|
|
|
) {
|
2017-03-22 19:13:22 +00:00
|
|
|
global $wgCiteResponsiveReferences;
|
2008-06-06 20:38:04 +00:00
|
|
|
|
2019-10-25 08:19:08 +00:00
|
|
|
$group = $argv['group'] ?? self::DEFAULT_GROUP;
|
|
|
|
unset( $argv['group'] );
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2019-11-05 09:28:20 +00:00
|
|
|
if ( strval( $text ) !== '' ) {
|
2009-07-26 22:15:13 +00:00
|
|
|
$this->mReferencesGroup = $group;
|
2011-02-22 00:07:21 +00:00
|
|
|
|
Rollback all, then redo all, when fixing out-of-order tags; not one-by-one
Imagine the following wikitext:
<ref name=r/>
<references>
<ref name=r>A</ref>
<ref name=r>B</ref>
</references>
This is simple. Cite would see these as the following operations, in
order:
1. Use only: <ref name=r/>
2. References block
3. Define only: <ref name=r>A</ref>
4. Define only: <ref name=r>B</ref>
<ref name=r> is defined twice with different content and we get an
error message.
Now, imagine the following wikitext:
<ref name=r/>
{{#tag:references|
<ref name=r>A</ref>
<ref name=r>B</ref>
}}
Cite would see these as the following operations, in order:
1. Use only: <ref name=r/>
2. Use and define: <ref name=r>A</ref>
3. Use and define: <ref name=r>B</ref>
4. References block
When the 'references' block appears, Cite notices that the tag has
parsed content, and deduces that it was called with #tag. We need to
undo the last operations to update internal bookkeeping, as the last
two 'ref' tags do not actually represent ref usages, as we assumed,
but only definitions.
5. Undo: <ref name=r> reused
6. Define only: <ref name=r>B</ref>
7. Undo: <ref name=r> defined
(Right now, it appears to Cite that <ref name=r> was never defined!)
8. Define only: <ref name=r>A</ref>
Thus we get no errors, although we should.
This patch changes the order of the rollback operations:
5. Undo: <ref name=r> reused
6. Undo: <ref name=r> defined
7. Define only: <ref name=r>A</ref>
8. Define only: <ref name=r>B</ref>
Aha! <ref name=r> is defined twice with different content! We get an
error correctly.
Bug: T124227
Change-Id: I61766c4104856323987cca9a5e4ff85a76b3618b
2016-01-20 20:38:59 +00:00
|
|
|
# Detect whether we were sent already rendered <ref>s.
|
|
|
|
# Mostly a side effect of using #tag to call references.
|
|
|
|
# The following assumes that the parsed <ref>s sent within
|
|
|
|
# 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.
|
2019-11-05 09:28:20 +00:00
|
|
|
$count = substr_count( $text, Parser::MARKER_PREFIX . "-ref-" );
|
2016-05-09 23:36:49 +00:00
|
|
|
$redoStack = [];
|
Rollback all, then redo all, when fixing out-of-order tags; not one-by-one
Imagine the following wikitext:
<ref name=r/>
<references>
<ref name=r>A</ref>
<ref name=r>B</ref>
</references>
This is simple. Cite would see these as the following operations, in
order:
1. Use only: <ref name=r/>
2. References block
3. Define only: <ref name=r>A</ref>
4. Define only: <ref name=r>B</ref>
<ref name=r> is defined twice with different content and we get an
error message.
Now, imagine the following wikitext:
<ref name=r/>
{{#tag:references|
<ref name=r>A</ref>
<ref name=r>B</ref>
}}
Cite would see these as the following operations, in order:
1. Use only: <ref name=r/>
2. Use and define: <ref name=r>A</ref>
3. Use and define: <ref name=r>B</ref>
4. References block
When the 'references' block appears, Cite notices that the tag has
parsed content, and deduces that it was called with #tag. We need to
undo the last operations to update internal bookkeeping, as the last
two 'ref' tags do not actually represent ref usages, as we assumed,
but only definitions.
5. Undo: <ref name=r> reused
6. Define only: <ref name=r>B</ref>
7. Undo: <ref name=r> defined
(Right now, it appears to Cite that <ref name=r> was never defined!)
8. Define only: <ref name=r>A</ref>
Thus we get no errors, although we should.
This patch changes the order of the rollback operations:
5. Undo: <ref name=r> reused
6. Undo: <ref name=r> defined
7. Define only: <ref name=r>A</ref>
8. Define only: <ref name=r>B</ref>
Aha! <ref name=r> is defined twice with different content! We get an
error correctly.
Bug: T124227
Change-Id: I61766c4104856323987cca9a5e4ff85a76b3618b
2016-01-20 20:38:59 +00:00
|
|
|
|
|
|
|
# Undo effects of calling <ref> while unaware of containing <references>
|
2015-06-08 14:05:06 +00:00
|
|
|
for ( $i = 1; $i <= $count; $i++ ) {
|
2015-07-07 07:37:14 +00:00
|
|
|
if ( !$this->mRefCallStack ) {
|
2015-06-08 14:05:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$call = array_pop( $this->mRefCallStack );
|
Rollback all, then redo all, when fixing out-of-order tags; not one-by-one
Imagine the following wikitext:
<ref name=r/>
<references>
<ref name=r>A</ref>
<ref name=r>B</ref>
</references>
This is simple. Cite would see these as the following operations, in
order:
1. Use only: <ref name=r/>
2. References block
3. Define only: <ref name=r>A</ref>
4. Define only: <ref name=r>B</ref>
<ref name=r> is defined twice with different content and we get an
error message.
Now, imagine the following wikitext:
<ref name=r/>
{{#tag:references|
<ref name=r>A</ref>
<ref name=r>B</ref>
}}
Cite would see these as the following operations, in order:
1. Use only: <ref name=r/>
2. Use and define: <ref name=r>A</ref>
3. Use and define: <ref name=r>B</ref>
4. References block
When the 'references' block appears, Cite notices that the tag has
parsed content, and deduces that it was called with #tag. We need to
undo the last operations to update internal bookkeeping, as the last
two 'ref' tags do not actually represent ref usages, as we assumed,
but only definitions.
5. Undo: <ref name=r> reused
6. Define only: <ref name=r>B</ref>
7. Undo: <ref name=r> defined
(Right now, it appears to Cite that <ref name=r> was never defined!)
8. Define only: <ref name=r>A</ref>
Thus we get no errors, although we should.
This patch changes the order of the rollback operations:
5. Undo: <ref name=r> reused
6. Undo: <ref name=r> defined
7. Define only: <ref name=r>A</ref>
8. Define only: <ref name=r>B</ref>
Aha! <ref name=r> is defined twice with different content! We get an
error correctly.
Bug: T124227
Change-Id: I61766c4104856323987cca9a5e4ff85a76b3618b
2016-01-20 20:38:59 +00:00
|
|
|
$redoStack[] = $call;
|
2015-06-08 14:05:06 +00:00
|
|
|
if ( $call !== false ) {
|
2019-11-05 09:28:20 +00:00
|
|
|
list( $type, $ref_argv, $ref_text,
|
2015-06-08 14:05:06 +00:00
|
|
|
$ref_key, $ref_group, $ref_index ) = $call;
|
|
|
|
$this->rollbackRef( $type, $ref_key, $ref_group, $ref_index );
|
Rollback all, then redo all, when fixing out-of-order tags; not one-by-one
Imagine the following wikitext:
<ref name=r/>
<references>
<ref name=r>A</ref>
<ref name=r>B</ref>
</references>
This is simple. Cite would see these as the following operations, in
order:
1. Use only: <ref name=r/>
2. References block
3. Define only: <ref name=r>A</ref>
4. Define only: <ref name=r>B</ref>
<ref name=r> is defined twice with different content and we get an
error message.
Now, imagine the following wikitext:
<ref name=r/>
{{#tag:references|
<ref name=r>A</ref>
<ref name=r>B</ref>
}}
Cite would see these as the following operations, in order:
1. Use only: <ref name=r/>
2. Use and define: <ref name=r>A</ref>
3. Use and define: <ref name=r>B</ref>
4. References block
When the 'references' block appears, Cite notices that the tag has
parsed content, and deduces that it was called with #tag. We need to
undo the last operations to update internal bookkeeping, as the last
two 'ref' tags do not actually represent ref usages, as we assumed,
but only definitions.
5. Undo: <ref name=r> reused
6. Define only: <ref name=r>B</ref>
7. Undo: <ref name=r> defined
(Right now, it appears to Cite that <ref name=r> was never defined!)
8. Define only: <ref name=r>A</ref>
Thus we get no errors, although we should.
This patch changes the order of the rollback operations:
5. Undo: <ref name=r> reused
6. Undo: <ref name=r> defined
7. Define only: <ref name=r>A</ref>
8. Define only: <ref name=r>B</ref>
Aha! <ref name=r> is defined twice with different content! We get an
error correctly.
Bug: T124227
Change-Id: I61766c4104856323987cca9a5e4ff85a76b3618b
2016-01-20 20:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-08 14:05:06 +00:00
|
|
|
|
Rollback all, then redo all, when fixing out-of-order tags; not one-by-one
Imagine the following wikitext:
<ref name=r/>
<references>
<ref name=r>A</ref>
<ref name=r>B</ref>
</references>
This is simple. Cite would see these as the following operations, in
order:
1. Use only: <ref name=r/>
2. References block
3. Define only: <ref name=r>A</ref>
4. Define only: <ref name=r>B</ref>
<ref name=r> is defined twice with different content and we get an
error message.
Now, imagine the following wikitext:
<ref name=r/>
{{#tag:references|
<ref name=r>A</ref>
<ref name=r>B</ref>
}}
Cite would see these as the following operations, in order:
1. Use only: <ref name=r/>
2. Use and define: <ref name=r>A</ref>
3. Use and define: <ref name=r>B</ref>
4. References block
When the 'references' block appears, Cite notices that the tag has
parsed content, and deduces that it was called with #tag. We need to
undo the last operations to update internal bookkeeping, as the last
two 'ref' tags do not actually represent ref usages, as we assumed,
but only definitions.
5. Undo: <ref name=r> reused
6. Define only: <ref name=r>B</ref>
7. Undo: <ref name=r> defined
(Right now, it appears to Cite that <ref name=r> was never defined!)
8. Define only: <ref name=r>A</ref>
Thus we get no errors, although we should.
This patch changes the order of the rollback operations:
5. Undo: <ref name=r> reused
6. Undo: <ref name=r> defined
7. Define only: <ref name=r>A</ref>
8. Define only: <ref name=r>B</ref>
Aha! <ref name=r> is defined twice with different content! We get an
error correctly.
Bug: T124227
Change-Id: I61766c4104856323987cca9a5e4ff85a76b3618b
2016-01-20 20:38:59 +00:00
|
|
|
# Rerun <ref> call now that mInReferences is set.
|
|
|
|
for ( $i = count( $redoStack ) - 1; $i >= 0; $i-- ) {
|
|
|
|
$call = $redoStack[$i];
|
|
|
|
if ( $call !== false ) {
|
2019-11-05 09:28:20 +00:00
|
|
|
list( $type, $ref_argv, $ref_text,
|
Rollback all, then redo all, when fixing out-of-order tags; not one-by-one
Imagine the following wikitext:
<ref name=r/>
<references>
<ref name=r>A</ref>
<ref name=r>B</ref>
</references>
This is simple. Cite would see these as the following operations, in
order:
1. Use only: <ref name=r/>
2. References block
3. Define only: <ref name=r>A</ref>
4. Define only: <ref name=r>B</ref>
<ref name=r> is defined twice with different content and we get an
error message.
Now, imagine the following wikitext:
<ref name=r/>
{{#tag:references|
<ref name=r>A</ref>
<ref name=r>B</ref>
}}
Cite would see these as the following operations, in order:
1. Use only: <ref name=r/>
2. Use and define: <ref name=r>A</ref>
3. Use and define: <ref name=r>B</ref>
4. References block
When the 'references' block appears, Cite notices that the tag has
parsed content, and deduces that it was called with #tag. We need to
undo the last operations to update internal bookkeeping, as the last
two 'ref' tags do not actually represent ref usages, as we assumed,
but only definitions.
5. Undo: <ref name=r> reused
6. Define only: <ref name=r>B</ref>
7. Undo: <ref name=r> defined
(Right now, it appears to Cite that <ref name=r> was never defined!)
8. Define only: <ref name=r>A</ref>
Thus we get no errors, although we should.
This patch changes the order of the rollback operations:
5. Undo: <ref name=r> reused
6. Undo: <ref name=r> defined
7. Define only: <ref name=r>A</ref>
8. Define only: <ref name=r>B</ref>
Aha! <ref name=r> is defined twice with different content! We get an
error correctly.
Bug: T124227
Change-Id: I61766c4104856323987cca9a5e4ff85a76b3618b
2016-01-20 20:38:59 +00:00
|
|
|
$ref_key, $ref_group, $ref_index ) = $call;
|
2019-11-05 09:28:20 +00:00
|
|
|
$this->guardedRef( $ref_text, $ref_argv, $parser );
|
2015-06-08 14:05:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 09:28:20 +00:00
|
|
|
# Parse $text to process any unparsed <ref> tags.
|
|
|
|
$parser->recursiveTagParse( $text );
|
2015-06-08 14:05:06 +00:00
|
|
|
|
|
|
|
# Reset call stack
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mRefCallStack = [];
|
2009-07-26 22:15:13 +00:00
|
|
|
}
|
|
|
|
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
if ( isset( $argv['responsive'] ) ) {
|
|
|
|
$responsive = $argv['responsive'] !== '0';
|
|
|
|
unset( $argv['responsive'] );
|
|
|
|
} else {
|
|
|
|
$responsive = $wgCiteResponsiveReferences;
|
|
|
|
}
|
|
|
|
|
2017-03-22 19:05:27 +00:00
|
|
|
// There are remaining parameters we don't recognise
|
2015-07-07 07:37:14 +00:00
|
|
|
if ( $argv ) {
|
2017-03-22 19:13:22 +00:00
|
|
|
return $this->error( 'cite_error_references_invalid_parameters' );
|
2015-07-18 20:55:32 +00:00
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
$s = $this->referencesFormat( $group, $responsive );
|
2015-07-18 20:55:32 +00:00
|
|
|
|
|
|
|
# Append errors generated while processing <references>
|
2015-07-07 07:37:14 +00:00
|
|
|
if ( $this->mReferencesErrors ) {
|
2015-07-18 20:55:32 +00:00
|
|
|
$s .= "\n" . implode( "<br />\n", $this->mReferencesErrors );
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mReferencesErrors = [];
|
2015-07-18 20:55:32 +00:00
|
|
|
}
|
|
|
|
return $s;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-24 23:08:25 +00:00
|
|
|
* Make output to be returned from the references() function.
|
|
|
|
*
|
|
|
|
* If called outside of references(), caller is responsible for ensuring
|
|
|
|
* `mInReferences` is enabled before the call and disabled after call.
|
2011-09-14 15:07:20 +00:00
|
|
|
*
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string $group
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
* @param bool $responsive
|
|
|
|
* @return string HTML ready for output
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
private function referencesFormat( $group, $responsive ) {
|
2019-11-04 15:04:42 +00:00
|
|
|
if ( !isset( $this->mRefs[$group] ) ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
return '';
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 23:36:49 +00:00
|
|
|
$ent = [];
|
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
|
|
|
}
|
|
|
|
|
2018-09-11 22:54:42 +00:00
|
|
|
// Add new lines between the list items (ref entires) to avoid confusing tidy (T15073).
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
// Note: This builds a string of wikitext, not html.
|
|
|
|
$parserInput = Html::rawElement( 'ol', [ 'class' => [ 'references' ] ],
|
|
|
|
"\n" . implode( "\n", $ent ) . "\n"
|
|
|
|
);
|
2012-10-30 16:22:47 +00:00
|
|
|
|
2018-02-28 09:59:50 +00:00
|
|
|
// Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar
|
|
|
|
$ret = rtrim( $this->mParser->recursiveTagParse( $parserInput ), "\n" );
|
2009-02-03 04:57:28 +00:00
|
|
|
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
if ( $responsive ) {
|
|
|
|
// Use a DIV wrap because column-count on a list directly is broken in Chrome.
|
|
|
|
// See https://bugs.chromium.org/p/chromium/issues/detail?id=498730.
|
|
|
|
$wrapClasses = [ 'mw-references-wrap' ];
|
|
|
|
if ( count( $this->mRefs[$group] ) > 10 ) {
|
|
|
|
$wrapClasses[] = 'mw-references-columns';
|
|
|
|
}
|
|
|
|
$ret = Html::rawElement( 'div', [ 'class' => $wrapClasses ], $ret );
|
|
|
|
}
|
|
|
|
|
2016-01-25 16:52:46 +00:00
|
|
|
if ( !$this->mParser->getOptions()->getIsPreview() ) {
|
|
|
|
// save references data for later use by LinksUpdate hooks
|
2019-11-11 19:11:28 +00:00
|
|
|
$this->saveReferencesData( $this->mParser->getOutput(), $group );
|
2016-01-25 16:52:46 +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
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function referencesFormatEntry( $key, $val ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
// 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',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
self::getReferencesKey( $key )
|
|
|
|
),
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
$this->refKey( $key )
|
|
|
|
),
|
2012-05-15 18:31:23 +00:00
|
|
|
$this->referenceText( $key, $val ),
|
|
|
|
$val['dir']
|
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',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
self::getReferencesKey( $val['follow'] )
|
|
|
|
),
|
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
|
|
|
}
|
2016-05-05 19:09:33 +00:00
|
|
|
if ( !isset( $val['count'] ) ) {
|
|
|
|
// this handles the case of section preview for list-defined references
|
|
|
|
return wfMessage( 'cite_references_link_many',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2019-03-17 23:46:06 +00:00
|
|
|
self::getReferencesKey( $key . "-" . ( $val['key'] ?? '' ) )
|
2017-09-18 19:17:06 +00:00
|
|
|
),
|
2016-05-05 19:09:33 +00:00
|
|
|
'',
|
|
|
|
$text
|
|
|
|
)->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',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
self::getReferencesKey( $val['key'] )
|
|
|
|
),
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
$this->refKey( $val['key'] )
|
|
|
|
),
|
2012-05-15 18:31:23 +00:00
|
|
|
$text,
|
|
|
|
$val['dir']
|
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
|
2016-02-24 23:54:17 +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',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
self::getReferencesKey( $key . "-" . $val['key'] )
|
|
|
|
),
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
$this->refKey( $key, $val['key'] . "-" . $val['count'] )
|
|
|
|
),
|
2012-05-15 18:31:23 +00:00
|
|
|
$text,
|
|
|
|
$val['dir']
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
// Named references with >1 occurrences
|
2016-02-24 23:54:17 +00:00
|
|
|
}
|
2016-05-09 23:36:49 +00:00
|
|
|
$links = [];
|
2016-02-24 23:54:17 +00:00
|
|
|
// for group handling, we have an extra key here.
|
|
|
|
for ( $i = 0; $i <= $val['count']; ++$i ) {
|
|
|
|
$links[] = wfMessage(
|
|
|
|
'cite_references_link_many_format',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
$this->refKey( $key, $val['key'] . "-$i" )
|
|
|
|
),
|
2016-02-24 23:54:17 +00:00
|
|
|
$this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $i, $val['count'] ),
|
|
|
|
$this->referencesFormatEntryAlternateBacklinkLabel( $i )
|
|
|
|
)->inContentLanguage()->plain();
|
|
|
|
}
|
|
|
|
|
|
|
|
$list = $this->listToText( $links );
|
|
|
|
|
|
|
|
return wfMessage( 'cite_references_link_many',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
self::getReferencesKey( $key . "-" . $val['key'] )
|
|
|
|
),
|
2016-02-24 23:54:17 +00:00
|
|
|
$list,
|
2012-05-15 18:31:23 +00:00
|
|
|
$text,
|
|
|
|
$val['dir']
|
2016-02-24 23:54:17 +00:00
|
|
|
)->inContentLanguage()->plain();
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-04 15:00:01 +00:00
|
|
|
/**
|
|
|
|
* Returns formatted reference text
|
2018-11-19 15:39:34 +00:00
|
|
|
* @param string $key
|
|
|
|
* @param string|null $text
|
|
|
|
* @return string
|
2012-01-04 15:00:01 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function referenceText( $key, $text ) {
|
2018-11-19 15:33:41 +00:00
|
|
|
if ( $text === null || $text === '' ) {
|
2016-02-18 06:50:04 +00:00
|
|
|
if ( $this->mParser->getOptions()->getIsSectionPreview() ) {
|
|
|
|
return $this->warning( 'cite_warning_sectionpreview_no_text', $key, 'noparse' );
|
|
|
|
}
|
2018-09-13 00:32:00 +00:00
|
|
|
return $this->plainError( 'cite_error_references_no_text', $key );
|
2012-01-04 15:00:01 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
*
|
2017-12-28 14:55:49 +00:00
|
|
|
* @param int $base
|
|
|
|
* @param int $offset
|
2008-06-06 20:38:04 +00:00
|
|
|
* @param int $max Maximum value expected.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function referencesFormatEntryNumericBacklinkLabel( $base, $offset, $max ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
$scope = strlen( $max );
|
2019-09-02 18:53:09 +00:00
|
|
|
$ret = MediaWikiServices::getInstance()->getContentLanguage()->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.
|
2017-01-07 09:08:35 +00:00
|
|
|
* $offset = 2; = c if $this->mBacklinkLabels = [ 'a',
|
|
|
|
* 'b', 'c', ...]. Return an error if the offset > the # of
|
2008-06-06 20:38:04 +00:00
|
|
|
* array items
|
|
|
|
*
|
2017-12-28 14:55:49 +00:00
|
|
|
* @param int $offset
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function referencesFormatEntryAlternateBacklinkLabel( $offset ) {
|
2008-06-06 20:38:04 +00:00
|
|
|
if ( !isset( $this->mBacklinkLabels ) ) {
|
|
|
|
$this->genBacklinkLabels();
|
|
|
|
}
|
2019-10-25 08:19:08 +00:00
|
|
|
return $this->mBacklinkLabels[$offset]
|
|
|
|
?? $this->plainError( 'cite_error_references_no_backlink_label', null );
|
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"] =
|
2017-01-07 09:08:35 +00:00
|
|
|
* [ 'a', 'b', 'c', ...].
|
2010-05-22 14:28:48 +00:00
|
|
|
* Return an error if the offset > the # of array items
|
|
|
|
*
|
2017-12-28 14:55:49 +00:00
|
|
|
* @param int $offset
|
2010-05-22 14:28:48 +00:00
|
|
|
* @param string $group The group name
|
|
|
|
* @param string $label The text to use if there's no message for them.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private 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
|
|
|
|
2019-10-25 08:19:08 +00:00
|
|
|
return $this->mLinkLabels[$group][$offset - 1]
|
|
|
|
?? $this->plainError( 'cite_error_no_link_label_group', [ $group, $message ] );
|
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)
|
|
|
|
*
|
2017-12-28 14:55:49 +00:00
|
|
|
* @param string $key
|
2018-11-19 15:39:34 +00:00
|
|
|
* @param int|null $num The number of the key
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string A key for use in wikitext
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private 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();
|
2018-11-19 15:33:41 +00:00
|
|
|
if ( $num !== null ) {
|
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)
|
|
|
|
*
|
2017-12-28 14:55:49 +00:00
|
|
|
* @param string $key
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string A key for use in wikitext
|
|
|
|
*/
|
2016-02-24 21:14:32 +00:00
|
|
|
public static function getReferencesKey( $key ) {
|
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
|
|
|
|
|
|
|
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
|
|
|
|
*
|
2018-09-13 00:32:00 +00:00
|
|
|
* @suppress SecurityCheck-DoubleEscaped
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string $group
|
|
|
|
* @param string $key The key for the link
|
2018-11-19 15:39:34 +00:00
|
|
|
* @param int|null $count The index of the key, used for distinguishing
|
2012-03-19 14:59:29 +00:00
|
|
|
* multiple occurrences of the same key
|
2018-11-19 15:39:34 +00:00
|
|
|
* @param int|null $label 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.
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string $subkey
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) {
|
2019-09-02 18:53:09 +00:00
|
|
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
2018-11-19 15:33:41 +00:00
|
|
|
|
|
|
|
if ( $label === null ) {
|
|
|
|
$label = ++$this->mGroupCnt[$group];
|
|
|
|
}
|
2011-02-22 00:07:21 +00:00
|
|
|
|
2017-12-29 23:28:16 +00:00
|
|
|
return $this->mParser->recursiveTagParse(
|
2012-08-30 08:41:27 +00:00
|
|
|
wfMessage(
|
2008-06-06 20:38:04 +00:00
|
|
|
'cite_reference_link',
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
$this->refKey( $key, $count )
|
|
|
|
),
|
2017-11-10 01:21:54 +00:00
|
|
|
$this->normalizeKey(
|
2017-09-18 19:17:06 +00:00
|
|
|
self::getReferencesKey( $key . $subkey )
|
|
|
|
),
|
|
|
|
Sanitizer::safeEncodeAttribute(
|
|
|
|
$this->getLinkLabel( $label, $group,
|
2019-09-02 18:53:09 +00:00
|
|
|
( ( $group === self::DEFAULT_GROUP ) ? '' : "$group " ) . $contLang->formatNum( $label ) )
|
2017-09-18 19:17:06 +00:00
|
|
|
)
|
2012-08-30 08:41:27 +00:00
|
|
|
)->inContentLanguage()->plain()
|
2008-06-06 20:38:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-10 01:21:54 +00:00
|
|
|
/**
|
|
|
|
* Normalizes and sanitizes a reference key
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function normalizeKey( $key ) {
|
2019-07-09 21:00:43 +00:00
|
|
|
$ret = Sanitizer::escapeIdForAttribute( $key );
|
|
|
|
$ret = preg_replace( '/__+/', '_', $ret );
|
|
|
|
$ret = Sanitizer::safeEncodeAttribute( $ret );
|
2017-11-10 01:21:54 +00:00
|
|
|
|
2019-07-09 21:00:43 +00:00
|
|
|
return $ret;
|
2017-11-10 01:21:54 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2018-11-19 15:39:34 +00:00
|
|
|
* @param string[] $arr The array to format
|
2008-06-06 20:38:04 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2019-10-17 07:21:22 +00:00
|
|
|
private function listToText( array $arr ) {
|
2019-10-25 08:17:05 +00:00
|
|
|
$lastElement = array_pop( $arr );
|
|
|
|
|
|
|
|
if ( $arr === [] ) {
|
|
|
|
return (string)$lastElement;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
2018-11-19 15:40:39 +00:00
|
|
|
|
|
|
|
$sep = wfMessage( 'cite_references_link_many_sep' )->inContentLanguage()->plain();
|
|
|
|
$and = wfMessage( 'cite_references_link_many_and' )->inContentLanguage()->plain();
|
2019-10-25 08:17:05 +00:00
|
|
|
return implode( $sep, $arr ) . $and . $lastElement;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the labels to pass to the
|
|
|
|
* 'cite_references_link_many_format' message, the format is an
|
2018-11-19 15:36:01 +00:00
|
|
|
* arbitrary number of tokens separated by whitespace.
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function genBacklinkLabels() {
|
2012-08-30 08:41:27 +00:00
|
|
|
$text = wfMessage( 'cite_references_link_many_format_backlink_labels' )
|
|
|
|
->inContentLanguage()->plain();
|
2018-11-19 15:36:01 +00:00
|
|
|
$this->mBacklinkLabels = preg_split( '/\s+/', $text );
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
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
|
2018-11-19 15:36:01 +00:00
|
|
|
* arbitrary number of tokens separated by whitespace.
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param string $group
|
|
|
|
* @param string $message
|
2010-05-22 14:28:48 +00:00
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function genLinkLabels( $group, $message ) {
|
2010-05-22 14:28:48 +00:00
|
|
|
$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
|
|
|
}
|
2018-11-19 15:36:01 +00:00
|
|
|
$this->mLinkLabels[$group] = $text ? preg_split( '/\s+/', $text ) : false;
|
2010-05-22 14:28:48 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2019-11-04 16:00:49 +00:00
|
|
|
public function clearState() {
|
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 ) {
|
2018-05-15 08:40:58 +00:00
|
|
|
return;
|
2011-02-22 00:07:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mGroupCnt = [];
|
2012-10-17 22:58:55 +00:00
|
|
|
$this->mOutCnt = 0;
|
2016-05-09 23:36:49 +00:00
|
|
|
$this->mRefs = [];
|
|
|
|
$this->mReferencesErrors = [];
|
|
|
|
$this->mRefCallStack = [];
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 18:02:28 +00:00
|
|
|
/**
|
2015-08-06 17:33:01 +00:00
|
|
|
* Called at the end of page processing to append a default references
|
|
|
|
* section, if refs were used without a main references tag. If there are references
|
|
|
|
* in a custom group, and there is no references tag for it, show an error
|
|
|
|
* message for that group.
|
2014-05-18 23:06:44 +00:00
|
|
|
* If we are processing a section preview, this adds the missing
|
|
|
|
* references tags and does not add the errors.
|
2011-05-28 20:44:24 +00:00
|
|
|
*
|
2015-10-26 14:44:02 +00:00
|
|
|
* @param bool $afterParse True if called from the ParserAfterParse hook
|
2019-11-04 16:00:49 +00:00
|
|
|
* @param ParserOptions $parserOptions
|
2017-10-06 19:22:30 +00:00
|
|
|
* @param string &$text
|
2009-01-26 18:02:28 +00:00
|
|
|
*/
|
2019-11-04 16:00:49 +00:00
|
|
|
public function checkRefsNoReferences( $afterParse, ParserOptions $parserOptions, &$text ) {
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
global $wgCiteResponsiveReferences;
|
2015-06-08 14:05:06 +00:00
|
|
|
|
|
|
|
if ( $afterParse ) {
|
|
|
|
$this->mHaveAfterParse = true;
|
|
|
|
} elseif ( $this->mHaveAfterParse ) {
|
2018-05-15 08:40:58 +00:00
|
|
|
return;
|
2011-05-31 17:49:22 +00:00
|
|
|
}
|
2011-09-14 15:07:20 +00:00
|
|
|
|
2019-11-04 16:00:49 +00:00
|
|
|
if ( !$parserOptions->getIsPreview() ) {
|
2016-01-25 16:52:46 +00:00
|
|
|
// save references data for later use by LinksUpdate hooks
|
|
|
|
if ( $this->mRefs && isset( $this->mRefs[self::DEFAULT_GROUP] ) ) {
|
2019-11-11 19:11:28 +00:00
|
|
|
$this->saveReferencesData( $this->mParser->getOutput() );
|
2016-01-25 16:52:46 +00:00
|
|
|
}
|
|
|
|
$isSectionPreview = false;
|
|
|
|
} else {
|
2019-11-04 16:00:49 +00:00
|
|
|
$isSectionPreview = $parserOptions->getIsSectionPreview();
|
2016-01-25 16:52:46 +00:00
|
|
|
}
|
2016-02-06 12:24:58 +00:00
|
|
|
|
|
|
|
$s = '';
|
2009-01-26 18:02:28 +00:00
|
|
|
foreach ( $this->mRefs as $group => $refs ) {
|
2015-07-07 07:37:14 +00:00
|
|
|
if ( !$refs ) {
|
2011-02-22 00:07:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-18 23:06:44 +00:00
|
|
|
if ( $group === self::DEFAULT_GROUP || $isSectionPreview ) {
|
2018-07-24 23:08:25 +00:00
|
|
|
$this->mInReferences = true;
|
Implement responsive columns for reference lists
This is based on the popular 'count' parameter from Template:Reflist on
English Wikipedia, which has also been adopted by many other wikis.
That template's 'count' parameter allows maximum flexibility on a per-
page basis. This was important because the template can't know how many
references the list will contain. Users typically manually add (and
later, increment) the 'count' parameter when the list exceeds a certain
threshold.
The template currently sets an exact column count (via the CSS3
property `column-count`).
This patch improves on that by instead using the closely related CSS3
`column-width` property. This automatically derives the column count
based on the available space in the browser window. It will thus create
two or three columns on a typical desktop screen, and two or no columns
on a mobile device.
The specified width is the minimum width of a column. This ensures that
the list is not split when rendered on a narrow screen or mobile device.
It also hooks into the raw list before parsing and adds the class only
when the list will contain more than a certain number of items. This
prevents very short lists from being split into multiple columns.
Templates like Template:Reflist on English Wikipedia currently are not
able to set inline styles on the list element directly, which is why
they set it on a `<div>` wrapping the `<references />` output. Because
of this, the feature of the Cite extension must not be enabled at the
same time, as that would result in both the template's wrapper and the
references list being split. The end result would involve sitations with
three columns split in four sub-columns, creating a complicated mess of
nine intermixed columns.
To provide a smooth migration for wikis, this feature can be disabled by
default using `$wgCiteResponsiveReferences = false`. Each individual
template createing reference list can then be migrated, by removing the
wrapper column styles and instead settting the new "responsive"
attribute, like so: `<references responsive />`.
Once any conflicting templates have been migrated, the default for the
wiki can be swapped by setting `$wgCiteResponsiveReferences = true`.
If wikis wish for some templates to keep their custom column splitting
behaviour, templates can also opt-out by setting `responsive="0"`, which
will make sure that it will keep behaving the current way even after the
feature becomes enabled by default for the wiki.
In summary, when disabled by default, pages can opt into this system
with `<references responsive />`. When enabled by default, pages can opt
out of the system with `<references responsive=0 />`.
* Deprecate cite_references_prefix/cite_references_suffix.
This message is rarely used and opens up compatibility hazards.
It was already removed by Parsoid, but the PHP implementation
still had it. It's typically used to add inline styles to the
wrapper which is more appropiately done in Common.css (or
obsoleted as part of the skin or Cite extenion itself nowadays
depending on what style in question).
It was also a HTML-style message with separated open and close
segments, which is an anti-pattern in itself.
* Declare module target explicitly and include mobile. The absence of
this stylesheet caused subtle BiDi/RTL bugs on mobile.
Bug: T33597
Change-Id: Ia535f9b722e825e71e792b36356febc3bd444387
2015-07-21 02:33:50 +00:00
|
|
|
$s .= $this->referencesFormat( $group, $wgCiteResponsiveReferences );
|
2018-07-24 23:08:25 +00:00
|
|
|
$this->mInReferences = false;
|
2009-01-26 18:02:28 +00:00
|
|
|
} else {
|
2016-02-06 12:24:58 +00:00
|
|
|
$s .= "\n<br />" .
|
2017-09-18 19:17:06 +00:00
|
|
|
$this->error(
|
|
|
|
'cite_error_group_refs_without_references',
|
|
|
|
Sanitizer::safeEncodeAttribute( $group )
|
|
|
|
);
|
2009-01-26 18:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-06 12:24:58 +00:00
|
|
|
if ( $isSectionPreview && $s !== '' ) {
|
2016-02-08 16:02:47 +00:00
|
|
|
// provide a preview of references in its own section
|
|
|
|
$text .= "\n" . '<div class="mw-ext-cite-cite_section_preview_references" >';
|
|
|
|
$headerMsg = wfMessage( 'cite_section_preview_references' );
|
|
|
|
if ( !$headerMsg->isDisabled() ) {
|
|
|
|
$text .= '<h2 id="mw-ext-cite-cite_section_preview_references_header" >'
|
|
|
|
. $headerMsg->escaped()
|
|
|
|
. '</h2>';
|
|
|
|
}
|
|
|
|
$text .= $s . '</div>';
|
2016-02-06 12:24:58 +00:00
|
|
|
} else {
|
|
|
|
$text .= $s;
|
|
|
|
}
|
2009-01-26 18:02:28 +00:00
|
|
|
}
|
2011-09-14 15:07:20 +00:00
|
|
|
|
2016-01-25 16:52:46 +00:00
|
|
|
/**
|
|
|
|
* Saves references in parser extension data
|
|
|
|
* This is called by each <references/> tag, and by checkRefsNoReferences
|
|
|
|
* Assumes $this->mRefs[$group] is set
|
|
|
|
*
|
2019-11-11 19:11:28 +00:00
|
|
|
* @param ParserOutput $parserOutput
|
2017-10-06 19:22:30 +00:00
|
|
|
* @param string $group
|
2016-01-25 16:52:46 +00:00
|
|
|
*/
|
2019-11-11 19:11:28 +00:00
|
|
|
private function saveReferencesData( ParserOutput $parserOutput, $group = self::DEFAULT_GROUP ) {
|
2016-01-25 16:52:46 +00:00
|
|
|
global $wgCiteStoreReferencesData;
|
|
|
|
if ( !$wgCiteStoreReferencesData ) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-11 19:11:28 +00:00
|
|
|
$savedRefs = $parserOutput->getExtensionData( self::EXT_DATA_KEY );
|
2016-01-25 16:52:46 +00:00
|
|
|
if ( $savedRefs === null ) {
|
|
|
|
// Initialize array structure
|
2016-05-09 23:36:49 +00:00
|
|
|
$savedRefs = [
|
|
|
|
'refs' => [],
|
2016-01-25 16:52:46 +00:00
|
|
|
'version' => self::DATA_VERSION_NUMBER,
|
2016-05-09 23:36:49 +00:00
|
|
|
];
|
2016-01-25 16:52:46 +00:00
|
|
|
}
|
|
|
|
if ( $this->mBumpRefData ) {
|
|
|
|
// This handles pages with multiple <references/> tags with <ref> tags in between.
|
|
|
|
// On those, a group can appear several times, so we need to avoid overwriting
|
|
|
|
// a previous appearance.
|
2016-05-09 23:36:49 +00:00
|
|
|
$savedRefs['refs'][] = [];
|
2016-01-25 16:52:46 +00:00
|
|
|
$this->mBumpRefData = false;
|
|
|
|
}
|
|
|
|
$n = count( $savedRefs['refs'] ) - 1;
|
|
|
|
// save group
|
|
|
|
$savedRefs['refs'][$n][$group] = $this->mRefs[$group];
|
|
|
|
|
2019-11-11 19:11:28 +00:00
|
|
|
$parserOutput->setExtensionData( self::EXT_DATA_KEY, $savedRefs );
|
2016-01-25 16:52:46 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 20:38:04 +00:00
|
|
|
/**
|
2018-09-13 00:32:00 +00:00
|
|
|
* Return an error message based on an error ID and parses it
|
2008-06-06 20:38:04 +00:00
|
|
|
*
|
|
|
|
* @param string $key Message name for the error
|
2017-12-25 13:17:20 +00:00
|
|
|
* @param string[]|string|null $param Parameter to pass to the message
|
2018-09-13 00:32:00 +00:00
|
|
|
* @return string HTML ready for output
|
|
|
|
*/
|
|
|
|
private function error( $key, $param = null ) {
|
|
|
|
$error = $this->plainError( $key, $param );
|
|
|
|
return $this->mParser->recursiveTagParse( $error );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an error message based on an error ID as unescaped plaintext.
|
|
|
|
*
|
|
|
|
* @param string $key Message name for the error
|
|
|
|
* @param string[]|string|null $param Parameter to pass to the message
|
|
|
|
* @return string wikitext ready for output
|
|
|
|
* @return-taint tainted
|
2008-06-06 20:38:04 +00:00
|
|
|
*/
|
2018-09-13 00:32:00 +00:00
|
|
|
private function plainError( $key, $param = null ) {
|
2016-01-06 20:48:33 +00:00
|
|
|
# For ease of debugging and because errors are rare, we
|
|
|
|
# use the user language and split the parser cache.
|
|
|
|
$lang = $this->mParser->getOptions()->getUserLangObj();
|
2015-10-08 20:38:01 +00:00
|
|
|
$dir = $lang->getDir();
|
|
|
|
|
|
|
|
# We rely on the fact that PHP is okay with passing unused argu-
|
|
|
|
# ments to functions. If $1 is not used in the message, wfMessage will
|
|
|
|
# just ignore the extra parameter.
|
2016-01-06 20:48:33 +00:00
|
|
|
$msg = wfMessage(
|
2016-02-18 06:50:04 +00:00
|
|
|
'cite_error',
|
2016-01-06 20:48:33 +00:00
|
|
|
wfMessage( $key, $param )->inLanguage( $lang )->plain()
|
|
|
|
)
|
|
|
|
->inLanguage( $lang )
|
2014-09-27 16:49:28 +00:00
|
|
|
->plain();
|
|
|
|
|
2016-02-18 06:50:04 +00:00
|
|
|
$this->mParser->addTrackingCategory( 'cite-tracking-category-cite-error' );
|
|
|
|
|
2015-10-08 20:38:01 +00:00
|
|
|
$ret = Html::rawElement(
|
|
|
|
'span',
|
2016-05-09 23:36:49 +00:00
|
|
|
[
|
2015-10-08 20:38:01 +00:00
|
|
|
'class' => 'error mw-ext-cite-error',
|
|
|
|
'lang' => $lang->getHtmlCode(),
|
|
|
|
'dir' => $dir,
|
2016-05-09 23:36:49 +00:00
|
|
|
],
|
2015-10-08 20:38:01 +00:00
|
|
|
$msg
|
|
|
|
);
|
2015-07-05 12:32:44 +00:00
|
|
|
|
2016-02-18 06:50:04 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a warning message based on a warning ID
|
|
|
|
*
|
|
|
|
* @param string $key Message name for the warning. Name should start with cite_warning_
|
|
|
|
* @param string|null $param Parameter to pass to the message
|
|
|
|
* @param string $parse Whether to parse the message ('parse') or not ('noparse')
|
|
|
|
* @return string XHTML or wikitext ready for output
|
|
|
|
*/
|
2016-09-21 11:01:25 +00:00
|
|
|
private function warning( $key, $param = null, $parse = 'parse' ) {
|
2016-02-18 06:50:04 +00:00
|
|
|
# For ease of debugging and because errors are rare, we
|
|
|
|
# use the user language and split the parser cache.
|
|
|
|
$lang = $this->mParser->getOptions()->getUserLangObj();
|
2015-10-08 20:38:01 +00:00
|
|
|
$dir = $lang->getDir();
|
|
|
|
|
|
|
|
# We rely on the fact that PHP is okay with passing unused argu-
|
|
|
|
# ments to functions. If $1 is not used in the message, wfMessage will
|
|
|
|
# just ignore the extra parameter.
|
2016-02-18 06:50:04 +00:00
|
|
|
$msg = wfMessage(
|
|
|
|
'cite_warning',
|
|
|
|
wfMessage( $key, $param )->inLanguage( $lang )->plain()
|
|
|
|
)
|
|
|
|
->inLanguage( $lang )
|
|
|
|
->plain();
|
|
|
|
|
|
|
|
$key = preg_replace( '/^cite_warning_/', '', $key ) . '';
|
2015-10-08 20:38:01 +00:00
|
|
|
$ret = Html::rawElement(
|
|
|
|
'span',
|
2016-05-09 23:36:49 +00:00
|
|
|
[
|
2015-10-08 20:38:01 +00:00
|
|
|
'class' => 'warning mw-ext-cite-warning mw-ext-cite-warning-' .
|
|
|
|
Sanitizer::escapeClass( $key ),
|
|
|
|
'lang' => $lang->getHtmlCode(),
|
|
|
|
'dir' => $dir,
|
2016-05-09 23:36:49 +00:00
|
|
|
],
|
2015-10-08 20:38:01 +00:00
|
|
|
$msg
|
|
|
|
);
|
2016-02-18 06:50:04 +00:00
|
|
|
|
2015-07-07 12:20:53 +00:00
|
|
|
if ( $parse === 'parse' ) {
|
2014-06-05 17:51:48 +00:00
|
|
|
$ret = $this->mParser->recursiveTagParse( $ret );
|
2011-11-14 12:22:07 +00:00
|
|
|
}
|
2014-09-27 16:49:28 +00:00
|
|
|
|
2011-11-14 12:22:07 +00:00
|
|
|
return $ret;
|
2008-06-06 20:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|