Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/173668

Change subject: Move UpdateRepo hook handlers into a dedicated class
......................................................................

Move UpdateRepo hook handlers into a dedicated class

Change-Id: I60ab88d3d43d9981ee71412a569bb21bfc2bbd30
---
M client/WikibaseClient.hooks.php
M client/WikibaseClient.php
2 files changed, 2 insertions(+), 168 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/68/173668/1

diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index aa63bc9..1cb216a 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -7,10 +7,8 @@
 use ChangesList;
 use FormOptions;
 use IContextSource;
-use JobQueueGroup;
 use Message;
 use MovePageForm;
-use MWException;
 use OutputPage;
 use Parser;
 use QuickTemplate;
@@ -25,9 +23,6 @@
 use UnexpectedValueException;
 use User;
 use Wikibase\Client\Changes\ChangeHandler;
-use WikiPage;
-use Content;
-use ManualLogEntry;
 use Wikibase\Client\Hooks\BaseTemplateAfterPortletHandler;
 use Wikibase\Client\Hooks\BeforePageDisplayHandler;
 use Wikibase\Client\Hooks\ChangesPageWikibaseFilterHandler;
@@ -39,8 +34,6 @@
 use Wikibase\Client\RecentChanges\ExternalChangeFactory;
 use Wikibase\Client\RecentChanges\RecentChangesFilterOptions;
 use Wikibase\Client\RepoItemLinkGenerator;
-use Wikibase\Client\UpdateRepo\UpdateRepoOnMove;
-use Wikibase\Client\UpdateRepo\UpdateRepoOnDelete;
 use Wikibase\Client\WikibaseClient;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\SiteLink;
@@ -689,165 +682,6 @@
 
                $pageInfo = $infoActionHookHandler->handle( $context, $pageInfo 
);
 
-               return true;
-       }
-
-       /**
-        * After a page has been moved also update the item on the repo
-        * This only works with CentralAuth
-        *
-        * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete
-        *
-        * @param Title $oldTitle
-        * @param Title $newTitle
-        * @param User $user
-        * @param integer $pageId database ID of the page that's been moved
-        * @param integer $redirectId database ID of the created redirect
-        * @param string $reason
-        *
-        * @return bool
-        */
-       public static function onTitleMoveComplete(
-               Title $oldTitle,
-               Title $newTitle,
-               User $user,
-               $pageId,
-               $redirectId,
-               $reason
-       ) {
-
-               if ( !self::isWikibaseEnabled( $oldTitle->getNamespace() )
-                       && !self::isWikibaseEnabled( $newTitle->getNamespace() 
) ) {
-                       // shorten out
-                       return true;
-               }
-
-               wfProfileIn( __METHOD__ );
-
-               $wikibaseClient = WikibaseClient::getDefaultInstance();
-               $settings = $wikibaseClient->getSettings();
-
-               if ( $settings->getSetting( 'propagateChangesToRepo' ) !== true 
) {
-                       wfProfileOut( __METHOD__ );
-                       return true;
-               }
-
-               $repoDB = $settings->getSetting( 'repoDatabase' );
-               $siteLinkLookup = 
$wikibaseClient->getStore()->getSiteLinkTable();
-               $jobQueueGroup = JobQueueGroup::singleton( $repoDB );
-
-               if ( !$jobQueueGroup ) {
-                       wfLogWarning( "Failed to acquire a JobQueueGroup for 
$repoDB" );
-                       wfProfileOut( __METHOD__ );
-                       return true;
-               }
-
-               $updateRepo = new UpdateRepoOnMove(
-                       $repoDB,
-                       $siteLinkLookup,
-                       $user,
-                       $settings->getSetting( 'siteGlobalID' ),
-                       $oldTitle,
-                       $newTitle
-               );
-
-               if ( !$updateRepo || !$updateRepo->getEntityId() || 
!$updateRepo->userIsValidOnRepo() ) {
-                       wfProfileOut( __METHOD__ );
-                       return true;
-               }
-
-               try {
-                       $updateRepo->injectJob( $jobQueueGroup );
-
-                       // To be able to find out about this in the 
SpecialMovepageAfterMove hook
-                       $newTitle->wikibasePushedMoveToRepo = true;
-               } catch( MWException $e ) {
-                       // This is not a reason to let an exception bubble up, 
we just
-                       // show a message to the user that the Wikibase item 
needs to be
-                       // manually updated.
-                       wfLogWarning( $e->getMessage() );
-               }
-
-               wfProfileOut( __METHOD__ );
-               return true;
-       }
-
-       /**
-        * After a page has been deleted also update the item on the repo
-        * This only works with CentralAuth
-        *
-        * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDeleteComplete
-        *
-        * @param WikiPage $article
-        * @param User $user
-        * @param string $reason
-        * @param int $id id of the article that was deleted
-        * @param Content $content
-        * @param ManualLogEntry $logEntry
-        *
-        * @return bool
-        */
-       public static function onArticleDeleteComplete(
-               WikiPage &$article,
-               User &$user,
-               $reason,
-               $id,
-               Content $content,
-               ManualLogEntry $logEntry
-       ) {
-               $title = $article->getTitle();
-
-               if ( !self::isWikibaseEnabled( $title->getNamespace() ) ) {
-                       // shorten out
-                       return true;
-               }
-
-               wfProfileIn( __METHOD__ );
-
-               $wikibaseClient = WikibaseClient::getDefaultInstance();
-               $settings = $wikibaseClient->getSettings();
-
-               if ( $settings->getSetting( 'propagateChangesToRepo' ) !== true 
) {
-                       wfProfileOut( __METHOD__ );
-                       return true;
-               }
-
-               $repoDB = $settings->getSetting( 'repoDatabase' );
-               $siteLinkLookup = 
$wikibaseClient->getStore()->getSiteLinkTable();
-               $jobQueueGroup = JobQueueGroup::singleton( $repoDB );
-
-               if ( !$jobQueueGroup ) {
-                       wfLogWarning( "Failed to acquire a JobQueueGroup for 
$repoDB" );
-                       wfProfileOut( __METHOD__ );
-                       return true;
-               }
-
-               $updateRepo = new UpdateRepoOnDelete(
-                       $repoDB,
-                       $siteLinkLookup,
-                       $user,
-                       $settings->getSetting( 'siteGlobalID' ),
-                       $title
-               );
-
-               if ( !$updateRepo || !$updateRepo->getEntityId() || 
!$updateRepo->userIsValidOnRepo() ) {
-                       wfProfileOut( __METHOD__ );
-                       return true;
-               }
-
-               try {
-                       $updateRepo->injectJob( $jobQueueGroup );
-
-                       // To be able to find out about this in the 
ArticleDeleteAfter hook
-                       $title->wikibasePushedDeleteToRepo = true;
-               } catch( MWException $e ) {
-                       // This is not a reason to let an exception bubble up, 
we just
-                       // show a message to the user that the Wikibase item 
needs to be
-                       // manually updated.
-                       wfLogWarning( $e->getMessage() );
-               }
-
-               wfProfileOut( __METHOD__ );
                return true;
        }
 
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index cf69a45..bf5e88f 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -109,10 +109,10 @@
        $wgHooks['ScribuntoExternalLibraries'][]      = 
'\Wikibase\ClientHooks::onScribuntoExternalLibraries';
        $wgHooks['SpecialWatchlistFilters'][]          = 
'\Wikibase\ClientHooks::onSpecialWatchlistFilters';
        $wgHooks['InfoAction'][]                                                
                = '\Wikibase\ClientHooks::onInfoAction';
-       $wgHooks['TitleMoveComplete'][]          = 
'\Wikibase\ClientHooks::onTitleMoveComplete';
+       $wgHooks['TitleMoveComplete'][]          = 
'\Wikibase\Client\Hooks\UpdateRepoHookHandlers::onTitleMoveComplete';
        $wgHooks['BaseTemplateAfterPortlet'][] = 
'\Wikibase\ClientHooks::onBaseTemplateAfterPortlet';
        $wgHooks['GetBetaFeaturePreferences'][] = 
'\Wikibase\ClientHooks::onGetBetaFeaturePreferences';
-       $wgHooks['ArticleDeleteComplete'][] = 
'\Wikibase\ClientHooks::onArticleDeleteComplete';
+       $wgHooks['ArticleDeleteComplete'][] = 
'\Wikibase\Client\Hooks\UpdateRepoHookHandlers::onArticleDeleteComplete';
        $wgHooks['ArticleDeleteAfterSuccess'][] = 
'\Wikibase\ClientHooks::onArticleDeleteAfterSuccess';
 
        // update hooks

-- 
To view, visit https://gerrit.wikimedia.org/r/173668
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I60ab88d3d43d9981ee71412a569bb21bfc2bbd30
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to