Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
VisualEditorDesktopArticleTargetInitModule
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 getMessages
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * ResourceLoader module for the 'ext.visualEditor.desktopArticleTarget.init'
4 * module. Necessary to incorporate the VisualEditorTabMessages
5 * configuration setting.
6 *
7 * @file
8 * @ingroup Extensions
9 * @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
10 * @license MIT
11 */
12
13namespace MediaWiki\Extension\VisualEditor;
14
15use MediaWiki\MediaWikiServices;
16use MediaWiki\ResourceLoader\FileModule;
17
18class VisualEditorDesktopArticleTargetInitModule extends FileModule {
19
20    /**
21     * @inheritDoc
22     */
23    public function getMessages() {
24        $messages = parent::getMessages();
25        $services = MediaWikiServices::getInstance();
26
27        $veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
28        $messages = array_merge(
29            $messages,
30            array_filter( $veConfig->get( 'VisualEditorTabMessages' ) )
31        );
32
33        // Some skins don't use the default 'edit' and 'create' message keys.
34        // Check the localisation cache for which skins have a custom message for this.
35        // We only need this for the current skin, but ResourceLoader's message cache
36        // does not fragment by skin.
37        foreach ( [ 'edit', 'create', 'edit-local', 'create-local' ] as $msgKey ) {
38            // MediaWiki defaults
39            // * skin-view-edit
40            // * skin-view-create
41            // * skin-view-edit-local
42            // * skin-view-create-local
43            $messages[] = "skin-view-$msgKey";
44            foreach ( $services->getSkinFactory()->getInstalledSkins() as $skname => $unused ) {
45                // Per-skin overrides
46                // Messages: vector-view-edit, vector-view-create
47                // Disable database lookups for site-level message overrides as they
48                // are expensive and not needed here (T221294). We only care whether the
49                // message key is known to localisation cache at all.
50                $msg = wfMessage( "$skname-view-$msgKey" )->useDatabase( false )->inContentLanguage();
51                if ( $msg->exists() ) {
52                    $messages[] = "$skname-view-$msgKey";
53                }
54            }
55        }
56
57        return $messages;
58    }
59
60}