| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
namespace MediaWiki\Extension\DiscussionTools\Hooks; |
| 11 |
|
| 12 |
use MediaWiki\ChangeTags\Hook\ChangeTagsListActiveHook; |
| 13 |
use MediaWiki\ChangeTags\Hook\ListDefinedTagsHook; |
| 14 |
use MediaWiki\Context\RequestContext; |
| 15 |
use MediaWiki\Hook\RecentChange_saveHook; |
| 16 |
use RecentChange; |
| 17 |
|
| 18 |
class TagHooks implements |
| 19 |
ChangeTagsListActiveHook, |
| 20 |
ListDefinedTagsHook, |
| 21 |
RecentChange_saveHook |
| 22 |
{ |
| 23 |
private const TAGS = [ |
| 24 |
'discussiontools', |
| 25 |
|
| 26 |
'discussiontools-reply', |
| 27 |
'discussiontools-edit', |
| 28 |
'discussiontools-newtopic', |
| 29 |
'discussiontools-added-comment', |
| 30 |
|
| 31 |
'discussiontools-source', |
| 32 |
'discussiontools-visual', |
| 33 |
|
| 34 |
'discussiontools-source-enhanced', |
| 35 |
]; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function onChangeTagsListActive( &$tags ) { |
| 42 |
$this->onListDefinedTags( $tags ); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function onListDefinedTags( &$tags ) { |
| 52 |
$tags = array_merge( $tags, static::TAGS ); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function onRecentChange_save( $recentChange ) { |
| 65 |
|
| 66 |
|
| 67 |
if ( !defined( 'MW_API' ) ) { |
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
$tags = static::getDiscussionToolsTagsFromRequest(); |
| 72 |
if ( $tags ) { |
| 73 |
$recentChange->addTags( $tags ); |
| 74 |
} |
| 75 |
|
| 76 |
return true; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public static function getDiscussionToolsTagsFromRequest(): array { |
| 83 |
$request = RequestContext::getMain()->getRequest(); |
| 84 |
$tags = explode( ',', $request->getText( 'dttags' ) ); |
| 85 |
return array_values( array_intersect( $tags, static::TAGS ) ); |
| 86 |
} |
| 87 |
} |