Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 78
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialMoveThread
0.00% covered (danger)
0.00%
0 / 78
0.00% covered (danger)
0.00%
0 / 8
240
0.00% covered (danger)
0.00%
0 / 1
 getDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFormFields
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
6
 getPageName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSubmitText
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildForm
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
2
 checkUserRights
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 trySubmit
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
6
 validateTarget
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3use MediaWiki\MediaWikiServices;
4use MediaWiki\Message\Message;
5use MediaWiki\Permissions\PermissionStatus;
6use MediaWiki\SpecialPage\SpecialPage;
7use MediaWiki\Title\Title;
8
9class SpecialMoveThread extends ThreadActionPage {
10    /**
11     * @see SpecialPage::getDescription
12     * @return Message
13     */
14    public function getDescription() {
15        return $this->msg( 'lqt_movethread' );
16    }
17
18    public function getFormFields() {
19        $destAdditions = [];
20        $reasonAdditions = [];
21        if ( $this->getRequest()->getCheck( 'dest' ) ) {
22            $destAdditions['default'] = $this->getRequest()->getText( 'dest' );
23            $reasonAdditions['autofocus'] = true;
24        } else {
25            $destAdditions['autofocus'] = true;
26        }
27
28        return [
29            'dest-title' => [
30                'label-message' => 'lqt_move_destinationtitle',
31                'type' => 'text',
32                'validation-callback' => [ $this, 'validateTarget' ],
33            ] + $destAdditions,
34            'reason' => [
35                'label-message' => 'movereason',
36                'type' => 'text',
37            ] + $reasonAdditions,
38        ];
39    }
40
41    public function getPageName() {
42        return 'MoveThread';
43    }
44
45    public function getSubmitText() {
46        return $this->msg( 'lqt_move_move' )->text();
47    }
48
49    public function buildForm() {
50        $form = parent::buildForm();
51
52        // Generate introduction
53        $intro = '';
54
55        $page = $this->mThread->getTitle()->getPrefixedText();
56
57        $edit_text = new HtmlArmor( $this->msg( 'lqt_move_torename_edit' )->parse() );
58        $edit_link = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
59            $this->mThread->title(),
60            $edit_text,
61            [],
62            [
63                'lqt_method' => 'edit',
64                'lqt_operand' => $this->mThread->id()
65            ]
66        );
67
68        $intro .= $this->msg(
69            'lqt_move_movingthread',
70            [ '[[' . $this->mTarget . ']]', '[[' . $page . ']]' ]
71        )->parseAsBlock();
72        $intro .= $this->msg( 'lqt_move_torename' )->rawParams( $edit_link )->parseAsBlock();
73
74        $form->setPreHtml( $intro );
75
76        return $form;
77    }
78
79    public function checkUserRights( $oldTitle, $newTitle ) {
80        $user = $this->getUser();
81        $status = new PermissionStatus();
82        $permManager = MediaWikiServices::getInstance()->getPermissionManager();
83        $status->merge( $permManager->getPermissionStatus( 'move', $user, $oldTitle ) );
84        $status->merge( $permManager->getPermissionStatus( 'move', $user, $newTitle ) );
85
86        if ( !$status->isGood() ) {
87            $out = $this->getOutput();
88            return $out->parseAsInterface(
89                $out->formatPermissionStatus( $status, 'move' )
90            );
91        }
92
93        return true;
94    }
95
96    public function trySubmit( $data ) {
97        // Load data
98        $tmp = $data['dest-title'];
99        $oldtitle = $this->mThread->getTitle();
100        $newtitle = Title::newFromText( $tmp );
101        $reason = $data['reason'];
102
103        $rightsResult = $this->checkUserRights( $this->mThread->title(), $newtitle );
104
105        if ( $rightsResult !== true ) {
106            return $rightsResult;
107        }
108
109        // @todo No status code from this method.
110        $this->mThread->moveToPage( $newtitle, $reason, true, $this->getUser() );
111        $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
112
113        $this->getOutput()->addHTML( $this->msg( 'lqt_move_success' )->rawParams(
114            $linkRenderer->makeLink( $newtitle ),
115            $linkRenderer->makeLink(
116                SpecialPage::getTitleFor( 'MoveThread', $this->mThread->root()->getTitle() ),
117                $this->msg( 'revertmove' )->text(),
118                [],
119                [ 'dest' => $oldtitle ]
120            )
121        )->parseAsBlock() );
122
123        return true;
124    }
125
126    public function validateTarget( $target ) {
127        if ( !$target ) {
128            return $this->msg( 'lqt_move_nodestination' )->parse();
129        }
130
131        $title = Title::newFromText( $target );
132
133        if ( !$title || !LqtDispatch::isLqtPage( $title ) ) {
134            return $this->msg( 'lqt_move_thread_bad_destination' )->parse();
135        }
136
137        if ( $title->equals( $this->mThread->getTitle() ) ) {
138            return $this->msg( 'lqt_move_samedestination' )->parse();
139        }
140
141        return true;
142    }
143}