Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/311692
Change subject: Add hook for restoring a page & tests
......................................................................
Add hook for restoring a page & tests
Change-Id: I891df2f2ecbf25d9313015a0f293c2b1dff958dd
---
M extension.json
M src/CognateHooks.php
M src/hooks/CognatePageHookHandler.php
M tests/phpunit/hooks/CognatePageHookHandlerTest.php
4 files changed, 82 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cognate
refs/changes/92/311692/1
diff --git a/extension.json b/extension.json
index 364d02f..f544dfb 100644
--- a/extension.json
+++ b/extension.json
@@ -25,6 +25,7 @@
"PageContentSaveComplete": [ "CognateHooks::onPageContentSaveComplete" ],
"LanguageLinks": [ "CognateHooks::onLanguageLinks" ],
"WikiPageDeletionUpdates": [ "CognateHooks::onWikiPageDeletionUpdates" ],
+ "ArticleUndelete": [ "CognateHooks::onArticleUndelete" ],
"LoadExtensionSchemaUpdates": [
"CognateHooks::onLoadExtensionSchemaUpdates" ],
"UnitTestsList": [ "CognateHooks::onUnitTestsList" ]
},
diff --git a/src/CognateHooks.php b/src/CognateHooks.php
index 56dfb9e..1bd91ce 100644
--- a/src/CognateHooks.php
+++ b/src/CognateHooks.php
@@ -26,6 +26,17 @@
return true;
}
+ public static function onArticleUndelete() {
+ call_user_func_array(
+ [
+ MediaWikiServices::getInstance()->getService(
'CognatePageHookHandler' ),
+ 'onArticleUndelete'
+ ],
+ func_get_args()
+ );
+ return true;
+ }
+
/**
* @param Title $title
* @param array $links
diff --git a/src/hooks/CognatePageHookHandler.php
b/src/hooks/CognatePageHookHandler.php
index 50a0ddc..da5a4e8 100644
--- a/src/hooks/CognatePageHookHandler.php
+++ b/src/hooks/CognatePageHookHandler.php
@@ -98,4 +98,28 @@
return true;
}
+ /**
+ * When one or more revisions of an article are restored
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleUndelete
+ *
+ * @param Title $title
+ * @param bool $create
+ * @param string $comment
+ * @param int $oldPageId
+ *
+ * @return bool
+ */
+ public function onArticleUndelete(
+ Title $title,
+ $create,
+ $comment,
+ $oldPageId
+ ) {
+ if ( $title->inNamespaces( $this->namespaces ) ) {
+ $store = MediaWikiServices::getInstance()->getService(
'CognateStore' );
+ $store->savePage( $this->languageCode,
$title->getDBkey() );
+ }
+ return true;
+ }
+
}
\ No newline at end of file
diff --git a/tests/phpunit/hooks/CognatePageHookHandlerTest.php
b/tests/phpunit/hooks/CognatePageHookHandlerTest.php
index e6f898d..04550cc 100644
--- a/tests/phpunit/hooks/CognatePageHookHandlerTest.php
+++ b/tests/phpunit/hooks/CognatePageHookHandlerTest.php
@@ -141,4 +141,50 @@
return $updates;
}
+ public function test_onArticleUndelete_namespaceMatch() {
+ $this->store->expects( $this->never() )
+ ->method( 'deletePage' );
+ $this->store->expects( $this->once() )
+ ->method( 'savePage' )
+ ->with( 'abc2', 'ArticleDbKey' );
+
+ $this->call_onArticleUndelete(
+ [ 0 ],
+ 'abc2',
+ new TitleValue( 0, 'ArticleDbKey' )
+ );
+ }
+
+ public function test_onArticleUndelete_noNamespaceMatch() {
+ $this->store->expects( $this->never() )
+ ->method( 'deletePage' );
+ $this->store->expects( $this->never() )
+ ->method( 'savePage' );
+
+ $this->call_onArticleUndelete(
+ [ 120 ],
+ 'abc2',
+ new TitleValue( 0, 'ArticleDbKey' )
+ );
+ }
+
+ /**
+ * @param int[] $namespaces
+ * @param string $language
+ * @param LinkTarget $linkTarget
+ *
+ * @return DeferrableUpdate[]
+ */
+ private function call_onArticleUndelete(
+ array $namespaces,
+ $language,
+ LinkTarget $linkTarget
+ ) {
+ $handler = new CognatePageHookHandler( $namespaces, $language );
+ $handler->onArticleUndelete(
+ Title::newFromLinkTarget( $linkTarget ),
+ null, null, null
+ );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/311692
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I891df2f2ecbf25d9313015a0f293c2b1dff958dd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cognate
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits