SpecialWatchlistConditions   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 125
ccs 0
cts 75
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getDescription() 0 3 1
A setHeaders() 0 6 1
A execute() 0 47 3
A getGroupHtml() 0 27 3
1
<?php
2
3
/**
4
 * Interface to modify the semantic watchlist groups.
5
 *
6
 * @since 0.1
7
 *
8
 * @file SpecialWatchlistConditions.php
9
 * @ingroup SemanticWatchlist
10
 *
11
 * @licence GNU GPL v3 or later
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class SpecialWatchlistConditions extends SpecialPage {
15
16
	/**
17
	 * Constructor.
18
	 *
19
	 * @since 0.1
20
	 */
21
	public function __construct() {
22
		parent::__construct( 'WatchlistConditions', 'semanticwatchgroups' );
23
	}
24
25
	/**
26
	 * @see SpecialPage::getDescription
27
	 *
28
	 * @since 0.1
29
	 */
30
	public function getDescription() {
31
		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...
32
	}
33
34
	/**
35
	 * Sets headers - this should be called from the execute() method of all derived classes!
36
	 *
37
	 * @since 0.1
38
	 */
39
	public function setHeaders() {
40
		global $wgOut;
41
		$wgOut->setArticleRelated( false );
42
		$wgOut->setRobotPolicy( 'noindex,nofollow' );
43
		$wgOut->setPageTitle( $this->getDescription() );
44
	}
45
46
	/**
47
	 * Main method.
48
	 *
49
	 * @since 0.1
50
	 *
51
	 * @param string $arg
52
	 */
53
	public function execute( $arg ) {
54
		global $wgOut;
55
56
		$this->setHeaders();
57
		$this->outputHeader();
58
59
		// If the user is authorized, display the page, if not, show an error.
60
		if ( !$this->userCanExecute( $this->getUser() ) ) {
61
			$this->displayRestrictionError();
62
			return;
63
		}
64
65
		$wgOut->addHTML(
66
			'<strong><p class="saveMessage" style=" display:none;width: 100px; alight:center;text-align:center; background: #f9f9aa; border: 1px solid #dd9">' . $this->msg( 'swl-group-saved' )->text() . '</p></strong>'
67
		);
68
69
		$groupsHtml = array();
70
71
		foreach ( SWLGroups::getAll() as $group ) {
72
			$groupsHtml[] = $this->getGroupHtml( $group );
73
		}
74
		$wgOut->addHTML(
75
			'<div id="swl-groups">' .
76
				implode( '', $groupsHtml ) .
77
			'</div>'
78
		);
79
80
		$wgOut->addHTML( "<p>" . Html::element(
81
			'input',
82
			array(
83
				'type' => 'button',
84
				'value' => $this->msg( 'swl-group-add-group' )->text(),
85
				'id' => 'swl-add-group-button'
86
			)
87
		) . "</p>\n" );
88
89
		$wgOut->addHTML( "<p>" . Html::element(
90
			'input',
91
			array(
92
				'type' => 'button',
93
				'value' => $this->msg( 'swl-group-save' )->text(),
94
				'id' => 'swl-save-all'
95
			)
96
		) . "</p>\n" );
97
98
		$wgOut->addModules( 'ext.swl.watchlistconditions' );
99
	}
100
101
	/**
102
	 * Creates and returns the HTML for a single watchlist group.
103
	 *
104
	 * @since 0.1
105
	 *
106
	 * @param SWLGroup $group
107
	 *
108
	 * @return string
109
	 */
110
	protected function getGroupHtml( SWLGroup $group ) {
111
		$namespaces = $group->getNamespaces();
112
113
		foreach ( $namespaces as &$ns ) {
114
			$ns = $ns == 0 ? 'Main' : MWNamespace::getCanonicalName( $ns );
115
		}
116
117
		return Html::rawElement(
118
			'fieldset',
119
			array(
120
				'id' => 'swl_group_' . $group->getId(),
121
				'groupid' => $group->getId(),
122
				'class' => 'swl_group',
123
				'groupname' => $group->getName(),
124
				'categories' => implode( '|', $group->getCategories() ),
125
				'namespaces' => implode( '|', $namespaces ),
126
				'properties' => implode( '|', $group->getProperties() ),
127
				'concepts' => implode( '|', $group->getConcepts() ),
128
				'customTexts' => implode( '|', $group->getSerializedCustomTexts() ),
129
			),
130
			Html::element(
131
				'legend',
132
				array(),
133
				$this->msg( 'swl-group-legend' )->text()
134
			)
135
		);
136
	}
137
138
}
139