Completed
Push — master ( 3c2e58...240e91 )
by mw
16s
created

ConceptPage::getCacheInformation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 14
cp 0
rs 9.4285
cc 3
eloc 14
nc 2
nop 0
crap 12
1
<?php
2
3
namespace SMW;
4
5
use Html;
6
use SMW\Query\Language\ConceptDescription;
7
use SMWPageLister;
8
9
/**
10
 * Special handling for relation/attribute description pages.
11
 * Some code based on CategoryPage.php
12
 *
13
 * Indicate class aliases in a way PHPStorm and Eclipse understand.
14
 * This is purely an IDE helper file, and is not loaded by the extension.
15
 *
16
 * @since 1.9
17
 *
18
 * @ingroup SMW
19
 *
20
 * @license GNU GPL v2+
21
 * @author: Markus Krötzsch
22
 * @author: mwjames
23
 */
24
25
/**
26
 * Implementation of MediaWiki's Article that shows additional information on
27
 * Concept: pages. Very similar to CategoryPage.
28
 * @ingroup SMW
29
 */
30
class ConceptPage extends \SMWOrderedListPage {
31
32
	/**
33
	 * Initialize parameters to use a higher limit. This operation is very
34
	 * similar to showing members of categories.
35
	 */
36
	protected function initParameters() {
37
		global $smwgConceptPagingLimit;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
38
		$this->limit = $smwgConceptPagingLimit;
39
		return true;
40
	}
41
42
	/**
43
	 * Returns the HTML which is added to $wgOut after the article text.
44
	 *
45
	 * @return string
46
	 */
47
	protected function getHtml() {
48
49
		if ( $this->limit > 0 ) { // limit==0: configuration setting to disable this completely
50
			$description = new ConceptDescription( $this->getDataItem() );
51
			$query = SMWPageLister::getQuery( $description, $this->limit, $this->from, $this->until );
0 ignored issues
show
Documentation introduced by
$description is of type object<SMW\Query\Language\ConceptDescription>, but the function expects a object<SMWDescription>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
			$queryResult = ApplicationFactory::getInstance()->getStore()->getQueryResult( $query );
53
54
			$diWikiPages = $queryResult->getResults();
55
			if ( $this->until !== '' ) {
56
				$diWikiPages = array_reverse( $diWikiPages );
57
			}
58
59
			$errors = $queryResult->getErrors();
60
		} else {
61
			$diWikiPages = array();
62
			$errors = array();
63
		}
64
65
		$pageLister = new SMWPageLister( $diWikiPages, null, $this->limit, $this->from, $this->until );
66
		$this->mTitle->setFragment( '#SMWResults' ); // Make navigation point to the result list.
67
		$navigation = $pageLister->getNavigationLinks( $this->mTitle );
68
69
		$titleText = htmlspecialchars( $this->mTitle->getText() );
70
		$resultNumber = min( $this->limit, count( $diWikiPages ) );
71
72
		return Html::element( 'br', array( 'id' => 'smwfootbr' ) ) .
73
			Html::element( 'a', array( 'name' => 'SMWResults' ), null ) .
74
			Html::rawElement( 'div', array( 'id' => 'mw-pages'),
75
				$this->getCacheInformation() .
76
				Html::rawElement( 'h2', array(), $this->getContext()->msg( 'smw_concept_header', $titleText )->text() ) .
77
				Html::element( 'span', array(), $this->getContext()->msg( 'smw_conceptarticlecount', $resultNumber )->parse() ) .
78
				smwfEncodeMessages( $errors ) . ' '. $navigation .
79
				$pageLister->formatList()
80
			);
81
	}
82
83
	private function getCacheInformation() {
84
85
		$concept = ApplicationFactory::getInstance()->getStore()->getConceptCacheStatus( $this->getDataItem() );
86
		$cacheInformation = wfMessage( 'smw-concept-no-cache' )->text();
87
88
		if ( $concept instanceof DIConcept && $concept->getCacheStatus() === 'full' ) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $concept->getCacheStatus() (integer) and 'full' (string) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
89
			$cacheInformation = wfMessage(
90
				'smw-concept-cache-count',
91
				$this->getContext()->getLanguage()->formatNum( $concept->getCacheCount() ),
92
				$this->getContext()->getLanguage()->timeanddate( $concept->getCacheDate() )
93
			)->parse();
94
		}
95
96
		return Html::rawElement(
97
			'h2',
98
			array(),
99
			$this->getContext()->msg( 'smw-concept-cache-header' )->text()
100
		) . $cacheInformation;
101
	}
102
103
}
104