SpecialWikibasePage   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 82
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getGroupName() 0 3 1
A getDescription() 0 3 1
A setHeaders() 0 5 1
A execute() 0 9 2
A checkBlocked() 0 6 3
A showErrorHTML() 0 3 1
1
<?php
2
3
namespace Wikibase\Repo\Specials;
4
5
use SpecialPage;
6
use UserBlockedError;
7
use Wikibase\Lib\StringNormalizer;
8
9
/**
10
 * Base for special pages of the Wikibase extension,
11
 * holding some scaffolding and preventing us from needing to
12
 * deal with weird SpecialPage insanity (ie $this->mFile inclusion)
13
 * in every base class.
14
 *
15
 * @license GPL-2.0-or-later
16
 * @author Jeroen De Dauw < [email protected] >
17
 * @author Bene* < [email protected] >
18
 */
19
abstract class SpecialWikibasePage extends SpecialPage {
20
21
	/**
22
	 * @var StringNormalizer
23
	 */
24
	protected $stringNormalizer;
25
26
	/**
27
	 * @param string $name
28
	 * @param string $restriction
29
	 * @param bool   $listed
30
	 */
31
	public function __construct( $name = '', $restriction = '', $listed = true ) {
32
		parent::__construct( $name, $restriction, $listed );
33
34
		// XXX: Use StringNormalizer as a plain composite - since it
35
		//      doesn't have any dependencies, local instantiation isn't an issue.
36
		$this->stringNormalizer = new StringNormalizer();
37
	}
38
39
	/**
40
	 * @see SpecialPage::getGroupName
41
	 *
42
	 * @return string
43
	 */
44
	protected function getGroupName() {
45
		return 'wikibase';
46
	}
47
48
	/**
49
	 * @see SpecialPage::getDescription
50
	 *
51
	 * @return string
52
	 */
53
	public function getDescription() {
54
		return $this->msg( 'special-' . strtolower( $this->getName() ) )->text();
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
55
	}
56
57
	/**
58
	 * @inheritDoc
59
	 */
60
	public function setHeaders() {
61
		$out = $this->getOutput();
62
		$out->setArticleRelated( false );
63
		$out->setPageTitle( $this->getDescription() );
64
	}
65
66
	/**
67
	 * @see SpecialPage::execute
68
	 *
69
	 * @param string|null $subPage
70
	 */
71
	public function execute( $subPage ) {
72
		$this->setHeaders();
73
		$this->outputHeader( 'wikibase-' . strtolower( $this->getName() ) . '-summary' );
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
74
75
		// If the user is authorized, display the page, if not, show an error.
76
		if ( !$this->userCanExecute( $this->getUser() ) ) {
77
			$this->displayRestrictionError();
78
		}
79
	}
80
81
	/**
82
	 * Checks if user is blocked, and if blocked throws a UserBlocked.
83
	 *
84
	 * @throws UserBlockedError
85
	 */
86
	protected function checkBlocked() {
87
		$block = $this->getUser()->getBlock();
88
		if ( $block && $block->isSitewide() ) {
89
			throw new UserBlockedError( $this->getUser()->getBlock() );
90
		}
91
	}
92
93
	/**
94
	 * @param string $error The error message in HTML format
95
	 */
96
	protected function showErrorHTML( $error ) {
97
		$this->getOutput()->addHTML( '<p class="error">' . $error . '</p>' );
98
	}
99
100
}
101