Issues (2950)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

includes/articlepages/ConceptPage.php (7 issues)

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;
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...
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;
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...
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 );
0 ignored issues
show
$pageLister is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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' ) {
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...
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() );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$contentsByIndex was never initialized. Although not strictly required by PHP, it is generally a good practice to add $contentsByIndex = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
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 );
0 ignored issues
show
The variable $contentsByIndex does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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