r82870 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82869‎ | r82870 | r82871 >
Date:22:39, 26 February 2011
Author:platonides
Status:ok
Tags:
Comment:
Make Cite properly register to any parser instead of just $wgParser.
Makes CiteParserTests work with r82867 code.
Modified paths:
  • /trunk/extensions/Cite/Cite.php (modified) (history)
  • /trunk/extensions/Cite/Cite_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Cite/Cite.php
@@ -43,9 +43,13 @@
4444 */
4545 $wgCiteCacheReferences = false;
4646
47 -function wfCite() {
48 - new Cite;
49 - return true;
 47+/**
 48+ * Performs the hook registration.
 49+ * Note that several extensions (and even core!) try to detect if Cite is
 50+ * installed by looking for wfCite().
 51+ */
 52+function wfCite( $parser ) {
 53+ return Cite::setHooks( $parser );
5054 }
5155
5256 /**#@-*/
Index: trunk/extensions/Cite/Cite_body.php
@@ -45,7 +45,7 @@
4646 * </code>
4747 *
4848 * This works because:
49 - * * PHP's datastructures are guarenteed to be returned in the
 49+ * * PHP's datastructures are guaranteed to be returned in the
5050 * order that things are inserted into them (unless you mess
5151 * with that)
5252 * * User supplied keys can't be integers, therefore avoiding
@@ -133,14 +133,10 @@
134134 */
135135 var $mRefCallStack = array();
136136
137 - /**#@-*/
138 -
139137 /**
140 - * Constructor
 138+ * Variable holding the singleton.
141139 */
142 - function __construct() {
143 - $this->setHooks();
144 - }
 140+ static protected $instance = null;
145141
146142 /**#@+ @access private */
147143
@@ -1021,14 +1017,19 @@
10221018 /**
10231019 * Initialize the parser hooks
10241020 */
1025 - function setHooks() {
1026 - global $wgParser, $wgHooks;
 1021+ static function setHooks( $parser ) {
 1022+ global $wgHooks;
10271023
1028 - $wgParser->setHook( 'ref' , array( &$this, 'ref' ) );
1029 - $wgParser->setHook( 'references' , array( &$this, 'references' ) );
 1024+ if ( !self::$instance ) {
 1025+ self::$instance = new self();
10301026
1031 - $wgHooks['ParserClearState'][] = array( &$this, 'clearState' );
1032 - $wgHooks['ParserBeforeTidy'][] = array( &$this, 'checkRefsNoReferences' );
 1027+ $wgHooks['ParserClearState'][] = array( self::$instance, 'clearState' );
 1028+ $wgHooks['ParserBeforeTidy'][] = array( self::$instance, 'checkRefsNoReferences' );
 1029+ }
 1030+ $parser->setHook( 'ref' , array( self::$instance, 'ref' ) );
 1031+ $parser->setHook( 'references' , array( self::$instance, 'references' ) );
 1032+
 1033+ return true;
10331034 }
10341035
10351036 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82867Finally commit the testing stuff I have been with this week. Could be conside...platonides21:49, 26 February 2011

Status & tagging log