Documentation

This commit is contained in:
Sam Reed 2011-05-28 20:44:24 +00:00
parent 37ff765a58
commit c48d4b674b
4 changed files with 117 additions and 22 deletions

View file

@ -47,6 +47,10 @@ $wgCiteCacheReferences = false;
* Performs the hook registration. * Performs the hook registration.
* Note that several extensions (and even core!) try to detect if Cite is * Note that several extensions (and even core!) try to detect if Cite is
* installed by looking for wfCite(). * installed by looking for wfCite().
*
* @param $parser Parser
*
* @return bool
*/ */
function wfCite( $parser ) { function wfCite( $parser ) {
return Cite::setHooks( $parser ); return Cite::setHooks( $parser );

View file

@ -87,7 +87,6 @@ class Cite {
*/ */
var $mBacklinkLabels; var $mBacklinkLabels;
/** /**
* The links to use per group, in order. * The links to use per group, in order.
* *
@ -96,7 +95,7 @@ class Cite {
var $mLinkLabels = array(); var $mLinkLabels = array();
/** /**
* @var object * @var Parser
*/ */
var $mParser; var $mParser;
@ -141,6 +140,7 @@ class Cite {
/** /**
* Variable holding the singleton. * Variable holding the singleton.
* @var Cite
*/ */
static protected $instance = null; static protected $instance = null;
@ -149,8 +149,10 @@ class Cite {
/** /**
* Callback function for <ref> * Callback function for <ref>
* *
* @param string $str Input * @param $str string Input
* @param array $argv Arguments * @param $argv array Arguments
* @param $parser Parser
*
* @return string * @return string
*/ */
function ref( $str, $argv, $parser ) { function ref( $str, $argv, $parser ) {
@ -165,6 +167,13 @@ class Cite {
} }
} }
/**
* @param $str string Input
* @param $argv array Arguments
* @param $parser Parser
* @param $default_group string
* @return string
*/
function guardedRef( $str, $argv, $parser, $default_group = CITE_DEFAULT_GROUP ) { function guardedRef( $str, $argv, $parser, $default_group = CITE_DEFAULT_GROUP ) {
$this->mParser = $parser; $this->mParser = $parser;
@ -291,9 +300,8 @@ class Cite {
* "group" : Group to which it belongs. Needs to be passed to <references /> too. * "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. * "follow" : If the current reference is the continuation of another, key of that reference.
* *
* @static
* *
* @param array $argv The argument vector * @param $argv array The argument vector
* @return mixed false on invalid input, a string on valid * @return mixed false on invalid input, a string on valid
* input and null on no input * input and null on no input
*/ */
@ -350,8 +358,12 @@ class Cite {
/** /**
* Populate $this->mRefs based on input and arguments to <ref> * Populate $this->mRefs based on input and arguments to <ref>
* *
* @param string $str Input from the <ref> tag * @param $str string Input from the <ref> tag
* @param mixed $key Argument to the <ref> tag as returned by $this->refArg() * @param $key mixed Argument to the <ref> tag as returned by $this->refArg()
* @param $group
* @param $follow
* @param $call
*
* @return string * @return string
*/ */
function stack( $str, $key = null, $group, $follow, $call ) { function stack( $str, $key = null, $group, $follow, $call ) {
@ -453,6 +465,11 @@ class Cite {
* This function is not a total rollback since some internal * This function is not a total rollback since some internal
* counters remain incremented. Doing so prevents accidentally * counters remain incremented. Doing so prevents accidentally
* corrupting certain links. * corrupting certain links.
*
* @param $type
* @param $key
* @param $group
* @param $index
*/ */
function rollbackRef( $type, $key, $group, $index ) { function rollbackRef( $type, $key, $group, $index ) {
if ( !isset( $this->mRefs[$group] ) ) { if ( !isset( $this->mRefs[$group] ) ) {
@ -502,8 +519,10 @@ class Cite {
/** /**
* Callback function for <references> * Callback function for <references>
* *
* @param string $str Input * @param $str string Input
* @param array $argv Arguments * @param $argv array Arguments
* @param $parser Parser
*
* @return string * @return string
*/ */
function references( $str, $argv, $parser ) { function references( $str, $argv, $parser ) {
@ -522,6 +541,13 @@ class Cite {
} }
} }
/**
* @param $str string
* @param $argv array
* @param $parser Parser
* @param $group string
* @return string
*/
function guardedReferences( $str, $argv, $parser, $group = CITE_DEFAULT_GROUP ) { function guardedReferences( $str, $argv, $parser, $group = CITE_DEFAULT_GROUP ) {
global $wgAllowCiteGroups; global $wgAllowCiteGroups;
@ -592,6 +618,8 @@ class Cite {
/** /**
* Make output to be returned from the references() function * Make output to be returned from the references() function
* *
* @param $group
*
* @return string XHTML ready for output * @return string XHTML ready for output
*/ */
function referencesFormat( $group ) { function referencesFormat( $group ) {
@ -845,12 +873,15 @@ class Cite {
* Generate a link (<sup ...) for the <ref> element from a key * Generate a link (<sup ...) for the <ref> element from a key
* and return XHTML ready for output * and return XHTML ready for output
* *
* @param string $key The key for the link * @param $group
* @param int $count The index of the key, used for distinguishing * @param $key string The key for the link
* @param $count int The index of the key, used for distinguishing
* multiple occurances of the same key * multiple occurances of the same key
* @param int $label The label to use for the link, I want to * @param $label int The label to use for the link, I want to
* use the same label for all occourances of * use the same label for all occourances of
* the same named reference. * the same named reference.
* @param $subkey string
*
* @return string * @return string
*/ */
function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) { function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) {
@ -864,7 +895,7 @@ class Cite {
$this->refKey( $key, $count ), $this->refKey( $key, $count ),
$this->referencesKey( $key . $subkey ), $this->referencesKey( $key . $subkey ),
$this->getLinkLabel( $label, $group, $this->getLinkLabel( $label, $group,
( ( $group == CITE_DEFAULT_GROUP ) ? '':"$group " ) . $wgContLang->formatNum( $label ) ) ( ( $group == CITE_DEFAULT_GROUP ) ? '' : "$group " ) . $wgContLang->formatNum( $label ) )
) )
); );
} }
@ -966,6 +997,9 @@ class Cite {
* Generate the labels to pass to the * Generate the labels to pass to the
* 'cite_reference_link' message instead of numbers, the format is an * 'cite_reference_link' message instead of numbers, the format is an
* arbitrary number of tokens separated by [\t\n ] * arbitrary number of tokens separated by [\t\n ]
*
* @param $group
* @param $message
*/ */
function genLinkLabels( $group, $message ) { function genLinkLabels( $group, $message ) {
wfProfileIn( __METHOD__ ); wfProfileIn( __METHOD__ );
@ -981,6 +1015,10 @@ class Cite {
/** /**
* Gets run when Parser::clearState() gets run, since we don't * Gets run when Parser::clearState() gets run, since we don't
* want the counts to transcend pages and other instances * want the counts to transcend pages and other instances
*
* @param $parser Parser
*
* @return bool
*/ */
function clearState( $parser ) { function clearState( $parser ) {
global $wgParser; global $wgParser;
@ -1004,6 +1042,11 @@ class Cite {
/** /**
* Called at the end of page processing to append an error if refs were * Called at the end of page processing to append an error if refs were
* used without a references tag. * used without a references tag.
*
* @param $parser Parser
* @param $text string
*
* @return bool
*/ */
function checkRefsNoReferences( &$parser, &$text ) { function checkRefsNoReferences( &$parser, &$text ) {
if ( $parser->getOptions()->getIsSectionPreview() ) { if ( $parser->getOptions()->getIsSectionPreview() ) {
@ -1027,6 +1070,10 @@ class Cite {
/** /**
* Hook for the InlineEditor extension. If any ref or reference reference tag is in the text, the entire * Hook for the InlineEditor extension. If any ref or reference reference tag is in the text, the entire
* page should be reparsed, so we return false in that case. * page should be reparsed, so we return false in that case.
*
* @param $output
*
* @return bool
*/ */
function checkAnyCalls( &$output ) { function checkAnyCalls( &$output ) {
return ( $this->mCallCnt <= 0 ); return ( $this->mCallCnt <= 0 );
@ -1034,6 +1081,10 @@ class Cite {
/** /**
* Initialize the parser hooks * Initialize the parser hooks
*
* @param $parser Parser
*
* @return bool
*/ */
static function setHooks( $parser ) { static function setHooks( $parser ) {
global $wgHooks; global $wgHooks;

View file

@ -33,6 +33,13 @@ $wgHooks['SkinTemplateToolboxEnd'][] = 'wfSpecialCiteToolbox';
$wgSpecialPages['Cite'] = 'SpecialCite'; $wgSpecialPages['Cite'] = 'SpecialCite';
$wgAutoloadClasses['SpecialCite'] = $dir . 'SpecialCite_body.php'; $wgAutoloadClasses['SpecialCite'] = $dir . 'SpecialCite_body.php';
/**
* @param $skintemplate SkinTemplate
* @param $nav_urls
* @param $oldid
* @param $revid
* @return bool
*/
function wfSpecialCiteNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) { function wfSpecialCiteNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) {
// check whether were in the right namespace, the $revid has the correct type and is not empty // check whether were in the right namespace, the $revid has the correct type and is not empty
// (what would mean that the current page doesnt exist) // (what would mean that the current page doesnt exist)
@ -46,9 +53,13 @@ function wfSpecialCiteNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) {
/** /**
* add the cite link to the toolbar * add the cite link to the toolbar
*
* @param $skin Skin
*
* @return bool
*/ */
function wfSpecialCiteToolbox( &$skin ) { function wfSpecialCiteToolbox( &$skin ) {
global $wgUser; global $wgUser;
if ( isset( $skin->data['nav_urls']['cite'] ) ) { if ( isset( $skin->data['nav_urls']['cite'] ) ) {
echo Html::rawElement( echo Html::rawElement(

View file

@ -32,9 +32,9 @@ class SpecialCite extends SpecialPage {
} }
$cform = new CiteForm( $title ); $cform = new CiteForm( $title );
if ( !$title || ! $article->exists() ) if ( !$title || ! $article->exists() ) {
$cform->execute(); $cform->execute();
else { } else {
$cform->execute(); $cform->execute();
$cout = new CiteOutput( $title, $article, $id ); $cout = new CiteOutput( $title, $article, $id );
@ -44,6 +44,10 @@ class SpecialCite extends SpecialPage {
} }
class CiteForm { class CiteForm {
/**
* @var Title
*/
var $mTitle; var $mTitle;
function __construct( &$title ) { function __construct( &$title ) {
@ -88,8 +92,30 @@ class CiteForm {
} }
class CiteOutput { class CiteOutput {
var $mTitle, $mArticle, $mId;
var $mParser, $mParserOptions, $mSpTitle; /**
* @var Title
*/
var $mTitle;
/**
* @var Article
*/
var $mArticle;
var $mId;
/**
* @var Parser
*/
var $mParser;
/**
* @var ParserOptions
*/
var $mParserOptions;
var $mSpTitle;
function __construct( &$title, &$article, $id ) { function __construct( &$title, &$article, $id ) {
global $wgHooks, $wgParser; global $wgHooks, $wgParser;
@ -138,11 +164,14 @@ class CiteOutput {
return $ret->getText(); return $ret->getText();
} }
function varCache() { return false; } function varCache() {
return false;
}
function timestamp( &$parser, &$ts ) { function timestamp( &$parser, &$ts ) {
if ( isset( $parser->mTagHooks['citation'] ) ) if ( isset( $parser->mTagHooks['citation'] ) ) {
$ts = wfTimestamp( TS_UNIX, $this->mArticle->getTimestamp() ); $ts = wfTimestamp( TS_UNIX, $this->mArticle->getTimestamp() );
}
return true; return true;
} }