-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHooks.php
54 lines (49 loc) · 1.48 KB
/
Hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Hooks for ExportForTranslation extension
*
* @file
* @ingroup Extensions
*/
namespace ExportForTranslation;
use MediaWiki\MediaWikiServices;
use SkinTemplate;
use SpecialPage;
class Hooks {
/**
* @param SkinTemplate &$sktemplate The skin template on which the UI is built.
* @param array &$links Navigation links.
*
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation
*/
public static function onSkinTemplateNavigation( SkinTemplate &$sktemplate, array &$links ) {
global $wgExportForTranslationNamespaces;
$title = $sktemplate->getRelevantTitle();
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if (
is_array( $wgExportForTranslationNamespaces ) &&
in_array( $title->getNamespace(), $wgExportForTranslationNamespaces ) &&
$title->exists() &&
$permissionManager->userHasRight( $sktemplate->getUser(), 'export-for-translation' )
) {
self::addButtonToToolbar( $sktemplate, $links );
}
}
/**
* @param SkinTemplate &$sktemplate
* @param array &$links
*
* @return void
* @throws \MWException
*/
public static function addButtonToToolbar( SkinTemplate &$sktemplate, array &$links ) {
$title = $sktemplate->getRelevantTitle();
$exportPage = SpecialPage::getTitleFor(
'ExportForTranslation', $title->getFullText()
);
$links[ 'actions' ][ 'exportfortranslation' ] = [
'text' => $sktemplate->msg( 'exportfortranslation-btn' )->text(),
'href' => $exportPage->getLocalURL()
];
}
}