Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 67
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CollaborationListContentEditor
0.00% covered (danger)
0.00%
0 / 67
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 showContentForm
0.00% covered (danger)
0.00%
0 / 45
0.00% covered (danger)
0.00%
0 / 1
20
 importContentFormData
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3/**
4 * Specialized editing interface for CollaborationListContent pages.
5 * Extends the notorious EditPage class.
6 *
7 * @todo Unicode unsafe browsers?
8 * @file
9 */
10
11class CollaborationListContentEditor extends EditPage {
12
13    public function __construct( Article $page ) {
14        parent::__construct( $page );
15        // Make human readable the default format for editing, but still
16        // save as json. Can be overriden by url ?format=application/json param.
17        if ( $this->getCurrentContent()->isValid() ) {
18            $this->contentFormat = CollaborationListContentHandler::FORMAT_WIKI;
19        }
20
21        $out = $this->getContext()->getOutput();
22        $out->addModules( 'mediawiki.htmlform' );
23        $out->addModuleStyles( 'ext.CollaborationKit.edit.styles' );
24    }
25
26    /**
27     * Prepares a modified edit form
28     */
29    protected function showContentForm() {
30        if ( $this->contentFormat !== CollaborationListContentHandler::FORMAT_WIKI ) {
31            parent::showContentForm();
32            return;
33        }
34
35        $parts = explode(
36            CollaborationKitSerialization::SERIALIZATION_SPLIT,
37            $this->textbox1,
38            3
39        );
40        if ( count( $parts ) !== 3 ) {
41            parent::showContentForm();
42            return;
43        }
44        $out = $this->getContext()->getOutput();
45        $out->addHTML( Html::hidden( 'wpCollaborationKitOptions', $parts[1] ) );
46
47        if ( $parts[2] == '' ) {
48            $includedContent = '';
49        } else {
50            $includedContent = $parts[2];
51        }
52        $fields = [
53            'description' => [
54                'type' => 'textarea',
55                'cssclass' => 'mw-ck-introduction-input',
56                'label-message' => 'collaborationkit-listedit-description',
57                'placeholder-message' => 'collaborationkit-listedit-description-placeholder',
58                'name' => 'wpCollabListDescription',
59                'default' => $parts[0],
60                'rows' => 4,
61                'id' => 'wpCollabListDescription'
62            ],
63            'content' => [
64                'type' => 'textarea',
65                'cssclass' => 'mw-ck-content-input',
66                'label-message' => 'collaborationkit-listedit-list',
67                'help-message' => 'collaborationkit-listedit-list-help',
68                'name' => 'wpCollabListContent',
69                'default' => $includedContent,
70                'rows' => 18,
71                'id' => 'wpCollabListContent'
72            ]
73        ];
74
75        $dummyForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
76        $partFields = $dummyForm->prepareForm()->getBody();
77
78        $out->addHTML( Html::rawElement(
79            'div',
80            [ 'class' => 'mw-collabkit-modifiededitform' ],
81            $partFields
82        ) );
83    }
84
85    /**
86     * Takes contents of edit form and serializes it.
87     *
88     * @param WebRequest &$request
89     * @return string
90     */
91    protected function importContentFormData( &$request ) {
92        $format = $request->getVal(
93            'format',
94            CollaborationListContentHandler::FORMAT_WIKI
95        );
96        if ( $format !== CollaborationListContentHandler::FORMAT_WIKI ) {
97            return parent::importContentFormData( $request );
98        }
99        $desc = trim( $request->getText( 'wpCollabListDescription', '' ) );
100        if ( $desc === '' ) {
101            // Only 1 textbox?
102            return parent::importContentFormData( $request );
103        }
104        $main = trim( $request->getText( 'wpCollabListContent', '' ) );
105        $options = $request->getText( 'wpCollaborationKitOptions', '' );
106
107        return CollaborationKitSerialization::getSerialization( [
108            $desc,
109            $options,
110            $main
111        ] );
112    }
113}