Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractContentEditAction
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 show
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getPageTitleMsg
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getRestriction
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 doesWrites
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * WikiLambda edit action for Abstract Wiki content
4 *
5 * @file
6 * @ingroup Extensions
7 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
8 * @license MIT
9 */
10
11namespace MediaWiki\Extension\WikiLambda\AbstractContent;
12
13use MediaWiki\Actions\Action;
14use MediaWiki\Title\Title;
15
16class AbstractContentEditAction extends Action {
17    use AbstractContentEditPageTrait;
18
19    /**
20     * @inheritDoc
21     */
22    public function getName() {
23        return 'edit';
24    }
25
26    /**
27     * @inheritDoc
28     */
29    public function show() {
30        $output = $this->getOutput();
31
32        $pageTitle = $this->getTitle();
33        $this->generateAbstractContentPayload( $this->getContext(), $output, $pageTitle );
34
35        // Load styles and Vue app module
36        $output->addModuleStyles( [ 'ext.wikilambda.editpage.styles' ] );
37        $output->addModules( [ 'ext.wikilambda.app' ] );
38
39        // Set page header (edit or create, depending on the returned config vars)
40        $output->setPageTitle( $this->getPageTitleMsg( $pageTitle ) );
41    }
42
43    /**
44     * Get page header title for an edit page:
45     * * when content is new: show create title
46     * * when content exists: show edit tile
47     *
48     * @param Title $title
49     * @return string
50     */
51    protected function getPageTitleMsg( Title $title ): string {
52        $pageExists = $title->exists();
53        return $pageExists ?
54            $this->msg( 'wikilambda-abstract-edit-title' )->params( $title->getText() )->text() :
55            $this->msg( 'wikilambda-abstract-special-create-qid' )->params( $title->getText() )->text();
56    }
57
58    /**
59     * @inheritDoc
60     */
61    public function getRestriction() {
62        return 'wikilambda-abstract-create';
63    }
64
65    /**
66     * @inheritDoc
67     */
68    public function doesWrites() {
69        return true;
70    }
71}