Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
4.17% |
2 / 48 |
|
25.00% |
2 / 8 |
CRAP | |
0.00% |
0 / 1 |
PFForm | |
4.17% |
2 / 48 |
|
25.00% |
2 / 8 |
336.73 | |
0.00% |
0 / 1 |
create | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getFormName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getItems | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPageNameFormula | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setCreateTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setEditTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setAssociatedCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createMarkup | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
132 |
1 | <?php |
2 | |
3 | /** |
4 | * Represents a user-defined form. |
5 | * |
6 | * @author Yaron Koren |
7 | * @file |
8 | * @ingroup PF |
9 | */ |
10 | class PFForm { |
11 | private $mFormName; |
12 | private $mPageNameFormula; |
13 | private $mCreateTitle; |
14 | private $mEditTitle; |
15 | private $mAssociatedCategory; |
16 | private $mItems; |
17 | |
18 | static function create( $formName, $items ) { |
19 | $form = new PFForm(); |
20 | if ( $formName !== null ) { |
21 | $form->mFormName = ucfirst( str_replace( '_', ' ', $formName ) ); |
22 | } |
23 | $form->mItems = $items; |
24 | return $form; |
25 | } |
26 | |
27 | function getFormName() { |
28 | return $this->mFormName; |
29 | } |
30 | |
31 | function getItems() { |
32 | return $this->mItems; |
33 | } |
34 | |
35 | function setPageNameFormula( $pageNameFormula ) { |
36 | $this->mPageNameFormula = $pageNameFormula; |
37 | } |
38 | |
39 | function setCreateTitle( $createTitle ) { |
40 | $this->mCreateTitle = $createTitle; |
41 | } |
42 | |
43 | function setEditTitle( $editTitle ) { |
44 | $this->mEditTitle = $editTitle; |
45 | } |
46 | |
47 | function setAssociatedCategory( $associatedCategory ) { |
48 | $this->mAssociatedCategory = $associatedCategory; |
49 | } |
50 | |
51 | function createMarkup( $includeFreeText = true, $freeTextLabel = null ) { |
52 | $title = Title::makeTitle( PF_NS_FORM, $this->mFormName ); |
53 | $fs = PFUtils::getSpecialPage( 'FormStart' ); |
54 | $form_start_url = PFUtils::titleURLString( $fs->getPageTitle() ) . "/" . $title->getPartialURL(); |
55 | $form_description = wfMessage( 'pf_form_docu', $this->mFormName, $form_start_url )->inContentLanguage()->text(); |
56 | $form_input = "{{#forminput:form=" . str_replace( ',', '\,', $this->mFormName ); |
57 | if ( $this->mAssociatedCategory !== null ) { |
58 | $form_input .= "|autocomplete on category=" . $this->mAssociatedCategory; |
59 | } |
60 | $form_input .= "}}\n"; |
61 | $text = <<<END |
62 | <noinclude> |
63 | $form_description |
64 | |
65 | $form_input |
66 | </noinclude><includeonly> |
67 | |
68 | END; |
69 | $info = ''; |
70 | if ( !empty( $this->mPageNameFormula ) ) { |
71 | $info .= "|page name=" . $this->mPageNameFormula; |
72 | } |
73 | if ( !empty( $this->mCreateTitle ) ) { |
74 | $info .= "|create title=" . $this->mCreateTitle; |
75 | } |
76 | if ( !empty( $this->mEditTitle ) ) { |
77 | $info .= "|edit title=" . $this->mEditTitle; |
78 | } |
79 | if ( $info ) { |
80 | $text .= "{{{info" . $info . "}}}\n"; |
81 | } |
82 | $text .= <<<END |
83 | <div id="wikiPreview" style="display: none; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid #AAAAAA;"></div> |
84 | |
85 | END; |
86 | foreach ( $this->mItems as $item ) { |
87 | if ( $item['type'] == 'template' ) { |
88 | $template = $item['item']; |
89 | $text .= $template->createMarkup() . "\n"; |
90 | } elseif ( $item['type'] == 'section' ) { |
91 | $section = $item['item']; |
92 | $text .= $section->createMarkup() . "\n"; |
93 | } |
94 | } |
95 | |
96 | if ( $includeFreeText ) { |
97 | if ( $freeTextLabel === null ) { |
98 | $freeTextLabel = wfMessage( 'pf_form_freetextlabel' )->inContentLanguage()->text(); |
99 | } |
100 | $text .= <<<END |
101 | '''$freeTextLabel:''' |
102 | |
103 | {{{standard input|free text|rows=10}}} |
104 | |
105 | END; |
106 | } |
107 | $text .= "</includeonly>\n"; |
108 | |
109 | return $text; |
110 | } |
111 | |
112 | } |