http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82870
Revision: 82870
Author: platonides
Date: 2011-02-26 22:39:53 +0000 (Sat, 26 Feb 2011)
Log Message:
-----------
Make Cite properly register to any parser instead of just $wgParser.
Makes CiteParserTests work with r82867 code.
Modified Paths:
--------------
trunk/extensions/Cite/Cite.php
trunk/extensions/Cite/Cite_body.php
Modified: trunk/extensions/Cite/Cite.php
===================================================================
--- trunk/extensions/Cite/Cite.php 2011-02-26 22:37:58 UTC (rev 82869)
+++ trunk/extensions/Cite/Cite.php 2011-02-26 22:39:53 UTC (rev 82870)
@@ -43,9 +43,13 @@
*/
$wgCiteCacheReferences = false;
-function wfCite() {
- new Cite;
- return true;
+/**
+ * Performs the hook registration.
+ * 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 );
}
/**#@-*/
Modified: trunk/extensions/Cite/Cite_body.php
===================================================================
--- trunk/extensions/Cite/Cite_body.php 2011-02-26 22:37:58 UTC (rev 82869)
+++ trunk/extensions/Cite/Cite_body.php 2011-02-26 22:39:53 UTC (rev 82870)
@@ -45,7 +45,7 @@
* </code>
*
* 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
* with that)
* * User supplied keys can't be integers, therefore avoiding
@@ -133,14 +133,10 @@
*/
var $mRefCallStack = array();
- /**#@-*/
-
/**
- * Constructor
+ * Variable holding the singleton.
*/
- function __construct() {
- $this->setHooks();
- }
+ static protected $instance = null;
/**#@+ @access private */
@@ -1021,14 +1017,19 @@
/**
* Initialize the parser hooks
*/
- function setHooks() {
- global $wgParser, $wgHooks;
+ static function setHooks( $parser ) {
+ global $wgHooks;
- $wgParser->setHook( 'ref' , array( &$this, 'ref' ) );
- $wgParser->setHook( 'references' , array( &$this, 'references'
) );
+ if ( !self::$instance ) {
+ self::$instance = new self();
- $wgHooks['ParserClearState'][] = array( &$this, 'clearState' );
- $wgHooks['ParserBeforeTidy'][] = array( &$this,
'checkRefsNoReferences' );
+ $wgHooks['ParserClearState'][] = array(
self::$instance, 'clearState' );
+ $wgHooks['ParserBeforeTidy'][] = array(
self::$instance, 'checkRefsNoReferences' );
+ }
+ $parser->setHook( 'ref' , array( self::$instance, 'ref' ) );
+ $parser->setHook( 'references' , array( self::$instance,
'references' ) );
+
+ return true;
}
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs