Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractContentEditAction
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 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%
26 / 26
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\Content\ContentHandlerFactory;
15use MediaWiki\Context\IContextSource;
16use MediaWiki\Extension\WikiLambda\PageTitle\PageTitleBuilder;
17use MediaWiki\Page\Article;
18use MediaWiki\Revision\RevisionStore;
19
20class AbstractContentEditAction extends Action {
21    use AbstractContentEditPageTrait;
22
23    /**
24     * @param Article $article
25     * @param IContextSource $context
26     * @param RevisionStore $revisionStore
27     * @param ContentHandlerFactory $contentHandlerFactory
28     */
29    public function __construct(
30        Article $article,
31        IContextSource $context,
32        private readonly RevisionStore $revisionStore,
33        private readonly ContentHandlerFactory $contentHandlerFactory
34    ) {
35        parent::__construct( $article, $context );
36    }
37
38    /**
39     * @inheritDoc
40     */
41    public function getName() {
42        return 'edit';
43    }
44
45    /**
46     * @inheritDoc
47     */
48    public function show() {
49        $output = $this->getOutput();
50
51        $pageTitle = $this->getTitle();
52        if ( !$this->generateAbstractContentPayload(
53            $this->getContext(),
54            $this->revisionStore,
55            $this->contentHandlerFactory,
56            $output,
57            $pageTitle
58        ) ) {
59            // Requested revision is hidden from this viewer; the deleted-text
60            // message has been shown, so render no editor.
61            return;
62        }
63
64        // Load styles and Vue app module
65        $output->addModuleStyles( [ 'ext.wikilambda.editpage.styles' ] );
66        $output->addModules( [ 'ext.wikilambda.app' ] );
67
68        // Set page header (edit or create, depending on the returned config vars)
69        $lang = $this->getContext()->getLanguage();
70        $qid = $pageTitle->getBaseText();
71        $editPageTitle = PageTitleBuilder::createAbstractEditPageHTMLTitleText( $pageTitle, $lang->getCode() );
72
73        // Rich HTML for the H1 display
74        $output->setPageTitle(
75            PageTitleBuilder::createAbstractEditPageTitle(
76                $editPageTitle,
77                $lang->getCode(),
78                $lang->getDir(),
79                $qid
80            )
81        );
82        // Plain-text override for the browser <title> tag: the same text (which already
83        // embeds the QID) plus the " - {{SITENAME}}" suffix, matching the view and history
84        // variants. (T426833) Previously appended " ($qid)" a second time.
85        $output->setHTMLTitle(
86            PageTitleBuilder::createAbstractEditPageHtmlTitle( $editPageTitle, $lang->getCode() )
87        );
88    }
89
90    /**
91     * @inheritDoc
92     */
93    public function getRestriction() {
94        return 'wikilambda-abstract-create';
95    }
96
97    /**
98     * @inheritDoc
99     */
100    public function doesWrites() {
101        return true;
102    }
103}