MediaWiki REL1_34
|
Public Member Functions | |
checkRefsNoReferences ( $afterParse, $parser, &$text) | |
Called at the end of page processing to append a default references section, if refs were used without a main references tag. | |
clearState (Parser $parser) | |
Gets run when Parser::clearState() gets run, since we don't want the counts to transcend pages and other instances. | |
cloneState (Parser $parser) | |
Gets run when the parser is cloned. | |
ref ( $str, array $argv, Parser $parser, PPFrame $frame) | |
Callback function for <ref> | |
references ( $str, array $argv, Parser $parser, PPFrame $frame) | |
Callback function for <references> | |
Static Public Member Functions | |
static | getReferencesKey ( $key) |
Return an id for use in wikitext output based on a key and optionally the number of it, used in <ref>, not <references> (since otherwise it would link to itself) | |
static | getStoredReferences (Title $title) |
Fetch references stored for the given title in page_props For performance, results are cached. | |
static | setHooks (Parser $parser) |
Initialize the parser hooks. | |
Public Attributes | |
boolean | $mInCite = false |
True when a <ref> tag is being processed. | |
boolean | $mInReferences = false |
True when a <references> tag is being processed. | |
const | CACHE_DURATION_ONFETCH = 18000 |
Cache duration set when fetching references from db. | |
const | CACHE_DURATION_ONPARSE = 3600 |
Cache duration set when parsing a page with references. | |
const | DATA_VERSION_NUMBER = 1 |
Version number in case we change the data structure in the future. | |
const | DEFAULT_GROUP = '' |
const | EXT_DATA_KEY = 'Cite:References' |
Key used for storage in parser output's ExtensionData and ObjectCache. | |
const | MAX_STORAGE_LENGTH = 65535 |
Maximum storage capacity for pp_value field of page_props table. | |
Private Member Functions | |
error ( $key, $param=null) | |
Return an error message based on an error ID and parses it. | |
genBacklinkLabels () | |
Generate the labels to pass to the 'cite_references_link_many_format' message, the format is an arbitrary number of tokens separated by whitespace. | |
genLinkLabels ( $group, $message) | |
Generate the labels to pass to the 'cite_reference_link' message instead of numbers, the format is an arbitrary number of tokens separated by whitespace. | |
getLinkLabel ( $offset, $group, $label) | |
Generate a custom format link for a group given an offset, e.g. | |
guardedRef ( $str, array $argv, Parser $parser) | |
guardedReferences ( $str, array $argv, Parser $parser) | |
Must only be called from references(). | |
linkRef ( $group, $key, $count=null, $label=null, $subkey='') | |
Generate a link (<sup ...) for the <ref> element from a key and return XHTML ready for output. | |
listToText ( $arr) | |
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 first separator and not 'and' as the second, and this has to use messages from the content language) I'm rolling my own. | |
normalizeKey ( $key) | |
Normalizes and sanitizes a reference key. | |
plainError ( $key, $param=null) | |
Return an error message based on an error ID as unescaped plaintext. | |
refArg (array $argv) | |
Parse the arguments to the <ref> tag. | |
referencesFormat ( $group, $responsive) | |
Make output to be returned from the references() function. | |
referencesFormatEntry ( $key, $val) | |
Format a single entry for the referencesFormat() function. | |
referencesFormatEntryAlternateBacklinkLabel ( $offset) | |
Generate a custom format backlink given an offset, e.g. | |
referencesFormatEntryNumericBacklinkLabel ( $base, $offset, $max) | |
Generate a numeric backlink given a base number and an offset, e.g. | |
referenceText ( $key, $text) | |
Returns formatted reference text. | |
refKey ( $key, $num=null) | |
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) | |
rollbackRef ( $type, $key, $group, $index) | |
Partially undoes the effect of calls to stack() | |
saveReferencesData ( $group=self::DEFAULT_GROUP) | |
Saves references in parser extension data This is called by each <references> tag, and by checkRefsNoReferences Assumes $this->mRefs[$group] is set. | |
stack ( $str, $key, $group, $follow, array $call, $dir, Parser $parser) | |
Populate $this->mRefs based on input and arguments to <ref> | |
warning ( $key, $param=null, $parse='parse') | |
Return a warning message based on a warning ID. | |
Static Private Member Functions | |
static | recursiveFetchRefsFromDB (Title $title, IDatabase $dbr, $string='', $i=1) |
Reconstructs compressed json by successively retrieving the properties references-1, -2, etc It attempts the next step when a decoding error occurs. | |
Private Attributes | |
string[] | $mBacklinkLabels |
The backlinks, in order, to pass as $3 to 'cite_references_link_many_format', defined in 'cite_references_link_many_format_backlink_labels. | |
bool | $mBumpRefData = false |
int | $mCallCnt = 0 |
Counter to track the total number of (useful) calls to either the ref or references tag hook. | |
int[] | $mGroupCnt = [] |
boolean | $mHaveAfterParse = false |
True when the ParserAfterParse hook has been called. | |
string[] false[] | $mLinkLabels = [] |
The links to use per group, in order. | |
int | $mOutCnt = 0 |
Count for user displayed output (ref[1], ref[2], ...) | |
Parser | $mParser |
array false[] | $mRefCallStack = [] |
<ref> call stack Used to cleanup out of sequence ref calls created by #tag See description of function rollbackRef. | |
string[] | $mReferencesErrors = [] |
Error stack used when defining refs in <references> | |
string | $mReferencesGroup = '' |
Group used when in <references> block. | |
array[] | $mRefs = [] |
Datastructure representing <ref> input, in the format of: [ 'user supplied' => [ 'text' => 'user supplied reference & key', 'count' => 1, // occurs twice 'number' => 1, // The first reference, we want // all occourances of it to // use the same number ], 0 => 'Anonymous reference', 1 => 'Another anonymous reference', 'some key' => [ 'text' => 'this one occurs once' 'count' => 0, 'number' => 4 ], 3 => 'more stuff' ]; | |
Static Private Attributes | |
static Boolean | $hooksInstalled = false |
Did we install us into $wgHooks yet? | |
Cite::checkRefsNoReferences | ( | $afterParse, | |
$parser, | |||
& | $text ) |
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. If we are processing a section preview, this adds the missing references tags and does not add the errors.
bool | $afterParse | True if called from the ParserAfterParse hook |
Parser | $parser | |
string | &$text |
Definition at line 1188 of file Cite.php.
References $s, error(), referencesFormat(), saveReferencesData(), and wfMessage().
Cite::clearState | ( | Parser | $parser | ) |
Gets run when Parser::clearState() gets run, since we don't want the counts to transcend pages and other instances.
Parser | $parser |
Definition at line 1135 of file Cite.php.
References Parser\clearState().
Cite::cloneState | ( | Parser | $parser | ) |
Gets run when the parser is cloned.
Parser | $parser |
Definition at line 1160 of file Cite.php.
References Parser\clearState(), and Parser\setHook().
|
private |
Return an error message based on an error ID and parses it.
string | $key | Message name for the error |
string[] | string | null | $param | Parameter to pass to the message |
Definition at line 1308 of file Cite.php.
References plainError().
Referenced by checkRefsNoReferences(), guardedRef(), and guardedReferences().
|
private |
Generate the labels to pass to the 'cite_references_link_many_format' message, the format is an arbitrary number of tokens separated by whitespace.
Definition at line 1106 of file Cite.php.
References wfMessage().
Referenced by referencesFormatEntryAlternateBacklinkLabel().
|
private |
Generate the labels to pass to the 'cite_reference_link' message instead of numbers, the format is an arbitrary number of tokens separated by whitespace.
string | $group | |
string | $message |
Definition at line 1120 of file Cite.php.
References wfMessage().
Referenced by getLinkLabel().
|
private |
Generate a custom format link for a group given an offset, e.g.
the second <ref group="foo"> is b if $this->mLinkLabels["foo"] = [ 'a', 'b', 'c', ...]. Return an error if the offset > the # of array items
int | $offset | |
string | $group | The group name |
string | $label | The text to use if there's no message for them. |
Definition at line 971 of file Cite.php.
References genLinkLabels(), and plainError().
Referenced by linkRef().
|
static |
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)
string | $key |
Definition at line 1017 of file Cite.php.
References wfMessage().
Referenced by ApiQueryReferences\execute().
|
static |
Fetch references stored for the given title in page_props For performance, results are cached.
Title | $title |
Definition at line 1402 of file Cite.php.
References $cache, $dbr, $title, DB_REPLICA, recursiveFetchRefsFromDB(), and wfGetDB().
Referenced by ApiQueryReferences\execute().
|
private |
string | null | $str | Raw content of the <ref> tag. |
string[] | $argv | Arguments |
Parser | $parser |
Exception |
Definition at line 237 of file Cite.php.
References $mReferencesGroup, DEFAULT_GROUP, error(), Parser\getOptions(), plainError(), refArg(), serialize(), and stack().
Referenced by guardedReferences(), and ref().
|
private |
Must only be called from references().
Use that to prevent recursion.
string | null | $str | Raw content of the <references> tag. |
string[] | $argv | |
Parser | $parser |
Definition at line 666 of file Cite.php.
References $s, $type, DEFAULT_GROUP, error(), guardedRef(), Parser\recursiveTagParse(), referencesFormat(), and rollbackRef().
Referenced by references().
|
private |
Generate a link (<sup ...) for the <ref> element from a key and return XHTML ready for output.
SecurityCheck-DoubleEscaped
string | $group | |
string | $key | The key for the link |
int | null | $count | The index of the key, used for distinguishing multiple occurrences of the same key |
int | null | $label | The label to use for the link, I want to use the same label for all occourances of the same named reference. |
string | $subkey |
Definition at line 1040 of file Cite.php.
References getLinkLabel(), normalizeKey(), refKey(), and wfMessage().
Referenced by stack().
|
private |
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 first separator and not 'and' as the second, and this has to use messages from the content language) I'm rolling my own.
string[] | $arr | The array to format |
Definition at line 1088 of file Cite.php.
References $t, and wfMessage().
Referenced by referencesFormatEntry().
|
private |
Normalizes and sanitizes a reference key.
string | $key |
Definition at line 1070 of file Cite.php.
Referenced by linkRef(), and referencesFormatEntry().
|
private |
Return an error message based on an error ID as unescaped plaintext.
string | $key | Message name for the error |
string[] | string | null | $param | Parameter to pass to the message |
Definition at line 1321 of file Cite.php.
References $lang, and wfMessage().
Referenced by error(), getLinkLabel(), guardedRef(), referencesFormatEntryAlternateBacklinkLabel(), referenceText(), and stack().
|
staticprivate |
Reconstructs compressed json by successively retrieving the properties references-1, -2, etc It attempts the next step when a decoding error occurs.
Returns json_decoded uncompressed string, with validation of json
Title | $title | |
IDatabase | $dbr | |
string | $string | |
int | $i |
Definition at line 1435 of file Cite.php.
References $dbr, $title, recursiveFetchRefsFromDB(), and wfDebug().
Referenced by getStoredReferences(), and recursiveFetchRefsFromDB().
Callback function for <ref>
string | null | $str | Raw content of the <ref> tag. |
string[] | $argv | Arguments |
Parser | $parser | |
PPFrame | $frame |
Definition at line 204 of file Cite.php.
References Parser\getOutput(), guardedRef(), and PPFrame\setVolatile().
|
private |
Parse the arguments to the <ref> tag.
"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. "dir" : set direction of text (ltr/rtl)
string[] | $argv | The argument vector |
Definition at line 398 of file Cite.php.
Referenced by guardedRef().
Callback function for <references>
string | null | $str | Raw content of the <references> tag. |
string[] | $argv | Arguments |
Parser | $parser | |
PPFrame | $frame |
Definition at line 642 of file Cite.php.
References guardedReferences(), and PPFrame\setVolatile().
|
private |
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.
string | $group | |
bool | $responsive |
Definition at line 761 of file Cite.php.
References referencesFormatEntry(), and saveReferencesData().
Referenced by checkRefsNoReferences(), and guardedReferences().
|
private |
Format a single entry for the referencesFormat() function.
string | $key | The key of the reference |
mixed | $val | The value of the reference, string for anonymous references, array for user-suppplied |
Definition at line 810 of file Cite.php.
References listToText(), normalizeKey(), referencesFormatEntryAlternateBacklinkLabel(), referencesFormatEntryNumericBacklinkLabel(), referenceText(), refKey(), and wfMessage().
Referenced by referencesFormat().
|
private |
Generate a custom format backlink given an offset, e.g.
$offset = 2; = c if $this->mBacklinkLabels = [ 'a', 'b', 'c', ...]. Return an error if the offset > the # of array items
int | $offset |
Definition at line 947 of file Cite.php.
References genBacklinkLabels(), and plainError().
Referenced by referencesFormatEntry().
|
private |
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
int | $base | |
int | $offset | |
int | $max | Maximum value expected. |
Definition at line 929 of file Cite.php.
References $base.
Referenced by referencesFormatEntry().
|
private |
Returns formatted reference text.
string | $key | |
string | null | $text |
Definition at line 909 of file Cite.php.
References plainError(), and warning().
Referenced by referencesFormatEntry().
|
private |
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)
string | $key | |
int | null | $num | The number of the key |
Definition at line 998 of file Cite.php.
References wfMessage().
Referenced by linkRef(), and referencesFormatEntry().
|
private |
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.
string | $type | |
string | null | $key | |
string | $group | |
int | $index |
Definition at line 587 of file Cite.php.
References $type.
Referenced by guardedReferences().
|
private |
Saves references in parser extension data This is called by each <references> tag, and by checkRefsNoReferences Assumes $this->mRefs[$group] is set.
string | $group |
Definition at line 1253 of file Cite.php.
References DATA_VERSION_NUMBER.
Referenced by checkRefsNoReferences(), and referencesFormat().
|
static |
|
private |
Populate $this->mRefs based on input and arguments to <ref>
string | $str | Input from the <ref> tag |
string | null | $key | Argument to the <ref> tag as returned by $this->refArg() |
string | $group | |
string | null | $follow | |
string[] | $call | |
string | $dir | ref direction |
Parser | $parser |
Exception |
Definition at line 462 of file Cite.php.
References $mOutCnt, linkRef(), plainError(), and serialize().
Referenced by guardedRef().
|
private |
Return a warning message based on a warning ID.
string | $key | Message name for the warning. Name should start with cite_warning_ |
string | null | $param | Parameter to pass to the message |
string | $parse | Whether to parse the message ('parse') or not ('noparse') |
Definition at line 1360 of file Cite.php.
References $lang, and wfMessage().
Referenced by referenceText().
|
staticprivate |
|
private |
|
private |
|
private |
boolean Cite::$mInCite = false |
boolean Cite::$mInReferences = false |
|
private |
|
private |
|
private |
|
private |
|
private |
Group used when in <references> block.
Definition at line 172 of file Cite.php.
Referenced by guardedRef().
|
private |
Datastructure representing <ref> input, in the format of: [ 'user supplied' => [ 'text' => 'user supplied reference & key', 'count' => 1, // occurs twice 'number' => 1, // The first reference, we want // all occourances of it to // use the same number ], 0 => 'Anonymous reference', 1 => 'Another anonymous reference', 'some key' => [ 'text' => 'this one occurs once' 'count' => 0, 'number' => 4 ], 3 => 'more stuff' ];
This works because:
const Cite::CACHE_DURATION_ONFETCH = 18000 |
const Cite::CACHE_DURATION_ONPARSE = 3600 |
Cache duration set when parsing a page with references.
Definition at line 55 of file Cite.php.
Referenced by CiteHooks\onLinksUpdate().
const Cite::DATA_VERSION_NUMBER = 1 |
Version number in case we change the data structure in the future.
Definition at line 50 of file Cite.php.
Referenced by saveReferencesData().
const Cite::DEFAULT_GROUP = '' |
Definition at line 34 of file Cite.php.
Referenced by guardedRef(), and guardedReferences().
const Cite::EXT_DATA_KEY = 'Cite:References' |
Key used for storage in parser output's ExtensionData and ObjectCache.
Definition at line 45 of file Cite.php.
Referenced by CiteHooks\onLinksUpdate(), and CiteHooks\onLinksUpdateComplete().
const Cite::MAX_STORAGE_LENGTH = 65535 |
Maximum storage capacity for pp_value field of page_props table.
Definition at line 40 of file Cite.php.
Referenced by CiteHooks\onLinksUpdate().