Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
LexiconArticleEditHook
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 onCustomEditor
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace MediaWiki\Wikispeech\Hooks;
4
5/**
6 * @file
7 * @ingroup Extensions
8 * @license GPL-2.0-or-later
9 */
10
11use Article;
12use MediaWiki\Hook\CustomEditorHook;
13use SpecialPage;
14use User;
15
16/**
17 * Redirects edits of lexicon wiki pages to SpecialPage:EditLexicon
18 *
19 * @since 0.1.9
20 */
21class LexiconArticleEditHook implements CustomEditorHook {
22
23    /**
24     * This hook is called when invoking the page editor.
25     *
26     * @since 0.1.9
27     * @param Article $article Article being edited
28     * @param User $user User performing the edit
29     * @return bool|void True or no return value to allow the normal editor to be used.
30     *   False if implementing a custom editor, e.g. for a special namespace, etc.
31     */
32    public function onCustomEditor(
33        $article,
34        $user
35    ) {
36        if ( !$article->getTitle()->inNamespace( NS_PRONUNCIATION_LEXICON ) ) {
37            return true;
38        }
39        $tuple = explode( '/', $article->getTitle()->getText(), 2 );
40        $language = mb_strtolower( $tuple[0] );
41        $key = $tuple[1];
42
43        $editLexicon = SpecialPage::getTitleFor( 'EditLexicon' );
44        $article->getContext()->getOutput()->redirect(
45            $editLexicon->getFullURL( [
46                'word' => $key,
47                'language' => $language,
48            ] )
49        );
50        return true;
51    }
52}