http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89220
Revision: 89220
Author: platonides
Date: 2011-05-31 17:49:22 +0000 (Tue, 31 May 2011)
Log Message:
-----------
Remove Cite singleton. Store it inside each associated parser at
$parser->extCite
This fixes bug 20748 and bug 15819 without breaking the other tests. Reverts
r88971.
The conflict with CategoryTree was the old problem of a message being called
inside
of a parser callback, this time with clearState for which the hook is global.
Modified Paths:
--------------
trunk/extensions/Cite/Cite.php
trunk/extensions/Cite/Cite_body.php
Added Paths:
-----------
trunk/extensions/Cite/citeCatTreeParserTests.txt
Modified: trunk/extensions/Cite/Cite.php
===================================================================
--- trunk/extensions/Cite/Cite.php 2011-05-31 17:19:11 UTC (rev 89219)
+++ trunk/extensions/Cite/Cite.php 2011-05-31 17:49:22 UTC (rev 89220)
@@ -27,6 +27,7 @@
'url' => 'http://www.mediawiki.org/wiki/Extension:Cite/Cite.php'
);
$wgParserTestFiles[] = dirname( __FILE__ ) . "/citeParserTests.txt";
+$wgParserTestFiles[] = dirname( __FILE__ ) . "/citeCatTreeParserTests.txt";
$wgExtensionMessagesFiles['Cite'] = dirname( __FILE__ ) . "/Cite.i18n.php";
$wgAutoloadClasses['Cite'] = dirname( __FILE__ ) . "/Cite_body.php";
$wgSpecialPageGroups['Cite'] = 'pagetools';
Modified: trunk/extensions/Cite/Cite_body.php
===================================================================
--- trunk/extensions/Cite/Cite_body.php 2011-05-31 17:19:11 UTC (rev 89219)
+++ trunk/extensions/Cite/Cite_body.php 2011-05-31 17:49:22 UTC (rev 89220)
@@ -139,10 +139,10 @@
var $mRefCallStack = array();
/**
- * Variable holding the singleton.
- * @var Cite
+ * Did we install us into $wgHooks yet?
+ * @var Boolean
*/
- static protected $instance = null;
+ static protected $hooksInstalled = false;
/**#@+ @access private */
@@ -1021,10 +1021,13 @@
* @return bool
*/
function clearState( $parser ) {
- global $wgParser;
+ if ( $parser->extCite !== $this ) {
+ return $parser->extCite->clearState( $parser );
+ }
+
# Don't clear state when we're in the middle of parsing
# a <ref> tag or parsing messages
- if ( $this->mInCite || $this->mInReferences || $parser !==
$wgParser ) {
+ if ( $this->mInCite || $this->mInReferences ) {
return true;
}
@@ -1049,6 +1052,10 @@
* @return bool
*/
function checkRefsNoReferences( &$parser, &$text ) {
+ if ( $parser->extCite !== $this ) {
+ return $parser->extCite->checkRefsNoReferences(
$parser, $text );
+ }
+
if ( $parser->getOptions()->getIsSectionPreview() ) {
return true;
}
@@ -1076,7 +1083,9 @@
* @return bool
*/
function checkAnyCalls( &$output ) {
- return ( $this->mCallCnt <= 0 );
+ global $wgParser;
+ /* InlineEditor always uses $wgParser */
+ return ( $wgParser->extCite->mCallCnt <= 0 );
}
/**
@@ -1089,15 +1098,16 @@
static function setHooks( $parser ) {
global $wgHooks;
- if ( !self::$instance ) {
- self::$instance = new self();
-
- $wgHooks['ParserClearState'][] = array(
self::$instance, 'clearState' );
- $wgHooks['ParserBeforeTidy'][] = array(
self::$instance, 'checkRefsNoReferences' );
- $wgHooks['InlineEditorPartialAfterParse'][] = array(
self::$instance, 'checkAnyCalls' );
+ $parser->extCite = new self();
+
+ if ( !Cite::$hooksInstalled ) {
+ $wgHooks['ParserClearState'][] = array(
$parser->extCite, 'clearState' );
+ $wgHooks['ParserBeforeTidy'][] = array(
$parser->extCite, 'checkRefsNoReferences' );
+ $wgHooks['InlineEditorPartialAfterParse'][] = array(
$parser->extCite, 'checkAnyCalls' );
+ Cite::$hooksInstalled = true;
}
- $parser->setHook( 'ref' , array( self::$instance, 'ref' ) );
- $parser->setHook( 'references' , array( self::$instance,
'references' ) );
+ $parser->setHook( 'ref' , array( $parser->extCite, 'ref' ) );
+ $parser->setHook( 'references' , array( $parser->extCite,
'references' ) );
return true;
}
Added: trunk/extensions/Cite/citeCatTreeParserTests.txt
===================================================================
--- trunk/extensions/Cite/citeCatTreeParserTests.txt
(rev 0)
+++ trunk/extensions/Cite/citeCatTreeParserTests.txt 2011-05-31 17:49:22 UTC
(rev 89220)
@@ -0,0 +1,24 @@
+# Force the test runner to ensure the extension is loaded
+!! hooks
+ref
+references
+categorytree
+!! endhooks
+
+!! test
+Bug 20748 - <references /> doesn't work after category tree in some cases
+!! input
+<ref>ref</ref>
+
+<categorytree showcount=on>Articles tagged for deletion and
rescue</categorytree>
+<references />
+!! result
+<p><sup id="cite_ref-0" class="reference"><a href="#cite_note-0">[1]</a></sup>
+</p>
+<div class=" CategoryTreeTag"><div class="CategoryTreeSection"><div
class="CategoryTreeItem"><span class="CategoryTreeEmptyBullet">[<b>×</b>]
</span> <a class="CategoryTreeLabel CategoryTreeLabelNs14 new
CategoryTreeLabelCategory"
href="/index.php?title=Category:Articles_tagged_for_deletion_and_rescue&action=edit&redlink=1">Articles
tagged for deletion and rescue</a> <span title="contains 0 subcategories, 0
pages, and 0 files">(0)</span></div>
+ <div class="CategoryTreeChildren" style="display:block"><i
class="CategoryTreeNotice">no subcategories</i></div></div>
+ </div>
+<ol class="references"><li id="cite_note-0"><a href="#cite_ref-0">↑</a>
ref</li></ol>
+
+!! end
+
Property changes on: trunk/extensions/Cite/citeCatTreeParserTests.txt
___________________________________________________________________
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs