Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
SkinTemplateNavigationUniversal | |
0.00% |
0 / 41 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
handle | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
process | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
12 | |||
isFilePage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
makeExcludeNS | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getEditableNamespaces | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace NSFileRepo\Hooks; |
4 | |
5 | use NSFileRepo\NamespaceList; |
6 | use IContextSource; |
7 | use Config; |
8 | use SkinTemplate; |
9 | use Message; |
10 | use Title; |
11 | use FormatJson; |
12 | |
13 | class SkinTemplateNavigationUniversal { |
14 | |
15 | /** |
16 | * |
17 | * @var Config |
18 | */ |
19 | protected $config = null; |
20 | |
21 | /** |
22 | * |
23 | * @var IContextSource |
24 | */ |
25 | protected $context = null; |
26 | |
27 | /** |
28 | * |
29 | * @var SkinTemplate |
30 | */ |
31 | protected $sktemplate = null; |
32 | |
33 | /** |
34 | * |
35 | * @var array |
36 | */ |
37 | protected $links = []; |
38 | |
39 | /** |
40 | * |
41 | * @param SkinTemplate $sktemplate |
42 | * @param array $links |
43 | * @return boolean |
44 | */ |
45 | public static function handle( SkinTemplate $sktemplate, &$links ) { |
46 | $instance = new self( |
47 | \RequestContext::getMain(), |
48 | new \NSFileRepo\Config(), |
49 | $sktemplate, |
50 | $links |
51 | ); |
52 | |
53 | return $instance->process(); |
54 | } |
55 | |
56 | |
57 | /** |
58 | * |
59 | * @param IContextSource $context |
60 | * @param Config $config |
61 | * @param SkinTemplate $sktemplate |
62 | * @param array $links |
63 | */ |
64 | public function __construct( IContextSource $context, Config $config, SkinTemplate $sktemplate, &$links ) { |
65 | $this->context = $context; |
66 | $this->config = $config; |
67 | $this->sktemplate = $sktemplate; |
68 | $this->links =& $links; |
69 | } |
70 | |
71 | /** |
72 | * |
73 | * @return boolean |
74 | */ |
75 | public function process() { |
76 | if ( !$this->isFilePage() ) { |
77 | return true; |
78 | } |
79 | |
80 | $editableNamespaces = $this->getEditableNamespaces(); |
81 | if ( empty( $editableNamespaces ) ) { |
82 | return true; |
83 | } |
84 | |
85 | $excludeNS = $this->makeExcludeNS( $editableNamespaces ); |
86 | $filetitle = Title::newFromText( $this->sktemplate->getTitle()->getDBkey() ); |
87 | |
88 | $this->links['actions']['move-file-namespace'] = [ |
89 | 'class' => 'nsfr-move-file-namespace', |
90 | 'text' => Message::newFromKey( 'nsfilerepo-move-file-namespace-action-label' )->plain(), |
91 | 'href' => '#' |
92 | ]; |
93 | |
94 | $this->sktemplate->getOutput()->addModules( 'ext.nsfilerepo.filepage.bootstrap' ); |
95 | $this->sktemplate->getOutput()->addJsConfigVars( 'wgNSFRMoveFileNamespace', [ |
96 | 'currentNamespace' => $filetitle->getNamespace(), |
97 | 'unprefixedFilename' => $filetitle->getDBkey(), |
98 | 'excludeNS' => FormatJson::encode( $excludeNS ) |
99 | ] ); |
100 | |
101 | return true; |
102 | } |
103 | |
104 | private function isFilePage() { |
105 | return $this->sktemplate->getTitle()->getNamespace() === NS_FILE; |
106 | } |
107 | |
108 | private function makeExcludeNS( $editableNamespaces ) { |
109 | $allNamespaces = array_keys( $this->sktemplate->getLanguage()->getNamespaces() ); |
110 | |
111 | $nonEditableNamespaces = array_diff( $allNamespaces, $editableNamespaces ); |
112 | return array_values( $nonEditableNamespaces ); |
113 | } |
114 | |
115 | private function getEditableNamespaces() { |
116 | $nsList = new NamespaceList( |
117 | $this->sktemplate->getUser(), |
118 | $this->config, |
119 | $this->sktemplate->getLanguage() |
120 | ); |
121 | |
122 | $editableNamespaces = array_keys( $nsList->getEditable() ); |
123 | |
124 | return $editableNamespaces; |
125 | } |
126 | } |