Make Cite properly register to any parser instead of just $wgParser.

Makes CiteParserTests work with r82867 code.
This commit is contained in:
Platonides 2011-02-26 22:39:53 +00:00
parent 90a8629d1d
commit 286a80efc1
2 changed files with 21 additions and 16 deletions

View file

@ -43,9 +43,13 @@ $wgAllowCiteGroups = true;
*/ */
$wgCiteCacheReferences = false; $wgCiteCacheReferences = false;
function wfCite() { /**
new Cite; * Performs the hook registration.
return true; * Note that several extensions (and even core!) try to detect if Cite is
* installed by looking for wfCite().
*/
function wfCite( $parser ) {
return Cite::setHooks( $parser );
} }
/**#@-*/ /**#@-*/

View file

@ -45,7 +45,7 @@ class Cite {
* </code> * </code>
* *
* This works because: * This works because:
* * PHP's datastructures are guarenteed to be returned in the * * PHP's datastructures are guaranteed to be returned in the
* order that things are inserted into them (unless you mess * order that things are inserted into them (unless you mess
* with that) * with that)
* * User supplied keys can't be integers, therefore avoiding * * User supplied keys can't be integers, therefore avoiding
@ -133,14 +133,10 @@ class Cite {
*/ */
var $mRefCallStack = array(); var $mRefCallStack = array();
/**#@-*/
/** /**
* Constructor * Variable holding the singleton.
*/ */
function __construct() { static protected $instance = null;
$this->setHooks();
}
/**#@+ @access private */ /**#@+ @access private */
@ -1021,14 +1017,19 @@ class Cite {
/** /**
* Initialize the parser hooks * Initialize the parser hooks
*/ */
function setHooks() { static function setHooks( $parser ) {
global $wgParser, $wgHooks; global $wgHooks;
$wgParser->setHook( 'ref' , array( &$this, 'ref' ) ); if ( !self::$instance ) {
$wgParser->setHook( 'references' , array( &$this, 'references' ) ); self::$instance = new self();
$wgHooks['ParserClearState'][] = array( &$this, 'clearState' ); $wgHooks['ParserClearState'][] = array( self::$instance, 'clearState' );
$wgHooks['ParserBeforeTidy'][] = array( &$this, 'checkRefsNoReferences' ); $wgHooks['ParserBeforeTidy'][] = array( self::$instance, 'checkRefsNoReferences' );
}
$parser->setHook( 'ref' , array( self::$instance, 'ref' ) );
$parser->setHook( 'references' , array( self::$instance, 'references' ) );
return true;
} }
/** /**