From 6f49810aa18d6dde54ff8b279dd0b86f1e66c57e Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Wed, 30 Apr 2014 12:44:47 +0200 Subject: [PATCH 01/17] Inserted deletion import --- PubSubHubbubSubscriber.php | 1 + src/DeletionXMLImporter.php | 86 +++++++++++++++++++++++++++++++++++++ src/HookHandler.php | 11 +++++ 3 files changed, 98 insertions(+) create mode 100644 src/DeletionXMLImporter.php diff --git a/PubSubHubbubSubscriber.php b/PubSubHubbubSubscriber.php index 05b2437..7cfaf64 100644 --- a/PubSubHubbubSubscriber.php +++ b/PubSubHubbubSubscriber.php @@ -57,3 +57,4 @@ $wgHooks['LoadExtensionSchemaUpdates'][] = 'PubSubHubbubSubscriber\\HookHandler::onLoadExtensionSchemaUpdates'; $wgHooks['UnitTestsList'][] = 'PubSubHubbubSubscriber\\HookHandler::onUnitTestsList'; +$wgHooks['ImportHandlePageXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; \ No newline at end of file diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php new file mode 100644 index 0000000..00ac397 --- /dev/null +++ b/src/DeletionXMLImporter.php @@ -0,0 +1,86 @@ +reader = $reader; + } + + public function doImport() { + while ( $this->reader->read()) { + $tag = $this->reader->name; + $type = $this->reader->nodeType; + + if ( $tag == 'deletion' && $type == XmlReader::END_ELEMENT ) { + break; + } elseif ( $tag == 'logitem' ) { + $loginfo = $this->parseLogItem(); + } elseif ( $tag != '#text' ) { + $this->warn( "Unhandled deletion XML tag $tag" ); + } + } + $this->doDeletion( $loginfo ); + } + + private function warn( $data ) { + wfDebug( "DeletionXMLImporter: $data\n" ); + } + + private function parseLogItem() { + $logInfo = array(); + $normalFields = array( 'id', 'comment', 'type', 'action', 'timestamp', + 'logtitle', 'params' ); + + while ( $this->reader->read()) { + $tag = $this->reader->name; + $type = $this->reader->nodeType; + if ( $tag == 'logitem' && $type == XmlReader::END_ELEMENT ) { + break; + }elseif ( in_array( $tag, $normalFields ) ) { + $logInfo[$tag] = $this->reader->readInnerXml(); + } elseif ( $tag == 'contributor' ) { + $logInfo['contributor'] = $this->parseContributor(); + } elseif ( $tag != '#text' ) { + $this->warn( "Unhandled log-item XML tag $tag" ); + } + } + return $logInfo; + } + + private function parseContributor() { + $fields = array( 'id', 'ip', 'username' ); + $info = array(); + + while ( $this->reader->read()) { + $tag = $this->reader->name; + $type = $this->reader->nodeType; + if ( $tag == 'contributor' && $type == XmlReader::END_ELEMENT ) { + break; + } + if ( in_array( $tag, $fields ) ) { + $info[$tag] = $this->reader->readInnerXml(); + } + } + return $info; + } + + private function doDeletion( $logInfo ) { + $title = Title::newFromText( $logInfo['logtitle'] ); + $article = new Article( $title ); + $article->doDelete(''); + } +} diff --git a/src/HookHandler.php b/src/HookHandler.php index 7d6593a..d41e0e9 100644 --- a/src/HookHandler.php +++ b/src/HookHandler.php @@ -3,6 +3,7 @@ namespace PubSubHubbubSubscriber; use DatabaseUpdater; +use XMLReader; class HookHandler { @@ -35,4 +36,14 @@ public static function onUnitTestsList( &$files ) { return true; } + public static function onImportHandleToplevelXMLTag( $reader ) { + $tag = $reader->name; + if ( $tag != 'deletion' ) { + return true; + } + $importer = new DeletionXMLImporter( $reader ); + $importer->doImport(); + return false; + } + } From 766e19d63668363f9d7133851e501b2efcd7113b Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Mon, 5 May 2014 16:17:22 +0200 Subject: [PATCH 02/17] Inserted deletion of an article --- PubSubHubbubSubscriber.php | 3 ++- src/DeletionXMLImporter.php | 42 ++++++++++++++++++++++++++++++------- src/HookHandler.php | 2 +- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/PubSubHubbubSubscriber.php b/PubSubHubbubSubscriber.php index 7cfaf64..d82c82f 100644 --- a/PubSubHubbubSubscriber.php +++ b/PubSubHubbubSubscriber.php @@ -52,9 +52,10 @@ $wgAutoloadClasses['PubSubHubbubSubscriber\\Subscription'] = $dir . 'src/Subscription.php'; $wgAutoloadClasses['PubSubHubbubSubscriber\\SubscriptionHandler'] = $dir . 'src/SubscriptionHandler.php'; $wgAutoloadClasses['PubSubHubbubSubscriber\\SubscriberClient'] = $dir . 'src/SubscriberClient.php'; +$wgAutoloadClasses['PubSubHubbubSubscriber\\DeletionXMLImporter'] = $dir . 'src/DeletionXMLImporter.php'; $wgAPIModules['pushcallback'] = 'PubSubHubbubSubscriber\\ApiSubscription'; $wgHooks['LoadExtensionSchemaUpdates'][] = 'PubSubHubbubSubscriber\\HookHandler::onLoadExtensionSchemaUpdates'; $wgHooks['UnitTestsList'][] = 'PubSubHubbubSubscriber\\HookHandler::onUnitTestsList'; -$wgHooks['ImportHandlePageXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; \ No newline at end of file +$wgHooks['ImportHandleToplevelXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; \ No newline at end of file diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php index 00ac397..24a15f5 100644 --- a/src/DeletionXMLImporter.php +++ b/src/DeletionXMLImporter.php @@ -8,15 +8,16 @@ namespace PubSubHubbubSubscriber; -use Article; use Title; +use User; +use WikiPage; use XMLReader; class DeletionXMLImporter { - private $reader; + private $reader = null; - function __construct( XMLReader $reader ) { + public function __construct( XMLReader $reader ) { $this->reader = $reader; } @@ -51,7 +52,7 @@ private function parseLogItem() { if ( $tag == 'logitem' && $type == XmlReader::END_ELEMENT ) { break; }elseif ( in_array( $tag, $normalFields ) ) { - $logInfo[$tag] = $this->reader->readInnerXml(); + $logInfo[$tag] = $this->nodeContents(); } elseif ( $tag == 'contributor' ) { $logInfo['contributor'] = $this->parseContributor(); } elseif ( $tag != '#text' ) { @@ -72,15 +73,42 @@ private function parseContributor() { break; } if ( in_array( $tag, $fields ) ) { - $info[$tag] = $this->reader->readInnerXml(); + $info[$tag] = $this->nodeContents(); } } return $info; } private function doDeletion( $logInfo ) { + if ( isset( $logInfo['contributor']['username'] ) ) { + $user = User::newFromName( $logInfo['contributor']['username'] ); + } + else { + $user = null; + } + $error = array(); $title = Title::newFromText( $logInfo['logtitle'] ); - $article = new Article( $title ); - $article->doDelete(''); + $wikipage = new WikiPage( $title ); + $wikipage->doDeleteArticle( $logInfo['comment'], false, 0, true, $error, $user ); + } + + private function nodeContents() { + if ( $this->reader->isEmptyElement ) { + return ""; + } + $buffer = ""; + while ( $this->reader->read() ) { + switch ( $this->reader->nodeType ) { + case XmlReader::TEXT: + case XmlReader::SIGNIFICANT_WHITESPACE: + $buffer .= $this->reader->value; + break; + case XmlReader::END_ELEMENT: + return $buffer; + } + } + + $this->reader->close(); + return ''; } } diff --git a/src/HookHandler.php b/src/HookHandler.php index d41e0e9..49f996c 100644 --- a/src/HookHandler.php +++ b/src/HookHandler.php @@ -36,7 +36,7 @@ public static function onUnitTestsList( &$files ) { return true; } - public static function onImportHandleToplevelXMLTag( $reader ) { + public static function onImportHandleToplevelXMLTag( XMLReader $reader ) { $tag = $reader->name; if ( $tag != 'deletion' ) { return true; From 73066642ca42811f0531d34ca28cb15397a709c3 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Thu, 8 May 2014 16:09:15 +0200 Subject: [PATCH 03/17] inserted test file --- src/DeletionXMLImporter.php | 7 +----- src/HookHandler.php | 9 +++++++ tests/phpunit/DeletionXMLImporterTest.php | 29 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 tests/phpunit/DeletionXMLImporterTest.php diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php index 24a15f5..fa2fa7c 100644 --- a/src/DeletionXMLImporter.php +++ b/src/DeletionXMLImporter.php @@ -1,10 +1,5 @@ name; if ( $tag != 'deletion' ) { diff --git a/tests/phpunit/DeletionXMLImporterTest.php b/tests/phpunit/DeletionXMLImporterTest.php new file mode 100644 index 0000000..41c6bb9 --- /dev/null +++ b/tests/phpunit/DeletionXMLImporterTest.php @@ -0,0 +1,29 @@ +setMwGlobals( array( + 'wgContLang' => Language::factory( 'en' ), + 'wgLanguageCode' => 'en', + ) ); + } + + protected function tearDown() { + parent::tearDown(); + } + + protected function newDeletionXMLImporter() { + return new + } + +} + \ No newline at end of file From edc6d1e0ba2bf58220807b85190ca8487ce9831f Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Wed, 14 May 2014 14:14:39 +0200 Subject: [PATCH 04/17] Inserted tests for the import of deletions --- src/DeletionXMLImporter.php | 15 +- tests/phpunit/DeletionXMLImporterTest.php | 213 +++++++++++++++++++++- 2 files changed, 220 insertions(+), 8 deletions(-) diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php index fa2fa7c..458e769 100644 --- a/src/DeletionXMLImporter.php +++ b/src/DeletionXMLImporter.php @@ -17,6 +17,7 @@ public function __construct( XMLReader $reader ) { } public function doImport() { + $logInfo = null; while ( $this->reader->read()) { $tag = $this->reader->name; $type = $this->reader->nodeType; @@ -24,19 +25,21 @@ public function doImport() { if ( $tag == 'deletion' && $type == XmlReader::END_ELEMENT ) { break; } elseif ( $tag == 'logitem' ) { - $loginfo = $this->parseLogItem(); + $logInfo = $this->parseLogItem(); } elseif ( $tag != '#text' ) { $this->warn( "Unhandled deletion XML tag $tag" ); } } - $this->doDeletion( $loginfo ); + if ( isset( $logInfo ) ) { + $this->doDeletion( $logInfo ); + } } private function warn( $data ) { wfDebug( "DeletionXMLImporter: $data\n" ); } - private function parseLogItem() { + function parseLogItem() { $logInfo = array(); $normalFields = array( 'id', 'comment', 'type', 'action', 'timestamp', 'logtitle', 'params' ); @@ -57,7 +60,7 @@ private function parseLogItem() { return $logInfo; } - private function parseContributor() { + function parseContributor() { $fields = array( 'id', 'ip', 'username' ); $info = array(); @@ -74,7 +77,7 @@ private function parseContributor() { return $info; } - private function doDeletion( $logInfo ) { + function doDeletion( $logInfo ) { if ( isset( $logInfo['contributor']['username'] ) ) { $user = User::newFromName( $logInfo['contributor']['username'] ); } @@ -87,7 +90,7 @@ private function doDeletion( $logInfo ) { $wikipage->doDeleteArticle( $logInfo['comment'], false, 0, true, $error, $user ); } - private function nodeContents() { + function nodeContents() { if ( $this->reader->isEmptyElement ) { return ""; } diff --git a/tests/phpunit/DeletionXMLImporterTest.php b/tests/phpunit/DeletionXMLImporterTest.php index 41c6bb9..9d57394 100644 --- a/tests/phpunit/DeletionXMLImporterTest.php +++ b/tests/phpunit/DeletionXMLImporterTest.php @@ -4,9 +4,26 @@ namespace PubSubHubbubSubscriber; +use ContentHandler; +use ImportStringSource; use Language; use MediaWikiLangTestCase; +use Revision; +use Title; +use UploadSourceAdapter; +use User; +use WikiPage; +use XMLReader; +/** + * @covers PubSubHubbubSubscriber\DeletionXMLImporter + * + * @group PubSubHubbubSubscriber + * @group Database + * + * @licence GNU GPL v2+ + * @author Sebastian Brückner < sebastian.brueckner@student.hpi.uni-potsdam.de > + */ class DeletionXMLImporterTest extends MediaWikiLangTestCase { protected function setUp() { @@ -15,15 +32,207 @@ protected function setUp() { 'wgContLang' => Language::factory( 'en' ), 'wgLanguageCode' => 'en', ) ); + stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' ); } protected function tearDown() { + stream_wrapper_unregister( 'uploadsource' ); parent::tearDown(); } - protected function newDeletionXMLImporter() { - return new + protected function newDeletionXMLImporter( $XMLString ) { + $reader = new XMLReader(); + $source = new ImportStringSource( $XMLString ); + $id = UploadSourceAdapter::registerSource( $source ); + $reader->open( "uploadsource://$id" ); + $reader->read(); + + return new DeletionXMLImporter( $reader ); + } + + public function addData() { + $this->insertUser( 'TestUser' ); + $this->insertWikipage( 'TestPage', 'TestPage content', 'TestPage comment' ); + } + + /** + * @param string $userName + */ + private function insertUser( $userName ) { + $user = User::newFromName( $userName ); + $user->addToDatabase(); + } + + /** + * @param string $titleName + * @param string $contentText + * @param string $comment + */ + private function insertWikipage( $titleName, $contentText, $comment ) { + $dbw = wfGetDB( DB_MASTER ); + $page = WikiPage::factory( Title::newFromText( $titleName ) ); + + if ( !$page->exists() ) { + $pageId = $page->insertOn( $dbw ); + } else { + $pageId = $page->getId(); + } + + $user = User::newFromName( 'TestUser' ); + $revision = new Revision( array( + 'title' => $page->getTitle(), + 'page' => $pageId, + 'content_model' => $page->getTitle()->getContentModel(), + 'content_format' => $this->getFormat( $page->getTitle() ), + 'text' => $contentText, + 'comment' => $comment, + 'user' => $user->getId(), + 'user_text' => $user->getName(), + 'timestamp' => wfTimestamp( TS_ISO_8601 ), + 'minor_edit' => false, + ) ); + $revision->insertOn( $dbw ); + $changed = $page->updateIfNewerOn( $dbw, $revision ); + + if ( $changed !== false ) { + $page->doEditUpdates( $revision, $user ); + } + } + + /** + * @param Title $title + * @return string + */ + private function getFormat( Title $title ) { + return ContentHandler::getForTitle( $title )->getDefaultFormat(); + } + + function testNodeContentsEmpty() { + $importer = $this->newDeletionXMLImporter( $this->getEmptyXMLNode() ); + $content = $importer->nodeContents(); + $this->assertEquals( '', $content ); + } + + function testNodeContents() { + $importer = $this->newDeletionXMLImporter( $this->getXMLNode() ); + $content = $importer->nodeContents(); + $this->assertEquals( '1', $content ); + } + + /** + * @depends testNodeContents + */ + public function testParseContributor() { + $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); + $logInfo = $importer->parseContributor(); + $this->assertTrue( $logInfo['id'] == 1 && $logInfo['username'] == 'TestUser' ); } + /** + * @depends testParseContributor + */ + public function testParseLogItem() { + $importer = $this->newDeletionXMLImporter( $this->getLogitemXML() ); + $actualLogInfo = $importer->parseLogItem(); + $this->assertEquals( $actualLogInfo, $this->getExpectedLogInfo() ); + } + + public function testDoDeletion() { + $this->addData(); + $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); + $importer->doDeletion( $this->getExpectedLogInfo() ); + $this->wikipageExistsTest(); + } + + /** + * @depends testParseLogItem + * @depends testDoDeletion + */ + public function testDoImport() { + $this->addData(); + $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); + $importer->doImport(); + $this->wikipageExistsTest(); + } + + private function wikipageExistsTest() { + $title = Title::newFromText( 'TestPage' ); + $wikipage = new WikiPage( $title ); + $this->assertFalse( $wikipage->exists() ); + } + + private function getExpectedLogInfo() { + return array ( + 'id'=> '1', + 'comment' => 'content was: "TestPage content"', + 'type' => 'delete', + 'action' => 'delete', + 'timestamp' => '2014-05-13T13:37:27Z', + 'logtitle' => 'TestPage', + 'params' => 'a:0:{}', + 'contributor' => array( + 'id' => 1, + 'username' => 'TestUser' + ) + ); + } + + private function getCompleteDeletionXML() { + $return = << + +1 +2014-05-13T13:37:27Z + +TestUser +1 + +content was: "TestPage content" +delete +delete +TestPage +a:0:{} + + +EOF; + return $return; + } + + private function getContributorXML() { + $return = << +TestUser +1 + +EOF; + return $return; + } + + private function getLogitemXML() { + $return = << +1 +2014-05-13T13:37:27Z + +TestUser +1 + +content was: "TestPage content" +delete +delete +TestPage +a:0:{} + +EOF; + return $return; + } + + private function getEmptyXMLNode() { + return ''; + } + + private function getXMLNode() { + return '1'; + } } \ No newline at end of file From 7aae97a66ad84be8a333871ef1d023c5a2641529 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Wed, 14 May 2014 14:48:49 +0200 Subject: [PATCH 05/17] Codestyle fixes --- src/DeletionXMLImporter.php | 6 +++--- tests/phpunit/DeletionXMLImporterTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php index 458e769..446ac5e 100644 --- a/src/DeletionXMLImporter.php +++ b/src/DeletionXMLImporter.php @@ -18,7 +18,7 @@ public function __construct( XMLReader $reader ) { public function doImport() { $logInfo = null; - while ( $this->reader->read()) { + while ( $this->reader->read() ) { $tag = $this->reader->name; $type = $this->reader->nodeType; @@ -64,7 +64,7 @@ function parseContributor() { $fields = array( 'id', 'ip', 'username' ); $info = array(); - while ( $this->reader->read()) { + while ( $this->reader->read() ) { $tag = $this->reader->name; $type = $this->reader->nodeType; if ( $tag == 'contributor' && $type == XmlReader::END_ELEMENT ) { @@ -78,7 +78,7 @@ function parseContributor() { } function doDeletion( $logInfo ) { - if ( isset( $logInfo['contributor']['username'] ) ) { + if ( isset( $logInfo['contributor']['username'] ) ) { $user = User::newFromName( $logInfo['contributor']['username'] ); } else { diff --git a/tests/phpunit/DeletionXMLImporterTest.php b/tests/phpunit/DeletionXMLImporterTest.php index 9d57394..bcb24ef 100644 --- a/tests/phpunit/DeletionXMLImporterTest.php +++ b/tests/phpunit/DeletionXMLImporterTest.php @@ -123,7 +123,7 @@ function testNodeContents() { * @depends testNodeContents */ public function testParseContributor() { - $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); + $importer = $this->newDeletionXMLImporter( $this->getContributorXML() ); $logInfo = $importer->parseContributor(); $this->assertTrue( $logInfo['id'] == 1 && $logInfo['username'] == 'TestUser' ); } @@ -171,8 +171,8 @@ private function getExpectedLogInfo() { 'logtitle' => 'TestPage', 'params' => 'a:0:{}', 'contributor' => array( - 'id' => 1, - 'username' => 'TestUser' + 'id' => 1, + 'username' => 'TestUser' ) ); } From 8cd512ba8d3d57287c31a5102ddd2a0dc85a6b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Br=C3=BCckner?= Date: Wed, 14 May 2014 15:41:23 +0200 Subject: [PATCH 06/17] Fixed code style and conventions. --- PubSubHubbubSubscriber.php | 2 +- src/DeletionXMLImporter.php | 38 +++++++++++------------ src/HookHandler.php | 3 +- tests/phpunit/DeletionXMLImporterTest.php | 28 ++++++++--------- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/PubSubHubbubSubscriber.php b/PubSubHubbubSubscriber.php index d82c82f..fe8b75e 100644 --- a/PubSubHubbubSubscriber.php +++ b/PubSubHubbubSubscriber.php @@ -58,4 +58,4 @@ $wgHooks['LoadExtensionSchemaUpdates'][] = 'PubSubHubbubSubscriber\\HookHandler::onLoadExtensionSchemaUpdates'; $wgHooks['UnitTestsList'][] = 'PubSubHubbubSubscriber\\HookHandler::onUnitTestsList'; -$wgHooks['ImportHandleToplevelXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; \ No newline at end of file +$wgHooks['ImportHandleToplevelXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php index 446ac5e..f5d8d2c 100644 --- a/src/DeletionXMLImporter.php +++ b/src/DeletionXMLImporter.php @@ -1,6 +1,5 @@ reader = $reader; + $this->mReader = $reader; } public function doImport() { $logInfo = null; - while ( $this->reader->read() ) { - $tag = $this->reader->name; - $type = $this->reader->nodeType; + while ( $this->mReader->read() ) { + $tag = $this->mReader->name; + $type = $this->mReader->nodeType; if ( $tag == 'deletion' && $type == XmlReader::END_ELEMENT ) { break; @@ -41,15 +40,14 @@ private function warn( $data ) { function parseLogItem() { $logInfo = array(); - $normalFields = array( 'id', 'comment', 'type', 'action', 'timestamp', - 'logtitle', 'params' ); + $normalFields = array( 'id', 'comment', 'type', 'action', 'timestamp', 'logtitle', 'params' ); - while ( $this->reader->read()) { - $tag = $this->reader->name; - $type = $this->reader->nodeType; + while ( $this->mReader->read() ) { + $tag = $this->mReader->name; + $type = $this->mReader->nodeType; if ( $tag == 'logitem' && $type == XmlReader::END_ELEMENT ) { break; - }elseif ( in_array( $tag, $normalFields ) ) { + } elseif ( in_array( $tag, $normalFields ) ) { $logInfo[$tag] = $this->nodeContents(); } elseif ( $tag == 'contributor' ) { $logInfo['contributor'] = $this->parseContributor(); @@ -64,9 +62,9 @@ function parseContributor() { $fields = array( 'id', 'ip', 'username' ); $info = array(); - while ( $this->reader->read() ) { - $tag = $this->reader->name; - $type = $this->reader->nodeType; + while ( $this->mReader->read() ) { + $tag = $this->mReader->name; + $type = $this->mReader->nodeType; if ( $tag == 'contributor' && $type == XmlReader::END_ELEMENT ) { break; } @@ -91,22 +89,22 @@ function doDeletion( $logInfo ) { } function nodeContents() { - if ( $this->reader->isEmptyElement ) { + if ( $this->mReader->isEmptyElement ) { return ""; } $buffer = ""; - while ( $this->reader->read() ) { - switch ( $this->reader->nodeType ) { + while ( $this->mReader->read() ) { + switch ( $this->mReader->nodeType ) { case XmlReader::TEXT: case XmlReader::SIGNIFICANT_WHITESPACE: - $buffer .= $this->reader->value; + $buffer .= $this->mReader->value; break; case XmlReader::END_ELEMENT: return $buffer; } } - $this->reader->close(); + $this->mReader->close(); return ''; } } diff --git a/src/HookHandler.php b/src/HookHandler.php index d14f9da..8a0faf5 100644 --- a/src/HookHandler.php +++ b/src/HookHandler.php @@ -41,11 +41,10 @@ public static function onUnitTestsList( &$files ) { * * @see https://www.mediawiki.org/wiki/Manual:Hooks/ImportHandleToplevelXMLTag * - * @codeCoverageIgnore * @param XMLReader $reader * @return bool */ - public static function onImportHandleToplevelXMLTag( XMLReader $reader ) { + public static function onImportHandleToplevelXMLTag( XMLReader $reader ) { $tag = $reader->name; if ( $tag != 'deletion' ) { return true; diff --git a/tests/phpunit/DeletionXMLImporterTest.php b/tests/phpunit/DeletionXMLImporterTest.php index bcb24ef..4da499e 100644 --- a/tests/phpunit/DeletionXMLImporterTest.php +++ b/tests/phpunit/DeletionXMLImporterTest.php @@ -1,9 +1,7 @@ + * @author Alexander Lehmann < alexander.lehmann@student.hpi.uni-potsdam.de > */ class DeletionXMLImporterTest extends MediaWikiLangTestCase { @@ -69,11 +67,10 @@ private function insertUser( $userName ) { * @param string $comment */ private function insertWikipage( $titleName, $contentText, $comment ) { - $dbw = wfGetDB( DB_MASTER ); $page = WikiPage::factory( Title::newFromText( $titleName ) ); if ( !$page->exists() ) { - $pageId = $page->insertOn( $dbw ); + $pageId = $page->insertOn( $this->db ); } else { $pageId = $page->getId(); } @@ -91,8 +88,8 @@ private function insertWikipage( $titleName, $contentText, $comment ) { 'timestamp' => wfTimestamp( TS_ISO_8601 ), 'minor_edit' => false, ) ); - $revision->insertOn( $dbw ); - $changed = $page->updateIfNewerOn( $dbw, $revision ); + $revision->insertOn( $this->db ); + $changed = $page->updateIfNewerOn( $this->db, $revision ); if ( $changed !== false ) { $page->doEditUpdates( $revision, $user ); @@ -125,7 +122,8 @@ function testNodeContents() { public function testParseContributor() { $importer = $this->newDeletionXMLImporter( $this->getContributorXML() ); $logInfo = $importer->parseContributor(); - $this->assertTrue( $logInfo['id'] == 1 && $logInfo['username'] == 'TestUser' ); + $this->assertEquals( 1, $logInfo['id'] ); + $this->assertEquals( 'TestUser', $logInfo['username'] ); } /** @@ -141,7 +139,7 @@ public function testDoDeletion() { $this->addData(); $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); $importer->doDeletion( $this->getExpectedLogInfo() ); - $this->wikipageExistsTest(); + $this->assertWikiPageExists(); } /** @@ -152,13 +150,13 @@ public function testDoImport() { $this->addData(); $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); $importer->doImport(); - $this->wikipageExistsTest(); + $this->assertWikiPageExists(); } - private function wikipageExistsTest() { + private function assertWikiPageExists() { $title = Title::newFromText( 'TestPage' ); - $wikipage = new WikiPage( $title ); - $this->assertFalse( $wikipage->exists() ); + $wikiPage = new WikiPage( $title ); + $this->assertFalse( $wikiPage->exists() ); } private function getExpectedLogInfo() { @@ -234,5 +232,5 @@ private function getEmptyXMLNode() { private function getXMLNode() { return '1'; } + } - \ No newline at end of file From e2351932d4e409787593171b2dd01bddd2a11715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Br=C3=BCckner?= Date: Wed, 14 May 2014 17:57:38 +0200 Subject: [PATCH 07/17] Disabled import hook until fix was accepted into MediaWiki core. --- PubSubHubbubSubscriber.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PubSubHubbubSubscriber.php b/PubSubHubbubSubscriber.php index fe8b75e..be4bd2e 100644 --- a/PubSubHubbubSubscriber.php +++ b/PubSubHubbubSubscriber.php @@ -58,4 +58,6 @@ $wgHooks['LoadExtensionSchemaUpdates'][] = 'PubSubHubbubSubscriber\\HookHandler::onLoadExtensionSchemaUpdates'; $wgHooks['UnitTestsList'][] = 'PubSubHubbubSubscriber\\HookHandler::onUnitTestsList'; -$wgHooks['ImportHandleToplevelXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; +// Disabled until changeset 133064 is accepted into MediaWiki core: +// https://gerrit.wikimedia.org/r/133064 +//$wgHooks['ImportHandleToplevelXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; From 6421edb9d338daaa5a0b775061f49a238a180dcf Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Mon, 19 May 2014 16:10:01 +0200 Subject: [PATCH 08/17] Adapt code to new hooks. --- src/DeletionXMLImporter.php | 42 ++++++----------------- src/HookHandler.php | 12 +++---- tests/phpunit/DeletionXMLImporterTest.php | 37 ++++---------------- 3 files changed, 23 insertions(+), 68 deletions(-) diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php index f5d8d2c..53f93cd 100644 --- a/src/DeletionXMLImporter.php +++ b/src/DeletionXMLImporter.php @@ -4,15 +4,18 @@ use Title; use User; +use WikiImporter; use WikiPage; use XMLReader; class DeletionXMLImporter { private $mReader = null; + private $mImporter = null; - public function __construct( XMLReader $reader ) { - $this->mReader = $reader; + public function __construct( WikiImporter $importer ) { + $this->mImporter = $importer; + $this->mReader = $importer->getReader(); } public function doImport() { @@ -26,7 +29,7 @@ public function doImport() { } elseif ( $tag == 'logitem' ) { $logInfo = $this->parseLogItem(); } elseif ( $tag != '#text' ) { - $this->warn( "Unhandled deletion XML tag $tag" ); + $this->mImporter->warn( "Unhandled deletion XML tag $tag" ); } } if ( isset( $logInfo ) ) { @@ -34,10 +37,6 @@ public function doImport() { } } - private function warn( $data ) { - wfDebug( "DeletionXMLImporter: $data\n" ); - } - function parseLogItem() { $logInfo = array(); $normalFields = array( 'id', 'comment', 'type', 'action', 'timestamp', 'logtitle', 'params' ); @@ -48,11 +47,11 @@ function parseLogItem() { if ( $tag == 'logitem' && $type == XmlReader::END_ELEMENT ) { break; } elseif ( in_array( $tag, $normalFields ) ) { - $logInfo[$tag] = $this->nodeContents(); + $logInfo[$tag] = $this->mImporter->nodeContents(); } elseif ( $tag == 'contributor' ) { $logInfo['contributor'] = $this->parseContributor(); } elseif ( $tag != '#text' ) { - $this->warn( "Unhandled log-item XML tag $tag" ); + $this->mImporter->warn( "Unhandled log-item XML tag $tag" ); } } return $logInfo; @@ -67,9 +66,8 @@ function parseContributor() { $type = $this->mReader->nodeType; if ( $tag == 'contributor' && $type == XmlReader::END_ELEMENT ) { break; - } - if ( in_array( $tag, $fields ) ) { - $info[$tag] = $this->nodeContents(); + } elseif ( in_array( $tag, $fields ) ) { + $info[$tag] = $this->mImporter->nodeContents(); } } return $info; @@ -87,24 +85,4 @@ function doDeletion( $logInfo ) { $wikipage = new WikiPage( $title ); $wikipage->doDeleteArticle( $logInfo['comment'], false, 0, true, $error, $user ); } - - function nodeContents() { - if ( $this->mReader->isEmptyElement ) { - return ""; - } - $buffer = ""; - while ( $this->mReader->read() ) { - switch ( $this->mReader->nodeType ) { - case XmlReader::TEXT: - case XmlReader::SIGNIFICANT_WHITESPACE: - $buffer .= $this->mReader->value; - break; - case XmlReader::END_ELEMENT: - return $buffer; - } - } - - $this->mReader->close(); - return ''; - } } diff --git a/src/HookHandler.php b/src/HookHandler.php index 47a5a6c..3ed0b81 100644 --- a/src/HookHandler.php +++ b/src/HookHandler.php @@ -3,7 +3,7 @@ namespace PubSubHubbubSubscriber; use DatabaseUpdater; -use XMLReader; +use WikiImporter; class HookHandler { @@ -44,16 +44,16 @@ public static function onUnitTestsList( &$files ) { * * @see https://www.mediawiki.org/wiki/Manual:Hooks/ImportHandleToplevelXMLTag * - * @param XMLReader $reader + * @param WikiImporter $reader * @return bool */ - public static function onImportHandleToplevelXMLTag( XMLReader $reader ) { - $tag = $reader->name; + public static function onImportHandleToplevelXMLTag( WikiImporter $importer ) { + $tag = $importer->getReader()->name; if ( $tag != 'deletion' ) { return true; } - $importer = new DeletionXMLImporter( $reader ); - $importer->doImport(); + $deletionImporter = new DeletionXMLImporter( $importer ); + $deletionImporter->doImport(); return false; } diff --git a/tests/phpunit/DeletionXMLImporterTest.php b/tests/phpunit/DeletionXMLImporterTest.php index 4da499e..18cf6a4 100644 --- a/tests/phpunit/DeletionXMLImporterTest.php +++ b/tests/phpunit/DeletionXMLImporterTest.php @@ -4,14 +4,12 @@ use ContentHandler; use ImportStringSource; -use Language; use MediaWikiLangTestCase; use Revision; use Title; -use UploadSourceAdapter; use User; +use WikiImporter; use WikiPage; -use XMLReader; /** * @covers PubSubHubbubSubscriber\DeletionXMLImporter @@ -26,26 +24,16 @@ class DeletionXMLImporterTest extends MediaWikiLangTestCase { protected function setUp() { parent::setUp(); - $this->setMwGlobals( array( - 'wgContLang' => Language::factory( 'en' ), - 'wgLanguageCode' => 'en', - ) ); - stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' ); } protected function tearDown() { - stream_wrapper_unregister( 'uploadsource' ); parent::tearDown(); } protected function newDeletionXMLImporter( $XMLString ) { - $reader = new XMLReader(); $source = new ImportStringSource( $XMLString ); - $id = UploadSourceAdapter::registerSource( $source ); - $reader->open( "uploadsource://$id" ); - $reader->read(); - - return new DeletionXMLImporter( $reader ); + $wikiImporter = new WikiImporter( $source ); + return new DeletionXMLImporter( $wikiImporter ); } public function addData() { @@ -104,26 +92,12 @@ private function getFormat( Title $title ) { return ContentHandler::getForTitle( $title )->getDefaultFormat(); } - function testNodeContentsEmpty() { - $importer = $this->newDeletionXMLImporter( $this->getEmptyXMLNode() ); - $content = $importer->nodeContents(); - $this->assertEquals( '', $content ); - } - - function testNodeContents() { - $importer = $this->newDeletionXMLImporter( $this->getXMLNode() ); - $content = $importer->nodeContents(); - $this->assertEquals( '1', $content ); - } - - /** - * @depends testNodeContents - */ public function testParseContributor() { $importer = $this->newDeletionXMLImporter( $this->getContributorXML() ); $logInfo = $importer->parseContributor(); $this->assertEquals( 1, $logInfo['id'] ); $this->assertEquals( 'TestUser', $logInfo['username'] ); + unset( $importer ); } /** @@ -133,6 +107,7 @@ public function testParseLogItem() { $importer = $this->newDeletionXMLImporter( $this->getLogitemXML() ); $actualLogInfo = $importer->parseLogItem(); $this->assertEquals( $actualLogInfo, $this->getExpectedLogInfo() ); + unset( $importer ); } public function testDoDeletion() { @@ -140,6 +115,7 @@ public function testDoDeletion() { $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); $importer->doDeletion( $this->getExpectedLogInfo() ); $this->assertWikiPageExists(); + unset( $importer ); } /** @@ -151,6 +127,7 @@ public function testDoImport() { $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); $importer->doImport(); $this->assertWikiPageExists(); + unset( $importer ); } private function assertWikiPageExists() { From ff850c8db923760981b5265d397ee3ca596baf4d Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Tue, 20 May 2014 12:53:18 +0200 Subject: [PATCH 09/17] Inserted callback for deletions. Deleted useless TopLevelXMLHook. --- PubSubHubbubSubscriber.php | 5 +- src/DeletionXMLImporter.php | 88 --------- src/HookHandler.php | 19 -- src/SubscriptionHandler.php | 21 +++ tests/phpunit/DeletionXMLImporterTest.php | 213 ---------------------- tests/phpunit/SubscriptionHandlerTest.php | 158 +++++++++++++++- 6 files changed, 176 insertions(+), 328 deletions(-) delete mode 100644 src/DeletionXMLImporter.php delete mode 100644 tests/phpunit/DeletionXMLImporterTest.php diff --git a/PubSubHubbubSubscriber.php b/PubSubHubbubSubscriber.php index be4bd2e..79873c7 100644 --- a/PubSubHubbubSubscriber.php +++ b/PubSubHubbubSubscriber.php @@ -52,12 +52,9 @@ $wgAutoloadClasses['PubSubHubbubSubscriber\\Subscription'] = $dir . 'src/Subscription.php'; $wgAutoloadClasses['PubSubHubbubSubscriber\\SubscriptionHandler'] = $dir . 'src/SubscriptionHandler.php'; $wgAutoloadClasses['PubSubHubbubSubscriber\\SubscriberClient'] = $dir . 'src/SubscriberClient.php'; -$wgAutoloadClasses['PubSubHubbubSubscriber\\DeletionXMLImporter'] = $dir . 'src/DeletionXMLImporter.php'; $wgAPIModules['pushcallback'] = 'PubSubHubbubSubscriber\\ApiSubscription'; $wgHooks['LoadExtensionSchemaUpdates'][] = 'PubSubHubbubSubscriber\\HookHandler::onLoadExtensionSchemaUpdates'; $wgHooks['UnitTestsList'][] = 'PubSubHubbubSubscriber\\HookHandler::onUnitTestsList'; -// Disabled until changeset 133064 is accepted into MediaWiki core: -// https://gerrit.wikimedia.org/r/133064 -//$wgHooks['ImportHandleToplevelXMLTag'][] = 'PubSubHubbubSubscriber\\HookHandler::onImportHandleToplevelXMLTag'; + diff --git a/src/DeletionXMLImporter.php b/src/DeletionXMLImporter.php deleted file mode 100644 index 53f93cd..0000000 --- a/src/DeletionXMLImporter.php +++ /dev/null @@ -1,88 +0,0 @@ -mImporter = $importer; - $this->mReader = $importer->getReader(); - } - - public function doImport() { - $logInfo = null; - while ( $this->mReader->read() ) { - $tag = $this->mReader->name; - $type = $this->mReader->nodeType; - - if ( $tag == 'deletion' && $type == XmlReader::END_ELEMENT ) { - break; - } elseif ( $tag == 'logitem' ) { - $logInfo = $this->parseLogItem(); - } elseif ( $tag != '#text' ) { - $this->mImporter->warn( "Unhandled deletion XML tag $tag" ); - } - } - if ( isset( $logInfo ) ) { - $this->doDeletion( $logInfo ); - } - } - - function parseLogItem() { - $logInfo = array(); - $normalFields = array( 'id', 'comment', 'type', 'action', 'timestamp', 'logtitle', 'params' ); - - while ( $this->mReader->read() ) { - $tag = $this->mReader->name; - $type = $this->mReader->nodeType; - if ( $tag == 'logitem' && $type == XmlReader::END_ELEMENT ) { - break; - } elseif ( in_array( $tag, $normalFields ) ) { - $logInfo[$tag] = $this->mImporter->nodeContents(); - } elseif ( $tag == 'contributor' ) { - $logInfo['contributor'] = $this->parseContributor(); - } elseif ( $tag != '#text' ) { - $this->mImporter->warn( "Unhandled log-item XML tag $tag" ); - } - } - return $logInfo; - } - - function parseContributor() { - $fields = array( 'id', 'ip', 'username' ); - $info = array(); - - while ( $this->mReader->read() ) { - $tag = $this->mReader->name; - $type = $this->mReader->nodeType; - if ( $tag == 'contributor' && $type == XmlReader::END_ELEMENT ) { - break; - } elseif ( in_array( $tag, $fields ) ) { - $info[$tag] = $this->mImporter->nodeContents(); - } - } - return $info; - } - - function doDeletion( $logInfo ) { - if ( isset( $logInfo['contributor']['username'] ) ) { - $user = User::newFromName( $logInfo['contributor']['username'] ); - } - else { - $user = null; - } - $error = array(); - $title = Title::newFromText( $logInfo['logtitle'] ); - $wikipage = new WikiPage( $title ); - $wikipage->doDeleteArticle( $logInfo['comment'], false, 0, true, $error, $user ); - } -} diff --git a/src/HookHandler.php b/src/HookHandler.php index 3ed0b81..88fdd42 100644 --- a/src/HookHandler.php +++ b/src/HookHandler.php @@ -38,23 +38,4 @@ public static function onUnitTestsList( &$files ) { $files = array_merge( $files, glob( __DIR__ . '/../tests/phpunit/*Test.php' ) ); return true; } - - /** - * Called when parsing a top level XML tag. - * - * @see https://www.mediawiki.org/wiki/Manual:Hooks/ImportHandleToplevelXMLTag - * - * @param WikiImporter $reader - * @return bool - */ - public static function onImportHandleToplevelXMLTag( WikiImporter $importer ) { - $tag = $importer->getReader()->name; - if ( $tag != 'deletion' ) { - return true; - } - $deletionImporter = new DeletionXMLImporter( $importer ); - $deletionImporter->doImport(); - return false; - } - } diff --git a/src/SubscriptionHandler.php b/src/SubscriptionHandler.php index 2945c0b..b68b71a 100644 --- a/src/SubscriptionHandler.php +++ b/src/SubscriptionHandler.php @@ -3,7 +3,10 @@ namespace PubSubHubbubSubscriber; use ImportStreamSource; +use User; use WikiImporter; +use WikiPage; +use WikiRevision; class SubscriptionHandler { @@ -16,6 +19,7 @@ public function handlePush( $file = "php://input" ) { $source = ImportStreamSource::newFromFile( $file ); if ( $source->isGood() ) { $importer = new WikiImporter( $source->value ); + $importer->setLogItemCallback( array( &$this, 'deletionPage' ) ); $importer->doImport(); return true; } else { @@ -23,6 +27,23 @@ public function handlePush( $file = "php://input" ) { } } + public function deletionPage( WikiRevision $revision ) { + if ( $revision->getAction() != 'delete' ){ + return; + } + $username = $revision->getUser(); + if ( !empty( $username ) ) { + $user = User::newFromName( $username ); + } + else { + $user = null; + } + $error = array(); + $title = $revision->getTitle(); + $wikipage = new WikiPage( $title ); + $wikipage->doDeleteArticle( $revision->getComment(), false, 0, true, $error, $user ); + } + /** * @param string $topic * @param int $lease_seconds diff --git a/tests/phpunit/DeletionXMLImporterTest.php b/tests/phpunit/DeletionXMLImporterTest.php deleted file mode 100644 index 18cf6a4..0000000 --- a/tests/phpunit/DeletionXMLImporterTest.php +++ /dev/null @@ -1,213 +0,0 @@ - - */ -class DeletionXMLImporterTest extends MediaWikiLangTestCase { - - protected function setUp() { - parent::setUp(); - } - - protected function tearDown() { - parent::tearDown(); - } - - protected function newDeletionXMLImporter( $XMLString ) { - $source = new ImportStringSource( $XMLString ); - $wikiImporter = new WikiImporter( $source ); - return new DeletionXMLImporter( $wikiImporter ); - } - - public function addData() { - $this->insertUser( 'TestUser' ); - $this->insertWikipage( 'TestPage', 'TestPage content', 'TestPage comment' ); - } - - /** - * @param string $userName - */ - private function insertUser( $userName ) { - $user = User::newFromName( $userName ); - $user->addToDatabase(); - } - - /** - * @param string $titleName - * @param string $contentText - * @param string $comment - */ - private function insertWikipage( $titleName, $contentText, $comment ) { - $page = WikiPage::factory( Title::newFromText( $titleName ) ); - - if ( !$page->exists() ) { - $pageId = $page->insertOn( $this->db ); - } else { - $pageId = $page->getId(); - } - - $user = User::newFromName( 'TestUser' ); - $revision = new Revision( array( - 'title' => $page->getTitle(), - 'page' => $pageId, - 'content_model' => $page->getTitle()->getContentModel(), - 'content_format' => $this->getFormat( $page->getTitle() ), - 'text' => $contentText, - 'comment' => $comment, - 'user' => $user->getId(), - 'user_text' => $user->getName(), - 'timestamp' => wfTimestamp( TS_ISO_8601 ), - 'minor_edit' => false, - ) ); - $revision->insertOn( $this->db ); - $changed = $page->updateIfNewerOn( $this->db, $revision ); - - if ( $changed !== false ) { - $page->doEditUpdates( $revision, $user ); - } - } - - /** - * @param Title $title - * @return string - */ - private function getFormat( Title $title ) { - return ContentHandler::getForTitle( $title )->getDefaultFormat(); - } - - public function testParseContributor() { - $importer = $this->newDeletionXMLImporter( $this->getContributorXML() ); - $logInfo = $importer->parseContributor(); - $this->assertEquals( 1, $logInfo['id'] ); - $this->assertEquals( 'TestUser', $logInfo['username'] ); - unset( $importer ); - } - - /** - * @depends testParseContributor - */ - public function testParseLogItem() { - $importer = $this->newDeletionXMLImporter( $this->getLogitemXML() ); - $actualLogInfo = $importer->parseLogItem(); - $this->assertEquals( $actualLogInfo, $this->getExpectedLogInfo() ); - unset( $importer ); - } - - public function testDoDeletion() { - $this->addData(); - $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); - $importer->doDeletion( $this->getExpectedLogInfo() ); - $this->assertWikiPageExists(); - unset( $importer ); - } - - /** - * @depends testParseLogItem - * @depends testDoDeletion - */ - public function testDoImport() { - $this->addData(); - $importer = $this->newDeletionXMLImporter( $this->getCompleteDeletionXML() ); - $importer->doImport(); - $this->assertWikiPageExists(); - unset( $importer ); - } - - private function assertWikiPageExists() { - $title = Title::newFromText( 'TestPage' ); - $wikiPage = new WikiPage( $title ); - $this->assertFalse( $wikiPage->exists() ); - } - - private function getExpectedLogInfo() { - return array ( - 'id'=> '1', - 'comment' => 'content was: "TestPage content"', - 'type' => 'delete', - 'action' => 'delete', - 'timestamp' => '2014-05-13T13:37:27Z', - 'logtitle' => 'TestPage', - 'params' => 'a:0:{}', - 'contributor' => array( - 'id' => 1, - 'username' => 'TestUser' - ) - ); - } - - private function getCompleteDeletionXML() { - $return = << - -1 -2014-05-13T13:37:27Z - -TestUser -1 - -content was: "TestPage content" -delete -delete -TestPage -a:0:{} - - -EOF; - return $return; - } - - private function getContributorXML() { - $return = << -TestUser -1 - -EOF; - return $return; - } - - private function getLogitemXML() { - $return = << -1 -2014-05-13T13:37:27Z - -TestUser -1 - -content was: "TestPage content" -delete -delete -TestPage -a:0:{} - -EOF; - return $return; - } - - private function getEmptyXMLNode() { - return ''; - } - - private function getXMLNode() { - return '1'; - } - -} diff --git a/tests/phpunit/SubscriptionHandlerTest.php b/tests/phpunit/SubscriptionHandlerTest.php index 535ebfc..ad9d669 100644 --- a/tests/phpunit/SubscriptionHandlerTest.php +++ b/tests/phpunit/SubscriptionHandlerTest.php @@ -2,11 +2,14 @@ namespace PubSubHubbubSubscriber; +use ContentHandler; use Language; use MediaWikiLangTestCase; use Revision; use Title; +use User; use WikiPage; +use WikiRevision; /** * @covers PubSubHubbubSubscriber\SubscriptionHandler @@ -26,10 +29,6 @@ class SubscriptionHandlerTest extends MediaWikiLangTestCase { protected function setUp() { parent::setUp(); - $this->setMwGlobals( array( - 'wgContLang' => Language::factory( 'en' ), - 'wgLanguageCode' => 'en', - ) ); $this->tablesUsed[] = 'push_subscriptions'; $this->mHandler = new SubscriptionHandler(); @@ -56,6 +55,40 @@ public function testHandlePushSuccessful( $xml ) { $this->assertEquals( "This is a Test Page.", $text ); } + /** + * @dataProvider getDeletionRevision + */ + public function testDeletionPage( WikiRevision $revision ) { + $this->addData(); + $wikiPage = new WikiPage( $revision->getTitle() ); + $this->mHandler->deletionPage( $revision ); + $this->assertFalse( $wikiPage->exists() ); + } + + /** + * @dataProvider getNoDeletionRevision + */ + public function testDeletionPageNoDelete( WikiRevision $revision ) { + $this->addData(); + $wikiPage = new WikiPage( $revision->getTitle() ); + $this->mHandler->deletionPage( $revision ); + $this->assertTrue( $wikiPage->exists() ); + } + + /** + * @dataProvider getXMLPushDeletionData + * @param string $xml The XML dump to import. + */ + public function testHandlePushDeletion( $xml ) { + $this->addData(); + $file = 'data:application/xml,' . $xml; + $this->mHandler->handlePush( $file ); + + $title = Title::newFromText( 'TestPage' ); + $wikiPage = new WikiPage( $title ); + $this->assertfalse( $wikiPage->exists() ); + } + public function testHandleSubscribeNonExistent() { $success = $this->mHandler->handleSubscribe( "http://some.nonexistent.topic/", 1337 ); $this->assertFalse( $success ); @@ -107,6 +140,99 @@ public function testHandleUnsubscribeSuccessful() { $this->assertNull( $subscription ); } + public function addData() { + $this->insertUser( 'TestUser' ); + $this->insertWikipage( 'TestPage', 'TestPage content', 'TestPage comment' ); + } + + /** + * @param string $userName + */ + public function insertUser( $userName ) { + $user = User::newFromName( $userName ); + $user->addToDatabase(); + } + + /** + * @param string $titleName + * @param string $contentText + * @param string $comment + */ + public function insertWikipage( $titleName, $contentText, $comment ) { + $page = WikiPage::factory( Title::newFromText( $titleName ) ); + + if ( !$page->exists() ) { + $pageId = $page->insertOn( $this->db ); + } else { + $pageId = $page->getId(); + } + + $user = User::newFromName( 'TestUser' ); + $revision = new Revision( array( + 'title' => $page->getTitle(), + 'page' => $pageId, + 'content_model' => $page->getTitle()->getContentModel(), + 'content_format' => $this->getFormat( $page->getTitle() ), + 'text' => $contentText, + 'comment' => $comment, + 'user' => $user->getId(), + 'user_text' => $user->getName(), + 'timestamp' => wfTimestamp( TS_ISO_8601 ), + 'minor_edit' => false, + ) ); + $revision->insertOn( $this->db ); + $changed = $page->updateIfNewerOn( $this->db, $revision ); + + if ( $changed !== false ) { + $page->doEditUpdates( $revision, $user ); + } + } + + /** + * @param Title $title + * @return string + */ + private function getFormat( Title $title ) { + return ContentHandler::getForTitle( $title )->getDefaultFormat(); + } + + public function getDeletionRevision() { + $data = array(); + + $revision = $this->getBaseRevision(); + $revision->setType( 'delete' ); + $revision->setAction( 'delete' ); + $revision->setUserName( 'TestUser' ); + array_push( $data, array( $revision ) ); + + $revision = $this->getBaseRevision(); + $revision->setType( 'delete' ); + $revision->setAction( 'delete' ); + array_push( $data, array( $revision ) ); + + return $data; + } + + public function getNoDeletionRevision() { + $revision = $this->getBaseRevision(); + $revision->setType( 'move' ); + $revision->setAction( 'move' ); + $revision->setUserName( 'TestUser' ); + return array( array( $revision ) ); + } + + public function getBaseRevision() { + $revision = new WikiRevision; + + $revision->setID( 1 ); + $revision->setTimestamp( wfTimestampNow() ); + $revision->setParams( 'a:0:{}' ); + $revision->setTitle( Title::newFromText( 'TestPage' ) ); + $revision->setNoUpdates( true ); + + return $revision; + } + public function getXMLPushData() { return array( array( @@ -130,6 +256,30 @@ public function getXMLPushData() { +EOF + ) + ); + } + + public function getXMLPushDeletionData() { + return array( + array( + <<< EOF + + + 70 + 2014-05-20T09:49:33Z + + TestUser + 1 + + content was: "test" (and the only contributor was "[[Special:Contributions/Root|Root]]") + delete + delete + TestPage + a:0:{} + + EOF ) ); From 5674bd1f6af988ec2eb35d5d021bc86ebf4d21e1 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Mon, 26 May 2014 17:17:02 +0200 Subject: [PATCH 10/17] Inserted page redirection. --- src/SubscriptionHandler.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/SubscriptionHandler.php b/src/SubscriptionHandler.php index 6317bab..549adfb 100644 --- a/src/SubscriptionHandler.php +++ b/src/SubscriptionHandler.php @@ -3,6 +3,7 @@ namespace PubSubHubbubSubscriber; use ImportStreamSource; +use Title; use User; use MWTimestamp; use WikiImporter; @@ -11,6 +12,8 @@ class SubscriptionHandler { + private $previousPageOutCallback; + /** * @param string $file The file to read the POST data from. Defaults to stdin. * @return bool whether the pushed data could be accepted. @@ -21,6 +24,7 @@ public function handlePush( $file = "php://input" ) { if ( $source->isGood() ) { $importer = new WikiImporter( $source->value ); $importer->setLogItemCallback( array( &$this, 'deletionPage' ) ); + $this->previousPageOutCallback = $importer->setPageOutCallback( array( &$this, ' createRedirectPage' ) ); $importer->doImport(); return true; } else { @@ -45,6 +49,38 @@ public function deletionPage( WikiRevision $revision ) { $wikipage->doDeleteArticle( $revision->getComment(), false, 0, true, $error, $user ); } + private function callOriginalPageOutCallback( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + if ( is_callable( $this->previousPageOutCallback) ) { + call_user_func_array( $this->previousPageOutCallback, func_get_args() ); + } + } + + public function createRedirectPage( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + if ( !array_key_exists( 'redirect', $pageInfo ) ) { + $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + return; + } + $wikipage = new WikiPage( $title ); + $redirectTitle = Title::newFromText( $pageInfo['redirect'] ); + if ($redirectTitle->exists()){ + $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + return; + } + + $dbw = wfGetDB( DB_MASTER ); + $pageId = $wikipage->getId(); + $currentRevision = $wikipage->getRevision(); + $contentRevision = $currentRevision->getPrevious(); + $currentRevisionID = $currentRevision->getId(); + $contentRevisionID = $contentRevision->getId(); + + $dbw->delete( 'revision', array( 'rev_id' => $currentRevisionID ) ); + $dbw->update( 'page', array( 'page_latest' => $contentRevisionID ), array( 'page_id' => $pageId ) ); + $title->moveTo( $redirectTitle ); + + $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + } + /** * @param string $topic * @param int $lease_seconds From 6ea5c51cec6e0bfb70129db827aa0c90a175de64 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Tue, 27 May 2014 14:03:07 +0200 Subject: [PATCH 11/17] Inserted debug log --- src/SubscriptionHandler.php | 12 ++++++---- tests/phpunit/SubscriptionHandlerTest.php | 27 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/SubscriptionHandler.php b/src/SubscriptionHandler.php index 549adfb..8de023a 100644 --- a/src/SubscriptionHandler.php +++ b/src/SubscriptionHandler.php @@ -24,7 +24,7 @@ public function handlePush( $file = "php://input" ) { if ( $source->isGood() ) { $importer = new WikiImporter( $source->value ); $importer->setLogItemCallback( array( &$this, 'deletionPage' ) ); - $this->previousPageOutCallback = $importer->setPageOutCallback( array( &$this, ' createRedirectPage' ) ); + $this->previousPageOutCallback = $importer->setPageOutCallback( array( &$this, 'createRedirectPage' ) ); $importer->doImport(); return true; } else { @@ -56,17 +56,19 @@ private function callOriginalPageOutCallback( Title $title, $origTitle, $revCoun } public function createRedirectPage( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { - if ( !array_key_exists( 'redirect', $pageInfo ) ) { + wfDebugLog('PubSubHubbubSubscriber', 'Start redirect Page'); + if ( !array_key_exists( 'redirect', $pageInfo ) || $sucCount < 1 ) { $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); return; } + wfDebugLog('PubSubHubbubSubscriber', 'Is a redirect Page'); $wikipage = new WikiPage( $title ); $redirectTitle = Title::newFromText( $pageInfo['redirect'] ); - if ($redirectTitle->exists()){ + if ( $redirectTitle->exists() ){ $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); return; } - + wfDebugLog('PubSubHubbubSubscriber', 'Init DB'); $dbw = wfGetDB( DB_MASTER ); $pageId = $wikipage->getId(); $currentRevision = $wikipage->getRevision(); @@ -74,8 +76,10 @@ public function createRedirectPage( Title $title, $origTitle, $revCount, $sucCou $currentRevisionID = $currentRevision->getId(); $contentRevisionID = $contentRevision->getId(); + wfDebugLog('PubSubHubbubSubscriber', 'Start DB'); $dbw->delete( 'revision', array( 'rev_id' => $currentRevisionID ) ); $dbw->update( 'page', array( 'page_latest' => $contentRevisionID ), array( 'page_id' => $pageId ) ); + wfDebugLog('PubSubHubbubSubscriber', 'Move'); $title->moveTo( $redirectTitle ); $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); diff --git a/tests/phpunit/SubscriptionHandlerTest.php b/tests/phpunit/SubscriptionHandlerTest.php index 8f1db83..4e883cc 100644 --- a/tests/phpunit/SubscriptionHandlerTest.php +++ b/tests/phpunit/SubscriptionHandlerTest.php @@ -46,7 +46,6 @@ public function testHandlePushFail() { public function testHandlePushSuccessful( $xml ) { $file = 'data:application/xml,' . $xml; $this->mHandler->handlePush( $file ); - $title = Title::newFromText( 'Unit Test Page' ); $page = WikiPage::factory( $title ); $revision = Revision::newFromPageId( $page->getId() ); @@ -286,3 +285,29 @@ public function getXMLPushDeletionData() { } } + +/* array( + <<< EOF + + + TestPage + 0 + 5 + + + 100 + 99 + 2015-04-24T13:37:42Z + + 127.0.0.1 + + This is a Test Page. + lg0sq0pjm7cngi77vxtmmeko4o7pho6 + wikitext + text/x-wiki + + + +EOF + ) + ); */ From 59d2ecf5c18ab88880ec45eeeaad0e19c8ae168d Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Tue, 27 May 2014 17:17:18 +0200 Subject: [PATCH 12/17] Fix move page, hopefully --- src/SubscriptionHandler.php | 11 ++---- tests/phpunit/SubscriptionHandlerTest.php | 48 ++++++++++++++++++----- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/SubscriptionHandler.php b/src/SubscriptionHandler.php index 8de023a..1ed6a1f 100644 --- a/src/SubscriptionHandler.php +++ b/src/SubscriptionHandler.php @@ -56,19 +56,18 @@ private function callOriginalPageOutCallback( Title $title, $origTitle, $revCoun } public function createRedirectPage( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { - wfDebugLog('PubSubHubbubSubscriber', 'Start redirect Page'); - if ( !array_key_exists( 'redirect', $pageInfo ) || $sucCount < 1 ) { + if ( !array_key_exists( 'redirect', $pageInfo ) || $pageInfo['redirect'] == "" || $sucCount < 1 ) { $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); return; } - wfDebugLog('PubSubHubbubSubscriber', 'Is a redirect Page'); + $wikipage = new WikiPage( $title ); $redirectTitle = Title::newFromText( $pageInfo['redirect'] ); if ( $redirectTitle->exists() ){ $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); return; } - wfDebugLog('PubSubHubbubSubscriber', 'Init DB'); + $dbw = wfGetDB( DB_MASTER ); $pageId = $wikipage->getId(); $currentRevision = $wikipage->getRevision(); @@ -76,11 +75,9 @@ public function createRedirectPage( Title $title, $origTitle, $revCount, $sucCou $currentRevisionID = $currentRevision->getId(); $contentRevisionID = $contentRevision->getId(); - wfDebugLog('PubSubHubbubSubscriber', 'Start DB'); $dbw->delete( 'revision', array( 'rev_id' => $currentRevisionID ) ); $dbw->update( 'page', array( 'page_latest' => $contentRevisionID ), array( 'page_id' => $pageId ) ); - wfDebugLog('PubSubHubbubSubscriber', 'Move'); - $title->moveTo( $redirectTitle ); + $title->moveTo( $redirectTitle, false ); $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); } diff --git a/tests/phpunit/SubscriptionHandlerTest.php b/tests/phpunit/SubscriptionHandlerTest.php index 4e883cc..7376d11 100644 --- a/tests/phpunit/SubscriptionHandlerTest.php +++ b/tests/phpunit/SubscriptionHandlerTest.php @@ -29,6 +29,9 @@ class SubscriptionHandlerTest extends MediaWikiLangTestCase { protected function setUp() { parent::setUp(); + global $wgContLang, $wgLanguageCode; + $wgContLang = Language::factory( 'en' ); + $wgLanguageCode = 'en'; $this->tablesUsed[] = 'push_subscriptions'; $this->mHandler = new SubscriptionHandler(); @@ -39,6 +42,29 @@ public function testHandlePushFail() { $this->assertFalse( $success ); } + /** + * + */ + public function testHandlePushRedirect() { + $this->addData(); + sleep( 1 ); + $xml = $this->getXMLPushRedirectData(); + + $file = 'data:application/xml,' . $xml; + $this->mHandler->handlePush( $file ); + + $orginalTitle = Title::newFromText( 'TestPage' ); + $orginalPage = WikiPage::factory( $orginalTitle ); + + $redirectTitle = Title::newFromText( 'Redirect TestPage' ); + $redirectPage = WikiPage::factory( $redirectTitle ); + + $this->assertTrue( $redirectPage->exists() ); + + $text = $orginalPage->getContent()->getNativeData(); + $this->assertEquals( "This is a Test Page.", $text ); + } + /** * @dataProvider getXMLPushData * @param string $xml The XML dump to import. @@ -46,6 +72,7 @@ public function testHandlePushFail() { public function testHandlePushSuccessful( $xml ) { $file = 'data:application/xml,' . $xml; $this->mHandler->handlePush( $file ); + $title = Title::newFromText( 'Unit Test Page' ); $page = WikiPage::factory( $title ); $revision = Revision::newFromPageId( $page->getId() ); @@ -282,12 +309,10 @@ public function getXMLPushDeletionData() { EOF ) ); - } - } -/* array( - <<< EOF + public function getXMLPushRedirectData() { + $xml = <<< EOF TestPage @@ -297,17 +322,22 @@ public function getXMLPushDeletionData() { 100 99 - 2015-04-24T13:37:42Z + 127.0.0.1 - This is a Test Page. + #REDIRECT [[TestPage]] lg0sq0pjm7cngi77vxtmmeko4o7pho6 wikitext text/x-wiki -EOF - ) - ); */ +EOF; + $xml = preg_replace('~.*?~', '' . wfTimestamp( TS_ISO_8601, wfTimestampNow() ) + . '', $xml ); + return $xml; + +} + +} From 5d4d35e9c2dfa133b8d1508d1ba8ff78a281ae86 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Wed, 28 May 2014 13:54:01 +0200 Subject: [PATCH 13/17] Inserted tests for page move. --- tests/phpunit/SubscriptionHandlerTest.php | 100 +++++++++++++++++----- 1 file changed, 79 insertions(+), 21 deletions(-) diff --git a/tests/phpunit/SubscriptionHandlerTest.php b/tests/phpunit/SubscriptionHandlerTest.php index 7376d11..ef33439 100644 --- a/tests/phpunit/SubscriptionHandlerTest.php +++ b/tests/phpunit/SubscriptionHandlerTest.php @@ -43,26 +43,54 @@ public function testHandlePushFail() { } /** - * + * @dataProvider getXMLPushRedirectDataSuccessful + * @param string $xml The XML dump to import. */ - public function testHandlePushRedirect() { - $this->addData(); - sleep( 1 ); - $xml = $this->getXMLPushRedirectData(); + public function testHandlePushRedirectSuccessful( $xml ) { + $originalPage = $this->redirectSetup( $xml ); + $redirectTitle = Title::newFromText( 'Redirect TestPage' ); + $redirectPage = WikiPage::factory( $redirectTitle ); - $file = 'data:application/xml,' . $xml; - $this->mHandler->handlePush( $file ); + $this->assertTrue( $redirectPage->exists() ); - $orginalTitle = Title::newFromText( 'TestPage' ); - $orginalPage = WikiPage::factory( $orginalTitle ); + $text = $redirectPage->getContent()->getNativeData(); + $this->assertEquals( "TestPage content", $text ); - $redirectTitle = Title::newFromText( 'Redirect TestPage' ); + $text =$originalPage->getContent()->getNativeData(); + $this->assertEquals( "#REDIRECT [[Redirect TestPage]]", $text ); + } + + /** + * @dataProvider getXMLPushRedirectDataExists + * @param string $xml The XML dump to import. + */ + public function testHandlePushRedirectExists( $xml ) { + $originalPage = $this->redirectSetup( $xml ); + $redirectTitle = Title::newFromText( 'Test Page' ); $redirectPage = WikiPage::factory( $redirectTitle ); - $this->assertTrue( $redirectPage->exists() ); + $text = $redirectPage->getContent()->getNativeData(); + $this->assertEquals( "Test Page content", $text ); - $text = $orginalPage->getContent()->getNativeData(); - $this->assertEquals( "This is a Test Page.", $text ); + $text =$originalPage->getContent()->getNativeData(); + $this->assertEquals( "TestPage content version 2", $text ); + } + + /** + * @param $xml + * @return WikiPage + */ + public function redirectSetup( $xml ) { + $this->addData(); + sleep( 1 ); + $xml = preg_replace('~.*?~', '' . wfTimestamp( TS_ISO_8601, wfTimestampNow() ) + . '', $xml ); + + $file = 'data:application/xml,' . $xml; + $this->mHandler->handlePush( $file ); + + $originalTitle = Title::newFromText( 'TestPage' ); + return WikiPage::factory( $originalTitle ); } /** @@ -169,6 +197,7 @@ public function testHandleUnsubscribeSuccessful() { public function addData() { $this->insertUser( 'TestUser' ); $this->insertWikipage( 'TestPage', 'TestPage content', 'TestPage comment' ); + $this->insertWikipage( 'Test Page', 'Test Page content', 'Test Page comment' ); } /** @@ -259,6 +288,8 @@ public function getBaseRevision() { return $revision; } + + public function getXMLPushData() { return array( array( @@ -309,10 +340,11 @@ public function getXMLPushDeletionData() { EOF ) ); -} + } - public function getXMLPushRedirectData() { - $xml = <<< EOF + public function getXMLPushRedirectDataSuccessful() { + return array( + array( <<< EOF TestPage @@ -333,11 +365,37 @@ public function getXMLPushRedirectData() { -EOF; - $xml = preg_replace('~.*?~', '' . wfTimestamp( TS_ISO_8601, wfTimestampNow() ) - . '', $xml ); - return $xml; +EOF + ) + ); + } -} + public function getXMLPushRedirectDataExists() { + return array( + array( <<< EOF + + + TestPage + 0 + 5 + + + 100 + 99 + + + 127.0.0.1 + + TestPage content version 2 + lg0sq0pjm7cngi77vxtmmeko4o7pho6 + wikitext + text/x-wiki + + + +EOF + ) + ); + } } From a15627c97cd52421ffabc4982603d8333f92ec3c Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Wed, 28 May 2014 17:34:23 +0200 Subject: [PATCH 14/17] Separating ImportCallback from Subscriptionhandler --- PubSubHubbubSubscriber.php | 1 + src/ImportCallbacks.php | 90 ++++++++ src/SubscriptionHandler.php | 58 +---- tests/phpunit/ImportCallbacksTest.php | 256 +++++++++++++++++++++ tests/phpunit/SubscriptionHandlerTest.php | 261 ---------------------- 5 files changed, 351 insertions(+), 315 deletions(-) create mode 100644 src/ImportCallbacks.php create mode 100644 tests/phpunit/ImportCallbacksTest.php diff --git a/PubSubHubbubSubscriber.php b/PubSubHubbubSubscriber.php index 37f2dbe..c0ffdb6 100644 --- a/PubSubHubbubSubscriber.php +++ b/PubSubHubbubSubscriber.php @@ -53,6 +53,7 @@ $wgAutoloadClasses['PubSubHubbubSubscriber\\Subscription'] = $dir . 'src/Subscription.php'; $wgAutoloadClasses['PubSubHubbubSubscriber\\SubscriptionHandler'] = $dir . 'src/SubscriptionHandler.php'; $wgAutoloadClasses['PubSubHubbubSubscriber\\SubscriberClient'] = $dir . 'src/SubscriberClient.php'; +$wgAutoloadClasses['PubSubHubbubSubscriber\\ImportCallbacks'] = $dir . 'src/ImportCallbacks.php'; $wgAPIModules['pushcallback'] = 'PubSubHubbubSubscriber\\ApiSubscription'; diff --git a/src/ImportCallbacks.php b/src/ImportCallbacks.php new file mode 100644 index 0000000..10334a8 --- /dev/null +++ b/src/ImportCallbacks.php @@ -0,0 +1,90 @@ +previousPageOutCallback = $previousPageOutCallback; + } + + /** + * @param WikiRevision $revision + */ + public function deletionPage( WikiRevision $revision ) { + if ( $revision->getAction() != 'delete' ){ + return; + } + $username = $revision->getUser(); + if ( !empty( $username ) ) { + $user = User::newFromName( $username ); + } + else { + $user = null; + } + $error = array(); + $title = $revision->getTitle(); + $wikipage = new WikiPage( $title ); + $wikipage->doDeleteArticle( $revision->getComment(), false, 0, true, $error, $user ); + } + + /** + * @param Title $title + * @param $origTitle + * @param $revCount + * @param $sucCount + * @param $pageInfo + */ + private function callOriginalPageOutCallback( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + if ( is_callable( $this->previousPageOutCallback) ) { + call_user_func_array( $this->previousPageOutCallback, func_get_args() ); + } + } + + /** + * @param Title $title + * @param $origTitle + * @param $revCount + * @param $sucCount + * @param $pageInfo + */ + public function createRedirect( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + if ( !array_key_exists( 'redirect', $pageInfo ) || $pageInfo['redirect'] == "" || $sucCount < 1 ) { + $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + return; + } + + $wikipage = new WikiPage( $title ); + $redirectTitle = Title::newFromText( $pageInfo['redirect'] ); + if ( $redirectTitle->exists() ){ + $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + return; + } + + $dbw = wfGetDB( DB_MASTER ); + $pageId = $wikipage->getId(); + $currentRevision = $wikipage->getRevision(); + $contentRevision = $currentRevision->getPrevious(); + $currentRevisionID = $currentRevision->getId(); + $contentRevisionID = $contentRevision->getId(); + + $dbw->delete( 'revision', array( 'rev_id' => $currentRevisionID ) ); + $dbw->update( 'page', array( 'page_latest' => $contentRevisionID ), array( 'page_id' => $pageId ) ); + $title->moveTo( $redirectTitle, false ); + + $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + } + +} \ No newline at end of file diff --git a/src/SubscriptionHandler.php b/src/SubscriptionHandler.php index 1ed6a1f..2e272ba 100644 --- a/src/SubscriptionHandler.php +++ b/src/SubscriptionHandler.php @@ -12,8 +12,6 @@ class SubscriptionHandler { - private $previousPageOutCallback; - /** * @param string $file The file to read the POST data from. Defaults to stdin. * @return bool whether the pushed data could be accepted. @@ -22,9 +20,11 @@ public function handlePush( $file = "php://input" ) { // The hub is POSTing new data. $source = ImportStreamSource::newFromFile( $file ); if ( $source->isGood() ) { + $callbacks = new ImportCallbacks(); $importer = new WikiImporter( $source->value ); - $importer->setLogItemCallback( array( &$this, 'deletionPage' ) ); - $this->previousPageOutCallback = $importer->setPageOutCallback( array( &$this, 'createRedirectPage' ) ); + $importer->setLogItemCallback( array( &$callbacks, 'deletionPage' ) ); + $callbacks->setPreviousPageOutCallback( $importer->setPageOutCallback( + array( &$callbacks, 'createRedirect' ) ) ); $importer->doImport(); return true; } else { @@ -32,56 +32,6 @@ public function handlePush( $file = "php://input" ) { } } - public function deletionPage( WikiRevision $revision ) { - if ( $revision->getAction() != 'delete' ){ - return; - } - $username = $revision->getUser(); - if ( !empty( $username ) ) { - $user = User::newFromName( $username ); - } - else { - $user = null; - } - $error = array(); - $title = $revision->getTitle(); - $wikipage = new WikiPage( $title ); - $wikipage->doDeleteArticle( $revision->getComment(), false, 0, true, $error, $user ); - } - - private function callOriginalPageOutCallback( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { - if ( is_callable( $this->previousPageOutCallback) ) { - call_user_func_array( $this->previousPageOutCallback, func_get_args() ); - } - } - - public function createRedirectPage( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { - if ( !array_key_exists( 'redirect', $pageInfo ) || $pageInfo['redirect'] == "" || $sucCount < 1 ) { - $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); - return; - } - - $wikipage = new WikiPage( $title ); - $redirectTitle = Title::newFromText( $pageInfo['redirect'] ); - if ( $redirectTitle->exists() ){ - $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); - return; - } - - $dbw = wfGetDB( DB_MASTER ); - $pageId = $wikipage->getId(); - $currentRevision = $wikipage->getRevision(); - $contentRevision = $currentRevision->getPrevious(); - $currentRevisionID = $currentRevision->getId(); - $contentRevisionID = $contentRevision->getId(); - - $dbw->delete( 'revision', array( 'rev_id' => $currentRevisionID ) ); - $dbw->update( 'page', array( 'page_latest' => $contentRevisionID ), array( 'page_id' => $pageId ) ); - $title->moveTo( $redirectTitle, false ); - - $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); - } - /** * @param string $topic * @param int $lease_seconds diff --git a/tests/phpunit/ImportCallbacksTest.php b/tests/phpunit/ImportCallbacksTest.php new file mode 100644 index 0000000..a593927 --- /dev/null +++ b/tests/phpunit/ImportCallbacksTest.php @@ -0,0 +1,256 @@ + + */ +class ImportCallbacksTest extends MediaWikiLangTestCase { + /** + * @var ImportCallbacks $mImportCallbacks; + */ + private $mImportCallbacks; + + protected function setUp() { + parent::setUp(); + $this->mImportCallbacks = new ImportCallbacks(); + $this->addDBData(); + } + + protected function tearDown() { + parent::tearDown(); + } + + /** + * @dataProvider getDeletionRevision + */ + public function testDeletionPage( WikiRevision $revision ) { + $wikiPage = new WikiPage( $revision->getTitle() ); + $this->mImportCallbacks->deletionPage( $revision ); + $this->assertFalse( $wikiPage->exists() ); + } + + /** + * @dataProvider getNoDeletionRevision + */ + public function testDeletionPageNoDelete( WikiRevision $revision ) { + $wikiPage = new WikiPage( $revision->getTitle() ); + $this->mImportCallbacks->deletionPage( $revision ); + $this->assertTrue( $wikiPage->exists() ); + } + + /** + * @dataProvider getNoRedirectData + * + * @param Title $title + * @param $origTitle + * @param $revCount + * @param $sucCount + * @param $pageInfo + */ + public function testCreateRedirectNoRedirect( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + $this->mImportCallbacks->createRedirect( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + + $originalTitle = Title::newFromText( 'TestPage' ); + $originalPage = WikiPage::factory( $originalTitle ); + $redirectTitle = Title::newFromText( 'Redirect TestPage' ); + $redirectPage = WikiPage::factory( $redirectTitle ); + + $this->assertFalse( $redirectPage->exists() ); + + $text = $originalPage->getContent()->getNativeData(); + $this->assertEquals( "TestPage content", $text ); + } + + /** + * @dataProvider getRedirectExistsData + * + * @param Title $title + * @param $origTitle + * @param $revCount + * @param $sucCount + * @param $pageInfo + */ + public function testCreateRedirectExists( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + $this->insertWikipage( 'Existing Page', 'Existing Page content', 'Existing Page comment' ); + $this->mImportCallbacks->createRedirect( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + + $originalTitle = Title::newFromText( 'TestPage' ); + $originalPage = WikiPage::factory( $originalTitle ); + $redirectTitle = Title::newFromText( 'Existing Page' ); + $redirectPage = WikiPage::factory( $redirectTitle ); + + $text = $redirectPage->getContent()->getNativeData(); + $this->assertEquals( "Existing Page content", $text ); + + $text =$originalPage->getContent()->getNativeData(); + $this->assertEquals( "TestPage content", $text ); + } + + /** + * @dataProvider getRedirectSuccessful + * + * @param Title $title + * @param $origTitle + * @param $revCount + * @param $sucCount + * @param $pageInfo + */ + public function testCreateRedirectSuccessful( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + $originalTitle = Title::newFromText( 'TestPage' ); + $originalPage = WikiPage::factory( $originalTitle ); + $content = new WikitextContent( '#REDIRECT [[Redirect TestPage]]' ); + $originalPage->doEditContent( $content, '' ); + + $this->mImportCallbacks->createRedirect( $title, $origTitle, $revCount, $sucCount, $pageInfo ); + + $redirectTitle = Title::newFromText( 'Redirect TestPage' ); + $redirectPage = WikiPage::factory( $redirectTitle ); + + $this->assertTrue( $redirectPage->exists() ); + + $text = $redirectPage->getContent()->getNativeData(); + $this->assertEquals( "TestPage content", $text ); + + $text =$originalPage->getContent()->getNativeData(); + $this->assertEquals( "#REDIRECT [[Redirect TestPage]]", $text ); + } + + public function addDBData() { + $this->insertUser( 'TestUser' ); + $this->insertWikipage( 'TestPage', 'TestPage content', 'TestPage comment' ); + } + + /** + * @param string $userName + */ + private function insertUser( $userName ) { + $user = User::newFromName( $userName ); + $user->addToDatabase(); + } + + /** + * @param string $titleName + * @param string $contentText + * @param string $comment + */ + private function insertWikipage( $titleName, $contentText, $comment ) { + $page = WikiPage::factory( Title::newFromText( $titleName ) ); + + if ( !$page->exists() ) { + $pageId = $page->insertOn( $this->db ); + } else { + $pageId = $page->getId(); + } + + $user = User::newFromName( 'TestUser' ); + $revision = new Revision( array( + 'title' => $page->getTitle(), + 'page' => $pageId, + 'content_model' => $page->getTitle()->getContentModel(), + 'content_format' => $this->getFormat( $page->getTitle() ), + 'text' => $contentText, + 'comment' => $comment, + 'user' => $user->getId(), + 'user_text' => $user->getName(), + 'timestamp' => wfTimestamp( TS_ISO_8601 ), + 'minor_edit' => false, + ) ); + $revision->insertOn( $this->db ); + $changed = $page->updateIfNewerOn( $this->db, $revision ); + + if ( $changed !== false ) { + $page->doEditUpdates( $revision, $user ); + } + } + + /** + * @param Title $title + * @return string + */ + private function getFormat( Title $title ) { + return ContentHandler::getForTitle( $title )->getDefaultFormat(); + } + + public function getDeletionRevision() { + $data = array(); + + $revision = $this->getBaseRevision(); + $revision->setType( 'delete' ); + $revision->setAction( 'delete' ); + $revision->setUserName( 'TestUser' ); + array_push( $data, array( $revision ) ); + + $revision = $this->getBaseRevision(); + $revision->setType( 'delete' ); + $revision->setAction( 'delete' ); + array_push( $data, array( $revision ) ); + + return $data; + } + + public function getNoDeletionRevision() { + $revision = $this->getBaseRevision(); + $revision->setType( 'move' ); + $revision->setAction( 'move' ); + $revision->setUserName( 'TestUser' ); + return array( array( $revision ) ); + } + + private function getBaseRevision() { + $revision = new WikiRevision; + + $revision->setID( 1 ); + $revision->setTimestamp( wfTimestampNow() ); + $revision->setParams( 'a:0:{}' ); + $revision->setTitle( Title::newFromText( 'TestPage' ) ); + $revision->setNoUpdates( true ); + + return $revision; + } + + public function getNoRedirectData() { + $title = Title::newFromText( 'TestPage' ); + $origTitle = $title; + $revCount = 1; + return array( + array( $title, $origTitle, $revCount, 1, array() ), + array( $title, $origTitle, $revCount, 1, array( 'redirect' => "" ) ), + array( $title, $origTitle, $revCount, 0, array( 'redirect' => "Redirect TestPage" ) ) + ); + } + + public function getRedirectExistsData() { + $title = Title::newFromText( 'TestPage' ); + $origTitle = $title; + return array( + array( $title, $origTitle, 1, 1, array( 'redirect' => "Existing Page" ) ) + ); + } + + public function getRedirectSuccessful() { + $title = Title::newFromText( 'TestPage' ); + $origTitle = $title; + return array( + array( $title, $origTitle, 1, 1, array( 'redirect' => "Redirect TestPage" ) ) + ); + } +} + \ No newline at end of file diff --git a/tests/phpunit/SubscriptionHandlerTest.php b/tests/phpunit/SubscriptionHandlerTest.php index ef33439..66bb1f3 100644 --- a/tests/phpunit/SubscriptionHandlerTest.php +++ b/tests/phpunit/SubscriptionHandlerTest.php @@ -42,57 +42,6 @@ public function testHandlePushFail() { $this->assertFalse( $success ); } - /** - * @dataProvider getXMLPushRedirectDataSuccessful - * @param string $xml The XML dump to import. - */ - public function testHandlePushRedirectSuccessful( $xml ) { - $originalPage = $this->redirectSetup( $xml ); - $redirectTitle = Title::newFromText( 'Redirect TestPage' ); - $redirectPage = WikiPage::factory( $redirectTitle ); - - $this->assertTrue( $redirectPage->exists() ); - - $text = $redirectPage->getContent()->getNativeData(); - $this->assertEquals( "TestPage content", $text ); - - $text =$originalPage->getContent()->getNativeData(); - $this->assertEquals( "#REDIRECT [[Redirect TestPage]]", $text ); - } - - /** - * @dataProvider getXMLPushRedirectDataExists - * @param string $xml The XML dump to import. - */ - public function testHandlePushRedirectExists( $xml ) { - $originalPage = $this->redirectSetup( $xml ); - $redirectTitle = Title::newFromText( 'Test Page' ); - $redirectPage = WikiPage::factory( $redirectTitle ); - - $text = $redirectPage->getContent()->getNativeData(); - $this->assertEquals( "Test Page content", $text ); - - $text =$originalPage->getContent()->getNativeData(); - $this->assertEquals( "TestPage content version 2", $text ); - } - - /** - * @param $xml - * @return WikiPage - */ - public function redirectSetup( $xml ) { - $this->addData(); - sleep( 1 ); - $xml = preg_replace('~.*?~', '' . wfTimestamp( TS_ISO_8601, wfTimestampNow() ) - . '', $xml ); - - $file = 'data:application/xml,' . $xml; - $this->mHandler->handlePush( $file ); - - $originalTitle = Title::newFromText( 'TestPage' ); - return WikiPage::factory( $originalTitle ); - } - /** * @dataProvider getXMLPushData * @param string $xml The XML dump to import. @@ -109,40 +58,6 @@ public function testHandlePushSuccessful( $xml ) { $this->assertEquals( "This is a Test Page.", $text ); } - /** - * @dataProvider getDeletionRevision - */ - public function testDeletionPage( WikiRevision $revision ) { - $this->addData(); - $wikiPage = new WikiPage( $revision->getTitle() ); - $this->mHandler->deletionPage( $revision ); - $this->assertFalse( $wikiPage->exists() ); - } - - /** - * @dataProvider getNoDeletionRevision - */ - public function testDeletionPageNoDelete( WikiRevision $revision ) { - $this->addData(); - $wikiPage = new WikiPage( $revision->getTitle() ); - $this->mHandler->deletionPage( $revision ); - $this->assertTrue( $wikiPage->exists() ); - } - - /** - * @dataProvider getXMLPushDeletionData - * @param string $xml The XML dump to import. - */ - public function testHandlePushDeletion( $xml ) { - $this->addData(); - $file = 'data:application/xml,' . $xml; - $this->mHandler->handlePush( $file ); - - $title = Title::newFromText( 'TestPage' ); - $wikiPage = new WikiPage( $title ); - $this->assertfalse( $wikiPage->exists() ); - } - public function testHandleSubscribeNonExistent() { $success = $this->mHandler->handleSubscribe( "http://some.nonexistent.topic/", 1337 ); $this->assertFalse( $success ); @@ -194,102 +109,6 @@ public function testHandleUnsubscribeSuccessful() { $this->assertNull( $subscription ); } - public function addData() { - $this->insertUser( 'TestUser' ); - $this->insertWikipage( 'TestPage', 'TestPage content', 'TestPage comment' ); - $this->insertWikipage( 'Test Page', 'Test Page content', 'Test Page comment' ); - } - - /** - * @param string $userName - */ - public function insertUser( $userName ) { - $user = User::newFromName( $userName ); - $user->addToDatabase(); - } - - /** - * @param string $titleName - * @param string $contentText - * @param string $comment - */ - public function insertWikipage( $titleName, $contentText, $comment ) { - $page = WikiPage::factory( Title::newFromText( $titleName ) ); - - if ( !$page->exists() ) { - $pageId = $page->insertOn( $this->db ); - } else { - $pageId = $page->getId(); - } - - $user = User::newFromName( 'TestUser' ); - $revision = new Revision( array( - 'title' => $page->getTitle(), - 'page' => $pageId, - 'content_model' => $page->getTitle()->getContentModel(), - 'content_format' => $this->getFormat( $page->getTitle() ), - 'text' => $contentText, - 'comment' => $comment, - 'user' => $user->getId(), - 'user_text' => $user->getName(), - 'timestamp' => wfTimestamp( TS_ISO_8601 ), - 'minor_edit' => false, - ) ); - $revision->insertOn( $this->db ); - $changed = $page->updateIfNewerOn( $this->db, $revision ); - - if ( $changed !== false ) { - $page->doEditUpdates( $revision, $user ); - } - } - - /** - * @param Title $title - * @return string - */ - private function getFormat( Title $title ) { - return ContentHandler::getForTitle( $title )->getDefaultFormat(); - } - - public function getDeletionRevision() { - $data = array(); - - $revision = $this->getBaseRevision(); - $revision->setType( 'delete' ); - $revision->setAction( 'delete' ); - $revision->setUserName( 'TestUser' ); - array_push( $data, array( $revision ) ); - - $revision = $this->getBaseRevision(); - $revision->setType( 'delete' ); - $revision->setAction( 'delete' ); - array_push( $data, array( $revision ) ); - - return $data; - } - - public function getNoDeletionRevision() { - $revision = $this->getBaseRevision(); - $revision->setType( 'move' ); - $revision->setAction( 'move' ); - $revision->setUserName( 'TestUser' ); - return array( array( $revision ) ); - } - - public function getBaseRevision() { - $revision = new WikiRevision; - - $revision->setID( 1 ); - $revision->setTimestamp( wfTimestampNow() ); - $revision->setParams( 'a:0:{}' ); - $revision->setTitle( Title::newFromText( 'TestPage' ) ); - $revision->setNoUpdates( true ); - - return $revision; - } - - - public function getXMLPushData() { return array( array( @@ -313,86 +132,6 @@ public function getXMLPushData() { -EOF - ) - ); - } - - public function getXMLPushDeletionData() { - return array( - array( - <<< EOF - - - 70 - 2014-05-20T09:49:33Z - - TestUser - 1 - - content was: "test" (and the only contributor was "[[Special:Contributions/Root|Root]]") - delete - delete - TestPage - a:0:{} - - -EOF - ) - ); - } - - public function getXMLPushRedirectDataSuccessful() { - return array( - array( <<< EOF - - - TestPage - 0 - 5 - - - 100 - 99 - - - 127.0.0.1 - - #REDIRECT [[TestPage]] - lg0sq0pjm7cngi77vxtmmeko4o7pho6 - wikitext - text/x-wiki - - - -EOF - ) - ); - } - - public function getXMLPushRedirectDataExists() { - return array( - array( <<< EOF - - - TestPage - 0 - 5 - - - 100 - 99 - - - 127.0.0.1 - - TestPage content version 2 - lg0sq0pjm7cngi77vxtmmeko4o7pho6 - wikitext - text/x-wiki - - - EOF ) ); From f09351d0e1017db3173708fac4eee6e844f69545 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Mon, 2 Jun 2014 15:22:00 +0200 Subject: [PATCH 15/17] Fix function declaration of setPreviousPageOutCallback. --- src/ImportCallbacks.php | 2 +- src/SubscriptionHandler.php | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/ImportCallbacks.php b/src/ImportCallbacks.php index 10334a8..8ff20af 100644 --- a/src/ImportCallbacks.php +++ b/src/ImportCallbacks.php @@ -16,7 +16,7 @@ class ImportCallbacks { * @codeCoverageIgnore * @param callable $previousPageOutCallback */ - public function setPreviousPageOutCallback( callable $previousPageOutCallback ) { + public function setPreviousPageOutCallback( $previousPageOutCallback ) { $this->previousPageOutCallback = $previousPageOutCallback; } diff --git a/src/SubscriptionHandler.php b/src/SubscriptionHandler.php index 2e272ba..71512b7 100644 --- a/src/SubscriptionHandler.php +++ b/src/SubscriptionHandler.php @@ -3,12 +3,8 @@ namespace PubSubHubbubSubscriber; use ImportStreamSource; -use Title; -use User; use MWTimestamp; use WikiImporter; -use WikiPage; -use WikiRevision; class SubscriptionHandler { From 9129945fe9ab35d3bfbfbb83e52de54ce34212e4 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Tue, 3 Jun 2014 13:10:11 +0200 Subject: [PATCH 16/17] Fix @covers class. --- tests/phpunit/ImportCallbacksTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/ImportCallbacksTest.php b/tests/phpunit/ImportCallbacksTest.php index a593927..0068da3 100644 --- a/tests/phpunit/ImportCallbacksTest.php +++ b/tests/phpunit/ImportCallbacksTest.php @@ -14,7 +14,7 @@ use WikitextContent; /** - * @covers PubSubHubbub\ImportCallbacks + * @covers PubSubHubbubSubscriber\ImportCallbacks * * @group Database * @group PubSubHubbubSubscriber From 2df135846e16d55e7b348989ddcbd58d5c28c627 Mon Sep 17 00:00:00 2001 From: Alexander Lehmann Date: Tue, 3 Jun 2014 14:36:37 +0200 Subject: [PATCH 17/17] Inserted CallOriginalPageOutCallback tests. --- src/ImportCallbacks.php | 7 +++--- tests/phpunit/ImportCallbacksTest.php | 36 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/ImportCallbacks.php b/src/ImportCallbacks.php index 8ff20af..2fba721 100644 --- a/src/ImportCallbacks.php +++ b/src/ImportCallbacks.php @@ -46,11 +46,13 @@ public function deletionPage( WikiRevision $revision ) { * @param $revCount * @param $sucCount * @param $pageInfo + * @return bool */ - private function callOriginalPageOutCallback( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + function callOriginalPageOutCallback( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { if ( is_callable( $this->previousPageOutCallback) ) { call_user_func_array( $this->previousPageOutCallback, func_get_args() ); } + return true; } /** @@ -86,5 +88,4 @@ public function createRedirect( Title $title, $origTitle, $revCount, $sucCount, $this->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ); } - -} \ No newline at end of file +} diff --git a/tests/phpunit/ImportCallbacksTest.php b/tests/phpunit/ImportCallbacksTest.php index 0068da3..90cb846 100644 --- a/tests/phpunit/ImportCallbacksTest.php +++ b/tests/phpunit/ImportCallbacksTest.php @@ -133,6 +133,42 @@ public function testCreateRedirectSuccessful( Title $title, $origTitle, $revCou $this->assertEquals( "#REDIRECT [[Redirect TestPage]]", $text ); } + /** + * @dataProvider getRedirectSuccessful + * + * @param Title $title + * @param $origTitle + * @param $revCount + * @param $sucCount + * @param $pageInfo + */ + public function testCallOriginalPageOutCallbackNull( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + $success = $this->mImportCallbacks->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, + $pageInfo ); + $this->assertTrue( $success ); + } + + /** + * @dataProvider getRedirectSuccessful + * + * @param Title $title + * @param $origTitle + * @param $revCount + * @param $sucCount + * @param $pageInfo + */ + public function testCallOriginalPageOutCallback( Title $title, $origTitle, $revCount, $sucCount, $pageInfo ) { + $mock = $this->getMock( 'OriginalCallbackClass', array( 'callback' ) ); + $mock->expects( $this->once() ) + ->method( 'callback' ); + $previousPageOutCallback = array( &$mock, 'callback' ); + $this->mImportCallbacks->setPreviousPageOutCallback( $previousPageOutCallback ); + $success = $this->mImportCallbacks->callOriginalPageOutCallback( $title, $origTitle, $revCount, $sucCount, + $pageInfo ); + $this->assertTrue( $success ); + + } + public function addDBData() { $this->insertUser( 'TestUser' ); $this->insertWikipage( 'TestPage', 'TestPage content', 'TestPage comment' );