Completed
Push — master ( 3abc67...80e892 )
by mw
207:38 queued 172:37
created

includes/articlepages/ConceptPage.php (1 issue)

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
namespace SMW;
4
5
use Html;
6
use SMW\MediaWiki\ByLanguageCollationMapper;
7
use SMW\Query\Language\ConceptDescription;
8
use SMWDataItem as DataItem;
9
use SMWPageLister;
10
11
/**
12
 * Special handling for relation/attribute description pages.
13
 * Some code based on CategoryPage.php
14
 *
15
 * Indicate class aliases in a way PHPStorm and Eclipse understand.
16
 * This is purely an IDE helper file, and is not loaded by the extension.
17
 *
18
 * @since 1.9
19
 *
20
 * @ingroup SMW
21
 *
22
 * @license GNU GPL v2+
23
 * @author: Markus Krötzsch
24
 * @author: mwjames
25
 */
26
27
/**
28
 * Implementation of MediaWiki's Article that shows additional information on
29
 * Concept: pages. Very similar to CategoryPage.
30
 * @ingroup SMW
31
 */
32
class ConceptPage extends \SMWOrderedListPage {
33
34
	/**
35
	 * Initialize parameters to use a higher limit. This operation is very
36
	 * similar to showing members of categories.
37
	 */
38
	protected function initParameters() {
39
		global $smwgConceptPagingLimit;
40
		$this->limit = $smwgConceptPagingLimit;
41
		return true;
42
	}
43
44
	/**
45
	 * Returns the HTML which is added to $wgOut after the article text.
46
	 *
47
	 * @return string
48
	 */
49
	protected function getHtml() {
50
		global $smwgConceptPagingLimit, $wgRequest;
51
52
		if ( $this->limit > 0 ) { // limit==0: configuration setting to disable this completely
53
			$description = new ConceptDescription( $this->getDataItem() );
54
			$query = SMWPageLister::getQuery( $description, $this->limit, $this->from, $this->until );
0 ignored issues
show
$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...
55
56
			$query->setLimit( $wgRequest->getVal( 'limit', $smwgConceptPagingLimit ) );
57
			$query->setOffset( $wgRequest->getVal( 'offset', '0' ) );
58
			$query->setContextPage( $this->getDataItem() );
59
60
			$queryResult = ApplicationFactory::getInstance()->getStore()->getQueryResult( $query );
61
62
			$diWikiPages = $queryResult->getResults();
63
			if ( $this->until !== '' ) {
64
				$diWikiPages = array_reverse( $diWikiPages );
65
			}
66
67
			$errors = $queryResult->getErrors();
68
		} else {
69
			$diWikiPages = array();
70
			$errors = array();
71
		}
72
73
		$pageLister = new SMWPageLister( $diWikiPages, null, $this->limit, $this->from, $this->until );
74
		$this->mTitle->setFragment( '#SMWResults' ); // Make navigation point to the result list.
75
76
		$titleText = htmlspecialchars( $this->mTitle->getText() );
77
78
		return Html::element( 'br', array( 'id' => 'smwfootbr' ) ) .
79
			Html::element( 'a', array( 'name' => 'SMWResults' ), null ) .
80
			Html::rawElement( 'div', array( 'id' => 'mw-pages'),
81
				$this->getCacheInformation() .
82
				Html::rawElement( 'h2', array(), $this->getContext()->msg( 'smw_concept_header', $titleText )->text() ) .
83
				$this->getNavigationLinks( 'smw_conceptarticlecount', $diWikiPages, $smwgConceptPagingLimit ) .
84
				smwfEncodeMessages( $errors ) . ' ' .
85
				$this->getFormattedColumns( $diWikiPages )
86
			);
87
	}
88
89
	private function getCacheInformation() {
90
91
		$concept = ApplicationFactory::getInstance()->getStore()->getConceptCacheStatus( $this->getDataItem() );
92
		$cacheInformation = wfMessage( 'smw-concept-no-cache' )->text();
93
94
		if ( $concept instanceof DIConcept && $concept->getCacheStatus() === 'full' ) {
95
			$cacheInformation = wfMessage(
96
				'smw-concept-cache-count',
97
				$this->getContext()->getLanguage()->formatNum( $concept->getCacheCount() ),
98
				$this->getContext()->getLanguage()->timeanddate( $concept->getCacheDate() )
99
			)->parse();
100
		}
101
102
		return Html::rawElement(
103
			'h2',
104
			array(),
105
			$this->getContext()->msg( 'smw-concept-cache-header' )->text()
106
		) . Html::rawElement(
107
			'span',
108
			array( 'class' => 'plainlinks' ),
109
			$cacheInformation
110
		);
111
	}
112
113
	private function getFormattedColumns( array $diWikiPages ) {
114
115
		if ( $diWikiPages === array() ) {
116
			return '';
117
		}
118
119
		$mwCollaboratorFactory = ApplicationFactory::getInstance()->newMwCollaboratorFactory();
120
		$htmlColumnListRenderer = $mwCollaboratorFactory->newHtmlColumnListRenderer();
121
122
		foreach ( $diWikiPages as $value ) {
123
			$dv = DataValueFactory::getInstance()->newDataValueByItem( $value );
124
			$contentsByIndex[$this->getFirstLetterForCategory( $value )][] = $dv->getLongHTMLText( smwfGetLinker() );
125
		}
126
127
		$htmlColumnListRenderer->setColumnRTLDirectionalityState(
128
			$this->getContext()->getLanguage()->isRTL()
129
		);
130
131
		$htmlColumnListRenderer->setColumnClass( 'smw-column-responsive' );
132
		$htmlColumnListRenderer->setNumberOfColumns( 1 );
133
		$htmlColumnListRenderer->addContentsByIndex( $contentsByIndex );
134
135
		return $htmlColumnListRenderer->getHtml();
136
	}
137
138
	private function getFirstLetterForCategory( DataItem $dataItem ) {
139
140
		$sortKey = $dataItem->getSortKey();
141
142
		if ( $dataItem->getDIType() == DataItem::TYPE_WIKIPAGE ) {
143
			$sortKey = ApplicationFactory::getInstance()->getStore()->getWikiPageSortKey( $dataItem );
144
145
		}
146
147
		return ByLanguageCollationMapper::getInstance()->findFirstLetterForCategory( $sortKey );
148
	}
149
150
}
151