Completed
Branch master (939199)
by
unknown
39:35
created

includes/actions/PurgeAction.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * User-requested page cache purging.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
 *
19
 * @file
20
 * @ingroup Actions
21
 */
22
23
/**
24
 * User-requested page cache purging
25
 *
26
 * @ingroup Actions
27
 */
28
class PurgeAction extends FormAction {
29
30
	private $redirectParams;
31
32
	public function getName() {
33
		return 'purge';
34
	}
35
36
	public function requiresUnblock() {
37
		return false;
38
	}
39
40
	public function getDescription() {
41
		return '';
42
	}
43
44
	public function onSubmit( $data ) {
45
		return $this->page->doPurge( WikiPage::PURGE_ALL );
0 ignored issues
show
The method doPurge does only exist in Article and CategoryPage... ImagePage and WikiPage, but not in Page.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
46
	}
47
48
	public function show() {
49
		$this->setHeaders();
50
51
		// This will throw exceptions if there's a problem
52
		$this->checkCanExecute( $this->getUser() );
53
54
		$user = $this->getUser();
55
56
		if ( $user->pingLimiter( 'purge' ) ) {
57
			// TODO: Display actionthrottledtext
58
			return;
59
		}
60
61
		if ( $this->getRequest()->wasPosted() ) {
62
			$this->redirectParams = wfArrayToCgi( array_diff_key(
63
				$this->getRequest()->getQueryValues(),
64
				[ 'title' => null, 'action' => null ]
65
			) );
66
			if ( $this->onSubmit( [] ) ) {
67
				$this->onSuccess();
68
			}
69
		} else {
70
			$this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
71
			$form = $this->getForm();
72
			if ( $form->show() ) {
73
				$this->onSuccess();
74
			}
75
		}
76
	}
77
78
	protected function alterForm( HTMLForm $form ) {
79
		$form->setSubmitTextMsg( 'confirm_purge_button' );
80
	}
81
82
	protected function preText() {
83
		return $this->msg( 'confirm-purge-top' )->parse();
84
	}
85
86
	protected function postText() {
87
		return $this->msg( 'confirm-purge-bottom' )->parse();
88
	}
89
90
	public function onSuccess() {
91
		$this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
92
	}
93
94
	public function doesWrites() {
95
		return true;
96
	}
97
}
98