jenkins-bot has submitted this change and it was merged.
Change subject: Remove dead code
......................................................................
Remove dead code
It turns out nothing is calling this recursive search code
anymore, lets get rid of it.
This does make obvious something we missed when changing things
previously though, the batching of redlink queries for Redlinker
was no longer doing anything. I've filed T91719 to address this.
Change-Id: If0da05ab5762d0a9998b201a986adedf671a3759
(cherry picked from commit a3eabf57116c3f4915875211f70ddd10de151bc2)
---
M includes/Block/Topic.php
M includes/Model/PostRevision.php
M includes/Parsoid/ContentFixer.php
M includes/Parsoid/Fixer.php
M includes/Parsoid/Fixer/BadImageRemover.php
M includes/Parsoid/Fixer/Redlinker.php
M tests/phpunit/Parsoid/Fixer/RedlinkerTest.php
7 files changed, 18 insertions(+), 434 deletions(-)
Approvals:
Mattflaschen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 62db763..99d6beb 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -869,8 +869,8 @@
if ( !$topicTitle ) {
return null;
}
- $post = $root->getRecursiveResult(
$root->registerDescendant( $postId ) );
- if ( !$post ) {
+ $post = $root->getDescendant( $postId );
+ if ( $post === null ) {
// The requested postId is not a member of the
current workflow
$this->addError( 'post', $this->context->msg(
'flow-error-invalid-postId', $postId->getAlphadecimal() ) );
return null;
diff --git a/includes/Model/PostRevision.php b/includes/Model/PostRevision.php
index 0929963..b130a15 100644
--- a/includes/Model/PostRevision.php
+++ b/includes/Model/PostRevision.php
@@ -49,34 +49,6 @@
protected $rootPost;
/**
- * Variables to which callback functions and their results will be
saved.
- *
- * We have some functionality to defer recursive processing through the
post
- * tree up until the moment we actually need to. This makes it possible
to
- * register multiple callback functions that need to be run
recursively, and
- * execute them all one once, so we only have to go recursive once.
- *
- * Callbacks & initial result value will be saved when calling
- * $this->registerRecursive(), final result will be saved after calling
- * $this->descendRecursive().
- * $this->getRecursiveResult() will return the result in
$recursiveResults.
- *
- * @see PostRevision::registerRecursive()
- * @see PostRevision::getRecursiveResult()
- * @see PostRevision::descendRecursive()
- *
- * @var array
- */
- protected $recursiveCallbacks = array();
-
- /**
- * @see PostRevision::$recursiveCallbacks
- *
- * @var array
- */
- protected $recursiveResults = array();
-
- /**
* Create a brand new root post for a brand new topic. Creating
replies to
* an existing post(incl topic root) should use self::reply.
*
@@ -350,183 +322,27 @@
}
/**
- * Runs all registered callback on every descendant of this post.
- *
- * Used to defer going recursive more than once: if all recursive
- * functionality is first registered, we can fetch all results in one
go.
- *
- * @param callable $callback The callback to call. 2 parameters:
- * PostRevision (the post being iterated) & $result (the current result
at
- * time of iteration). They must respond with [ $result, $continue ],
- * where $result is the result after that post's iteration & $continue a
- * boolean value indicating if the iteration still needs to continue
- *
- * @param mixed $init The initial $result value to be fed to the
callback
- * @param string[optional] $label Can be used to make the identifier
- * slightly more descriptive (just simple integers can be quite opaque
when
- * debugging)
- * @return int Identifier to pass to getRecursiveResult() to retrieve
- * the callback's result
- */
- public function registerRecursive( $callback, $init, $label = '' ) {
- $i = count( $this->recursiveResults );
- $identifier = "$i-$label";
-
- $this->recursiveCallbacks[$identifier] = $callback;
- $this->recursiveResults[$identifier] = $init;
-
- return $identifier;
- }
-
- /**
- * Returns the result of a specific callback, after having iterated over
- * all children.
- *
- * @param int $registered The identifier that was returned when
registering
- * the callback via PostRevision::registerRecursive()
- * @return mixed
- */
- public function getRecursiveResult( $registered ) {
- $results = $this->descendRecursive( $this->recursiveCallbacks,
$this->recursiveResults );
- $this->recursiveResults = end( $results );
-
- // Once all callbacks have run, null the callbacks to make sure
they won't run again
- $this->recursiveCallbacks = array_fill( 0, count(
$this->recursiveResults ), null );
-
- return $this->recursiveResults[$registered];
- }
-
- /**
- * Runs all registered callback on this post and all descendants to a
- * maximum depth of $maxDepth
- *
- * @param array $callbacks Array of callbacks to execute. Callbacks are
fed
- * 2 parameters: PostRevision (the post being iterated) & $result (the
current
- * result at time of iteration). They must respond with [ $result,
$continue ],
- * where $result is the result after that post's iteration & $continue a
- * boolean value indicating if the iteration still needs to continue
- * @param array $results Array of (initial or temporary) results per
callback
- * @param int[optional] $maxDepth The maximum depth to travel
- * @return array $results All final results of the callbacks
- */
- protected function descendRecursive( array $callbacks, array $results,
$maxDepth = 10 ) {
- if ( $maxDepth <= 0 ) {
- return array( $callbacks, $results );
- }
-
- $continue = false;
- foreach ( $callbacks as $i => $callback ) {
- if ( is_callable( $callback ) ) {
- $return = call_user_func( $callback, $this,
$results[$i] );
-
- // Callbacks respond with: [ result, continue ]
- // Continue can be set to false if a callback
has completed
- // what it set out to do, then we can stop
running it.
- $results[$i] = $return[0];
- $continue |= $return[1];
-
- // If this specific callback has responded it
should no longer
- // continue, get rid of it.
- if ( $return[1] === false ) {
- $callbacks[$i] = null;
- }
- }
- }
-
- // All of the callbacks have completed what they set out to do
= quit
- if ( $continue ) {
- foreach ( $this->getChildren() as $child ) {
- // Also fetch callbacks from children, some may
have been nulled to
- // prevent further execution.
- list( $callbacks, $results ) =
$child->descendRecursive( $callbacks, $results, $maxDepth - 1 );
-
- // Check to see if we should exit
- if ( ! count( array_filter( $callbacks ) ) ) {
- break;
- }
- }
- }
-
- return array( $callbacks, $results );
- }
-
- /**
- * Registers callback function to calculate the total number of
descendants.
- *
- * @return int $registered The identifier that was returned when
registering
- * the callback via PostRevision::registerRecursive()
- */
- public function registerDescendantCount() {
- /**
- * Adds 1 to the total value per post that's iterated over.
- *
- * @param PostRevision $post
- * @param int $result
- * @return array Return array in the format of [result,
continue]
- */
- $callback = function( PostRevision $post, $result ) {
- return array( $result + 1, true );
- };
-
- // Start at -1 because parent doesn't count as "descendant"
- return $this->registerRecursive( $callback, -1, 'count' );
- }
-
- /**
- * Registers callback function to compile a list of participants.
- *
- * @return int $registered The identifier that was returned when
registering
- * the callback via PostRevision::registerRecursive()
- */
- public function registerParticipants() {
- /**
- * Adds the user object of this post's creator.
- *
- * @param PostRevision $post
- * @param int $result
- * @return array Return array in the format of [result,
continue]
- */
- $callback = function( PostRevision $post, $result ) {
- $id = $post->getCreatorId();
- $ip = $post->getCreatorIp();
- // key is used to prevent duplication
- $key = $id ?: $ip;
- // store id, ip, and (@todo) wiki
- $result[$key] = array( $id, $ip );
-
- return array( $result, true );
- };
-
- return $this->registerRecursive( $callback, array(),
'participants' );
- }
-
- /**
- * Registers callback function to find a specific post within a post's
children.
+ * Finds the provided postId within this posts descendants
*
* @param UUID $postId The id of the post to find.
- * @return int $registered The identifier that was returned when
registering
- * the callback via PostRevision::registerRecursive()
+ * @return PostRevision|null
+ * @throws SomethingException
*/
- public function registerDescendant( $postId ) {
- if ( !$postId instanceof UUID ) {
- $postId = UUID::create( $postId );
+ public function getDescendant( UUID $postId ) {
+ if ( $this->children === null ) {
+ throw new Exception;
+ }
+ foreach ( $this->children as $child ) {
+ if ( $child->getPostId()->equals( $postId ) ) {
+ return $child;
+ }
+ $found = $child->getDescendant( $postId );
+ if ( $found !== null ) {
+ return $found;
+ }
}
- /**
- * Returns the found post.
- *
- * @param PostRevision $post
- * @param int $result
- * @return array Return array in the format of [result,
continue]
- */
- $callback = function( PostRevision $post, $result ) use (
&$postId ) {
- if ( $post->getPostId()->equals( $postId ) ) {
- return array( $post, false );
- }
- return array( false, true );
- };
-
- return $this->registerRecursive( $callback, false,
'descendant-' . $postId->getAlphadecimal() );
+ return null;
}
/**
diff --git a/includes/Parsoid/ContentFixer.php
b/includes/Parsoid/ContentFixer.php
index 6efd988..93efa99 100644
--- a/includes/Parsoid/ContentFixer.php
+++ b/includes/Parsoid/ContentFixer.php
@@ -16,16 +16,6 @@
protected $contentFixers = array();
/**
- * @var PostRevision[] Map of recursion identifiers to related revision
- */
- protected $identifiers = array();
-
- /**
- * @var array Array of registered PostRevision objects [revision id =>
true]
- */
- protected $registered = array();
-
- /**
* Accepts multiple content fixers.
*
* @param Fixer $contentFixer...
@@ -62,9 +52,6 @@
* @return string Html
*/
public function apply( $content, Title $title ) {
- // resolve all registered recursive callbacks
- $this->resolveRecursive();
-
$dom = self::createDOM( $content );
$xpath = new DOMXPath( $dom );
foreach ( $this->contentFixers as $i => $contentFixer ) {
@@ -81,93 +68,6 @@
}
return Utils::getInnerHtml( $dom->getElementsByTagName( 'body'
)->item( 0 ) );
- }
-
- /**
- * Registers callback function to pre-process multiple revisions at
once.
- * This could come in useful to perform multiple operations in batch.
- * Redlinker, for example, will have to resolve links & those will be
batch-
- * loaded and added to LinkCache all at once.
- *
- * This can be registered on multiple revisions to batch-load as much as
- * possible; all of the identifiers have to be saved and will be
processed
- * as soon as they first are needed.
- *
- * @param PostRevision $revision
- */
- public function registerRecursive( PostRevision $revision ) {
- // only register once
- $revisionId = $revision->getRevisionId()->getAlphadecimal();
- if ( isset( $this->registered[$revisionId] ) ) {
- return;
- }
- $this->registered[$revisionId] = true;
- $identifier = $revision->registerRecursive( array( $this,
'recursive' ), array(), __METHOD__ );
- $this->identifiers[$identifier] = $revision;
- }
-
- /**
- * @param PostRevision $post
- * @param array $result
- * @return array
- */
- public function recursive( PostRevision $post, $result ) {
- $dom = self::createDOM( $post->getContent( 'html' ) );
- $xpath = new DOMXPath( $dom );
- foreach ( $this->contentFixers as $i => $contentFixer ) {
- if ( !$contentFixer->isRecursive( $post ) ) {
- continue;
- }
-
- $found = $xpath->query( $contentFixer->getXPath() );
- if ( !$found ) {
- wfDebugLog( 'Flow', __METHOD__ . ': Invalid
XPath from ' . get_class( $contentFixer ) . ' of: ' . $contentFixer->getXPath()
);
- unset( $this->contentFixers[$i] );
- continue;
- }
-
- foreach ( $found as $node ) {
- $contentFixer->recursive( $node );
- }
- }
-
- /**
- * $result wil not be used; we'll register this callback
multiple
- * times and will want to gather overlapping results, so
they'll be
- * stored in the individual fixers
- */
- return array( array(), true );
- }
-
- /**
- * Descends all registered callbacks recursively for all registered
- * revisions, for all content fixers. The results are passed to all
content
- * fixers' resolve() method.
- */
- public function resolveRecursive() {
- if ( !$this->identifiers ) {
- return;
- }
-
- foreach ( $this->identifiers as $identifier => $revision ) {
- /** @var PostRevision $revision */
-
- /*
- * Adding additional content fixers will not cause the
recursive
- * function to be run more - all content fixers will be
resolved
- * at once, the next content fixer fetching his results
will
- * just have them fed from the revision object's inner
cache.
- */
- $revision->getRecursiveResult( $identifier );
- }
-
- /*
- * Notify content fixer we have finished recursive processing,
so it
- * can do whatever needs to be done (like batch-loading stuff)
- */
- foreach ( $this->contentFixers as $contentFixer ) {
- $contentFixer->resolve();
- }
}
/**
diff --git a/includes/Parsoid/Fixer.php b/includes/Parsoid/Fixer.php
index 4c2fe17..93b894c 100644
--- a/includes/Parsoid/Fixer.php
+++ b/includes/Parsoid/Fixer.php
@@ -14,24 +14,7 @@
public function apply( DOMNode $node, Title $title );
/**
- * @param PostRevision $post
- * @return bool Return true when the provided post should be
- * handled with self::recursive
- */
- public function isRecursive( PostRevision $post );
-
- /**
* @return string
*/
public function getXPath();
-
- /**
- * @param DOMNode $node
- */
- public function recursive( DOMNode $node );
-
- /**
- * Run any post-recursive cleanups.
- */
- public function resolve();
}
diff --git a/includes/Parsoid/Fixer/BadImageRemover.php
b/includes/Parsoid/Fixer/BadImageRemover.php
index e590858..4d02231 100644
--- a/includes/Parsoid/Fixer/BadImageRemover.php
+++ b/includes/Parsoid/Fixer/BadImageRemover.php
@@ -83,28 +83,4 @@
}
$nodeToRemove->parentNode->removeChild( $nodeToRemove );
}
-
- /**
- * @param PostRevision $post
- * @return bool
- */
- public function isRecursive( PostRevision $post ) {
- return false;
- }
-
- /**
- * Recursing doesn't make sense here, nothing to batch-load.
- *
- * @param DOMNode $node
- */
- public function recursive( DOMNode $node ) {
- // nothing to do
- }
-
- /**
- * Recursing doesn't make sense here, nothing to batch-load.
- */
- public function resolve() {
- // nothing to do
- }
}
diff --git a/includes/Parsoid/Fixer/Redlinker.php
b/includes/Parsoid/Fixer/Redlinker.php
index fd5e401..c181423 100644
--- a/includes/Parsoid/Fixer/Redlinker.php
+++ b/includes/Parsoid/Fixer/Redlinker.php
@@ -45,47 +45,6 @@
}
/**
- * @param PostRevision $post
- * @return bool
- */
- public function isRecursive( PostRevision $post ) {
- return $post->isFormatted();
- }
-
- /**
- * Collect referenced Title's from html content and add to LinkBatch
- *
- * @param DOMNode $node html to check for titles
- */
- public function recursive( DOMNode $node ) {
- if ( !$node instanceof DOMElement ) {
- return;
- }
-
- $href = $node->getAttribute( 'href' );
- if ( $href === '' ) {
- return;
- }
- // @todo Get proper title in here. doesn't matter currently
due to
- // the html from parsoid using '../../' style of relative
- // that don't strictly require the title its relative from.
- $title = Utils::createRelativeTitle( urldecode( $href ),
Title::newMainPage() );
- if ( $title !== null ) {
- $this->batch->addObj( $title );
- }
- }
-
- /**
- * Execute pending batched title lookup.
- */
- public function resolve() {
- if ( !$this->batch->isEmpty() ) {
- $this->batch->execute();
- $this->batch->setArray( array() );
- }
- }
-
- /**
* Parsoid ignores red links. With good reason: redlinks should only be
* applied when rendering the content, not when it's created.
*
@@ -114,9 +73,6 @@
if ( $title === null ) {
return;
}
-
- // finish any batch loading
- $this->resolve();
// gather existing link attributes
$attributes = array();
diff --git a/tests/phpunit/Parsoid/Fixer/RedlinkerTest.php
b/tests/phpunit/Parsoid/Fixer/RedlinkerTest.php
index 2c21a04..e31a6d4 100644
--- a/tests/phpunit/Parsoid/Fixer/RedlinkerTest.php
+++ b/tests/phpunit/Parsoid/Fixer/RedlinkerTest.php
@@ -71,53 +71,6 @@
$result = $fixer->apply( $anchor, Title::newMainPage() );
$this->assertContains( $expect, $result, $message );
}
-
- public function testRegistersPost() {
- $anchor = Html::element( 'a', array(
- 'rel' => 'mw:WikiLink',
- 'href' => './Main_Page',
- ), 'Main Page' );
-
- $post = $this->generateObject( array(
- // pretend not to be topic title (they're not parsed,
so ignored)
- 'tree_parent_id' => UUID::create()->getBinary(),
- // set content with link
- 'rev_content' => $anchor,
- 'rev_flags' => 'html'
- ) );
-
- $batch = $this->getMock( 'LinkBatch' );
- $batch->expects( $this->once() )
- ->method( 'addObj' )
- ->with( new MethodReturnsConstraint(
- 'getDBkey',
- $this->matches( 'Main_Page' )
- ) );
-
- $fixer = new ContentFixer( new Redlinker( $batch ) );
- $fixer->registerRecursive( $post );
- $fixer->resolveRecursive();
- }
-
- public function testCollectsLinks() {
- $anchor = Html::element( 'a', array(
- 'rel' => 'mw:WikiLink',
- 'href' => './Main_Page',
- ), 'Main Page' );
-
- $batch = $this->getMock( 'LinkBatch' );
- $batch->expects( $this->once() )
- ->method( 'addObj' )
- ->with( new MethodReturnsConstraint(
- 'getDBkey',
- $this->matches( 'Main_Page' )
- ) );
-
- $dom = Utils::createDOM( '<?xml encoding="utf-8"?>' . $anchor );
- $redlink = new Redlinker( $batch );
- $redlink->recursive( $dom->getElementsByTagName( 'a' )->item( 0
) );
- $redlink->resolve();
- }
}
class MethodReturnsConstraint extends \PHPUnit_Framework_Constraint {
--
To view, visit https://gerrit.wikimedia.org/r/196997
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If0da05ab5762d0a9998b201a986adedf671a3759
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: wmf/1.25wmf20
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits