Merge "Throttler: improve log message compatibility with Monolog logger"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 16 Nov 2016 00:18:12 +0000 (00:18 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 16 Nov 2016 00:18:12 +0000 (00:18 +0000)
docs/hooks.txt
includes/parser/Parser.php
tests/common/TestsAutoLoader.php
tests/parser/ParserTestMockParser.php [new file with mode: 0644]
tests/parser/ParserTestRunner.php

index 5b707c1..b8d9295 100644 (file)
@@ -2464,6 +2464,13 @@ $revId: ID of the revision that was parsed to create $parserOutput
 'ParserCloned': Called when the parser is cloned.
 $parser: Newly-cloned Parser object
 
+'ParserFetchTemplate': Called when the parser fetches a template
+$parser: Parser Parser object or false
+$title: Title object of the template to be fetched
+$rev: Revision object of the template
+&$text: Transclusion text of the template or false or null
+&$deps: Array of template dependencies with 'title', 'page_id', 'rev_id' keys
+
 'ParserFirstCallInit': Called when the parser initialises for the first time.
 &$parser: Parser object being cleared
 
index c7db8a1..10dfd26 100644 (file)
@@ -3599,6 +3599,9 @@ class Parser {
                                $content = $rev->getContent();
                                $text = $content ? $content->getWikitextForTransclusion() : null;
 
+                               Hooks::run( 'ParserFetchTemplate',
+                                       [ $parser, $title, $rev, &$text, &$deps ] );
+
                                if ( $text === false || $text === null ) {
                                        $text = false;
                                        break;
index 0bfa318..66df315 100644 (file)
@@ -35,6 +35,7 @@ $wgAutoloadClasses += [
        'DjVuSupport' => "$testDir/parser/DjVuSupport.php",
        'TestRecorder' => "$testDir/parser/TestRecorder.php",
        'MultiTestRecorder' => "$testDir/parser/MultiTestRecorder.php",
+       'ParserTestMockParser' => "$testDir/parser/ParserTestMockParser.php",
        'ParserTestRunner' => "$testDir/parser/ParserTestRunner.php",
        'ParserTestParserHook' => "$testDir/parser/ParserTestParserHook.php",
        'ParserTestPrinter' => "$testDir/parser/ParserTestPrinter.php",
diff --git a/tests/parser/ParserTestMockParser.php b/tests/parser/ParserTestMockParser.php
new file mode 100644 (file)
index 0000000..0757b34
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * A parser used during article insertion which does nothing, to avoid
+ * unnecessary log noise and other interference with debugging.
+ */
+class ParserTestMockParser {
+       public function preSaveTransform( $text, Title $title, User $user,
+               ParserOptions $options, $clearState = true
+       ) {
+               return $text;
+       }
+
+       public function parse(
+               $text, Title $title, ParserOptions $options,
+               $linestart = true, $clearState = true, $revid = null
+       ) {
+               return new ParserOutput;
+       }
+}
index e433c2e..04c142a 100644 (file)
@@ -426,7 +426,7 @@ class ParserTestRunner {
         * @param ScopedCallback|null A ScopedCallback to consume
         * @return ScopedCallback
         */
-       protected function createTeardownObject( $teardown, $nextTeardown ) {
+       protected function createTeardownObject( $teardown, $nextTeardown = null ) {
                return new ScopedCallback( function() use ( $teardown, $nextTeardown ) {
                        // Schedule teardown snippets in reverse order
                        $teardown = array_reverse( $teardown );
@@ -1503,7 +1503,14 @@ class ParserTestRunner {
                        throw new MWException( "duplicate article '$name' at $file:$line\n" );
                }
 
+               // Use mock parser, to make debugging of actual parser tests simpler.
+               // But initialise the MessageCache clone first, don't let MessageCache
+               // get a reference to the mock object.
+               MessageCache::singleton()->getParser();
+               $restore = $this->executeSetupSnippets( [ 'wgParser' => new ParserTestMockParser ] );
                $status = $page->doEditContent( ContentHandler::makeContent( $text, $title ), '', EDIT_NEW );
+               $restore();
+
                if ( !$status->isOK() ) {
                        throw new MWException( $status->getWikiText( false, false, 'en' ) );
                }