1 | <?php |
||
33 | class UpdateRepoHookHandler implements PageMoveCompleteHook, ArticleDeleteCompleteHook { |
||
34 | |||
35 | /** |
||
36 | * @var NamespaceChecker |
||
37 | */ |
||
38 | private $namespaceChecker; |
||
39 | |||
40 | /** |
||
41 | * @var JobQueueGroup |
||
42 | */ |
||
43 | private $jobQueueGroup; |
||
44 | |||
45 | /** |
||
46 | * @var SiteLinkLookup |
||
47 | */ |
||
48 | private $siteLinkLookup; |
||
49 | |||
50 | /** |
||
51 | * @var LoggerInterface |
||
52 | */ |
||
53 | private $logger; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | private $repoDatabase; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | private $siteGlobalID; |
||
64 | |||
65 | /** |
||
66 | * @var bool |
||
67 | */ |
||
68 | private $propagateChangesToRepo; |
||
69 | |||
70 | /** |
||
71 | * @return self|null |
||
72 | */ |
||
73 | public static function factory() { |
||
74 | $wikibaseClient = WikibaseClient::getDefaultInstance(); |
||
75 | $settings = $wikibaseClient->getSettings(); |
||
76 | |||
77 | $namespaceChecker = $wikibaseClient->getNamespaceChecker(); |
||
78 | |||
79 | $repoDB = $wikibaseClient->getDatabaseDomainNameOfLocalRepo(); |
||
80 | $jobQueueGroup = JobQueueGroup::singleton( $repoDB ); |
||
81 | |||
82 | if ( !$jobQueueGroup ) { |
||
83 | wfLogWarning( "Failed to acquire a JobQueueGroup for $repoDB" ); |
||
84 | return null; |
||
85 | } |
||
86 | |||
87 | $siteLinkLookup = $wikibaseClient->getStore()->getSiteLinkLookup(); |
||
88 | |||
89 | return new self( |
||
90 | $namespaceChecker, |
||
91 | $jobQueueGroup, |
||
92 | $siteLinkLookup, |
||
93 | LoggerFactory::getInstance( 'UpdateRepo' ), |
||
94 | $repoDB, |
||
95 | $settings->getSetting( 'siteGlobalID' ), |
||
96 | $settings->getSetting( 'propagateChangesToRepo' ) |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param NamespaceChecker $namespaceChecker |
||
102 | * @param JobQueueGroup $jobQueueGroup |
||
103 | * @param SiteLinkLookup $siteLinkLookup |
||
104 | * @param LoggerInterface $logger |
||
105 | * @param string $repoDatabase |
||
106 | * @param string $siteGlobalID |
||
107 | * @param bool $propagateChangesToRepo |
||
108 | */ |
||
109 | public function __construct( |
||
127 | |||
128 | /** |
||
129 | * @see NamespaceChecker::isWikibaseEnabled |
||
130 | * |
||
131 | * @param int $namespace |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | private function isWikibaseEnabled( $namespace ) { |
||
138 | |||
139 | /** |
||
140 | * After a page has been deleted also update the item on the repo. |
||
141 | * This only works if there's a user account with the same name on the repo. |
||
142 | * |
||
143 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDeleteComplete |
||
144 | * |
||
145 | * @param WikiPage $wikiPage WikiPage that was deleted |
||
146 | * @param User $user User that deleted the article |
||
147 | * @param string $reason Reason the article was deleted |
||
148 | * @param int $id ID of the article that was deleted |
||
149 | * @param Content|null $content Content of the deleted page (or null, when deleting a broken page) |
||
150 | * @param \ManualLogEntry $logEntry ManualLogEntry used to record the deletion |
||
151 | * @param int $archivedRevisionCount Number of revisions archived during the deletion |
||
152 | * @return bool|void True or no return value to continue or false to abort |
||
153 | */ |
||
154 | public function onArticleDeleteComplete( |
||
204 | |||
205 | /** |
||
206 | * After a page has been moved also update the item on the repo. |
||
207 | * This only works if there's a user account with the same name on the repo. |
||
208 | * |
||
209 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/PageMoveComplete |
||
210 | * |
||
211 | * @param LinkTarget $oldLinkTarget |
||
212 | * @param LinkTarget $newLinkTarget |
||
213 | * @param UserIdentity $userIdentity |
||
214 | * @param int $pageId database ID of the page that's been moved |
||
215 | * @param int $redirid ID of the created redirect |
||
216 | * @param string $reason |
||
217 | * @param RevisionRecord $revisionRecord revision created by the move |
||
218 | * |
||
219 | * @return bool |
||
220 | */ |
||
221 | public function onPageMoveComplete( |
||
279 | |||
280 | } |
||
281 |