Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
SpecialMergeThread | |
0.00% |
0 / 48 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
getFormFields | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 | |||
getRightRequirement | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkParameters | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
formatThreadField | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
trySubmit | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
getPageName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSubmitText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | use MediaWiki\Html\Html; |
4 | use MediaWiki\Message\Message; |
5 | |
6 | // @todo FIXME: access control |
7 | class SpecialMergeThread extends ThreadActionPage { |
8 | |
9 | /** @var Thread */ |
10 | protected $mDestThread; |
11 | |
12 | public function getFormFields() { |
13 | $splitForm = [ |
14 | 'src' => [ |
15 | 'type' => 'info', |
16 | 'label-message' => 'lqt-thread-merge-source', |
17 | 'default' => $this->formatThreadField( 'src', $this->mThread->id() ), |
18 | 'raw' => true |
19 | ], |
20 | 'dest' => [ |
21 | 'type' => 'info', |
22 | 'label-message' => 'lqt-thread-merge-dest', |
23 | 'default' => $this->formatThreadField( 'dest', $this->request->getInt( 'dest' ) ), |
24 | 'raw' => true |
25 | ], |
26 | 'reason' => [ |
27 | 'label-message' => 'movereason', |
28 | 'type' => 'text' |
29 | ] |
30 | ]; |
31 | |
32 | return $splitForm; |
33 | } |
34 | |
35 | protected function getRightRequirement() { |
36 | return 'lqt-merge'; |
37 | } |
38 | |
39 | public function checkParameters( $par ) { |
40 | if ( !parent::checkParameters( $par ) ) { |
41 | return false; |
42 | } |
43 | |
44 | $dest = $this->request->getInt( 'dest' ); |
45 | |
46 | if ( !$dest ) { |
47 | $this->getOutput()->addWikiMsg( 'lqt_threadrequired' ); |
48 | return false; |
49 | } |
50 | |
51 | $thread = Threads::withId( $dest ); |
52 | |
53 | if ( !$thread ) { |
54 | $this->getOutput()->addWikiMsg( 'lqt_nosuchthread' ); |
55 | return false; |
56 | } |
57 | |
58 | $this->mDestThread = $thread; |
59 | |
60 | return true; |
61 | } |
62 | |
63 | /** |
64 | * @param string $field |
65 | * @param int $threadid |
66 | * @return string |
67 | */ |
68 | public function formatThreadField( $field, $threadid ) { |
69 | $t = Threads::withId( $threadid ); |
70 | |
71 | $out = Html::hidden( $field, $threadid ); |
72 | $out .= LqtView::permalink( $t ); |
73 | |
74 | return $out; |
75 | } |
76 | |
77 | /** |
78 | * @see SpecialPage::getDescription |
79 | * @return Message |
80 | */ |
81 | public function getDescription() { |
82 | return $this->msg( 'lqt_merge_thread' ); |
83 | } |
84 | |
85 | public function trySubmit( $data ) { |
86 | // Load data |
87 | $srcThread = $this->mThread; |
88 | $dstThread = $this->mDestThread; |
89 | $reason = $data['reason']; |
90 | |
91 | $srcThread->moveToParent( $dstThread, $reason ); |
92 | |
93 | $srcLink = LqtView::linkInContext( $srcThread ); |
94 | $dstLink = LqtView::linkInContext( $dstThread ); |
95 | |
96 | $this->getOutput()->addHTML( $this->msg( 'lqt-merge-success' ) |
97 | ->rawParams( $srcLink, $dstLink )->parse() ); |
98 | |
99 | return true; |
100 | } |
101 | |
102 | public function getPageName() { |
103 | return 'MergeThread'; |
104 | } |
105 | |
106 | public function getSubmitText() { |
107 | return $this->msg( 'lqt-merge-submit' )->text(); |
108 | } |
109 | } |