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