Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
83.33% |
10 / 12 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
CognateHooks | |
83.33% |
10 / 12 |
|
80.00% |
4 / 5 |
6.17 | |
0.00% |
0 / 1 |
onPageSaveComplete | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
onWikiPageDeletionUpdates | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
onArticleUndelete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
onPageMoveComplete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
onContentAlterParserOutput | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
2.50 |
1 | <?php |
2 | |
3 | namespace Cognate; |
4 | |
5 | use Cognate\HookHandler\CognateParseHookHandler; |
6 | use MediaWiki\Content\Content; |
7 | use MediaWiki\Content\Hook\ContentAlterParserOutputHook; |
8 | use MediaWiki\Deferred\DeferrableUpdate; |
9 | use MediaWiki\Hook\PageMoveCompleteHook; |
10 | use MediaWiki\Linker\LinkTarget; |
11 | use MediaWiki\Page\Hook\ArticleUndeleteHook; |
12 | use MediaWiki\Page\Hook\WikiPageDeletionUpdatesHook; |
13 | use MediaWiki\Parser\ParserOutput; |
14 | use MediaWiki\Revision\RevisionRecord; |
15 | use MediaWiki\Storage\EditResult; |
16 | use MediaWiki\Storage\Hook\PageSaveCompleteHook; |
17 | use MediaWiki\Title\Title; |
18 | use MediaWiki\User\UserIdentity; |
19 | use WikiPage; |
20 | |
21 | /** |
22 | * @license GPL-2.0-or-later |
23 | * @author Gabriel Birke < gabriel.birke@wikimedia.de > |
24 | * @author Addshore |
25 | */ |
26 | class CognateHooks implements |
27 | PageSaveCompleteHook, |
28 | PageMoveCompleteHook, |
29 | ContentAlterParserOutputHook, |
30 | WikiPageDeletionUpdatesHook, |
31 | ArticleUndeleteHook |
32 | { |
33 | |
34 | /** |
35 | * @param WikiPage $wikiPage |
36 | * @param UserIdentity $userIdentity |
37 | * @param string $summary |
38 | * @param int $flags |
39 | * @param RevisionRecord $revisionRecord |
40 | * @param EditResult $editResult unused |
41 | */ |
42 | public function onPageSaveComplete( |
43 | $wikiPage, |
44 | $userIdentity, |
45 | $summary, |
46 | $flags, |
47 | $revisionRecord, |
48 | $editResult |
49 | ) { |
50 | CognateServices::getPageHookHandler()->onPageContentSaveComplete( |
51 | $wikiPage->getTitle(), |
52 | $revisionRecord |
53 | ); |
54 | } |
55 | |
56 | /** |
57 | * @param WikiPage $page |
58 | * @param Content|null $content |
59 | * @param DeferrableUpdate[] &$updates |
60 | */ |
61 | public function onWikiPageDeletionUpdates( |
62 | $page, |
63 | $content, |
64 | &$updates |
65 | ) { |
66 | CognateServices::getPageHookHandler() |
67 | ->onWikiPageDeletionUpdates( $page->getTitle(), $updates ); |
68 | } |
69 | |
70 | /** |
71 | * @param Title $title |
72 | * @param bool $create |
73 | * @param string $comment |
74 | * @param int $oldPageId |
75 | * @param array $restoredPages |
76 | */ |
77 | public function onArticleUndelete( |
78 | $title, |
79 | $create, |
80 | $comment, |
81 | $oldPageId, |
82 | $restoredPages |
83 | ) { |
84 | CognateServices::getPageHookHandler()->onArticleUndelete( $title ); |
85 | } |
86 | |
87 | /** |
88 | * @param LinkTarget $title |
89 | * @param LinkTarget $newTitle |
90 | * @param UserIdentity $userIdentity |
91 | * @param int $oldid |
92 | * @param int $newid |
93 | * @param string $reason |
94 | * @param RevisionRecord $nullRevisionRecord |
95 | */ |
96 | public function onPageMoveComplete( |
97 | $title, |
98 | $newTitle, |
99 | $userIdentity, |
100 | $oldid, |
101 | $newid, |
102 | $reason, |
103 | $nullRevisionRecord |
104 | ) { |
105 | CognateServices::getPageHookHandler()->onTitleMoveComplete( $title, $newTitle ); |
106 | } |
107 | |
108 | /** |
109 | * @param Content $content |
110 | * @param Title $title |
111 | * @param ParserOutput $parserOutput |
112 | */ |
113 | public function onContentAlterParserOutput( |
114 | $content, |
115 | $title, |
116 | $parserOutput |
117 | ) { |
118 | // this hook tries to access repo SiteLinkTable |
119 | // it interferes with any test that parses something, like a page or a message |
120 | if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
121 | return; |
122 | } |
123 | |
124 | $handler = CognateParseHookHandler::newFromGlobalState(); |
125 | $handler->doContentAlterParserOutput( $title, $parserOutput ); |
126 | } |
127 | } |