Issues (23)

Security Analysis    no request data  

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.

src/Setup.php (14 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 SubPageList;
4
5
use Parser;
6
use RecursiveDirectoryIterator;
7
use RecursiveIteratorIterator;
8
use Revision;
9
use SplFileInfo;
10
use Title;
11
use User;
12
use WikiPage;
13
14
/**
15
 * Object containing the logic to set up the SupPageList extension.
16
 *
17
 * @since 1.0
18
 *
19
 * @licence GNU GPL v2+
20
 * @author Jeroen De Dauw < [email protected] >
21
 */
22
class Setup {
23
24
	/**
25
	 * @var Extension
26
	 */
27
	private $extension;
28
29
	/**
30
	 * @var array[]
31
	 */
32
	private $hooks;
33
34
	/**
35
	 * @var string
36
	 */
37
	private $rootDirectory;
38
39
	/**
40
	 * @param Extension $extension
41
	 * @param array $hooks
42
	 * @param string $rootDirectory
43
	 */
44 1
	public function __construct( Extension $extension, array &$hooks, $rootDirectory ) {
45 1
		$this->hooks =& $hooks;
46 1
		$this->extension = $extension;
47 1
		$this->rootDirectory = $rootDirectory;
48 1
	}
49
50
	/**
51
	 * Sets up the SubPageList extension.
52
	 *
53
	 * @since 1.0
54
	 */
55 1
	public function run() {
56 1
		$this->registerParserHooks();
57 1
		$this->registerCacheInvalidator();
58 1
		$this->registerUnitTests();
59 1
	}
60
61 24
	private function registerParserHooks() {
62 1
		$extension = $this->extension;
63
64
		/**
65
		 * Called when the parser initialises for the first time.
66
		 * https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
67
		 */
68 24
		$this->hooks['ParserFirstCallInit'][] = function( Parser &$parser ) use ( $extension ) {
69 24
			$hookRegistrant = $extension->getHookRegistrant( $parser );
70
71 24
			$hookRegistrant->registerFunctionHandler(
72 24
				$extension->getCountHookDefinition(),
73 24
				$extension->getCountHookHandler()
74
			);
75
76 24
			$hookRegistrant->registerFunctionHandler(
77 24
				$extension->getListHookDefinition(),
78 24
				$extension->getListHookHandler()
79
			);
80
81 24
			$hookRegistrant->registerHookHandler(
82 24
				$extension->getCountHookDefinition(),
83 24
				$extension->getCountHookHandler()
84
			);
85
86 24
			$hookRegistrant->registerHookHandler(
87 24
				$extension->getListHookDefinition(),
88 24
				$extension->getListHookHandler()
89
			);
90
91 24
			return true;
92
		};
93 1
	}
94
95 4
	private function registerCacheInvalidator() {
96 1
		$extension = $this->extension;
97
98
		/**
99
		 * Occurs after a new article has been created.
100
		 * https://www.mediawiki.org/wiki/Manual:Hooks/ArticleInsertComplete
101
		 */
102 1
		$this->hooks['ArticleInsertComplete'][]
103
			= function( WikiPage $article, User &$user, $text, $summary, $minorEdit,
0 ignored issues
show
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $text is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $summary is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $minorEdit is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104
			$watchThis, $sectionAnchor, &$flags, Revision $revision ) use ( $extension ) {
0 ignored issues
show
The parameter $watchThis is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $sectionAnchor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $flags is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $revision is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
106
			if ( $extension->getSettings()->get( Settings::AUTO_REFRESH ) ) {
107
				$extension->getCacheInvalidator()->invalidateCaches( $article->getTitle() );
108
			}
109
110
			return true;
111
		};
112
113
		/**
114
		 * Occurs after the delete article request has been processed.
115
		 * https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDeleteComplete
116
		 */
117 4
		$this->hooks['ArticleDeleteComplete'][] = function( &$article, User &$user, $reason, $id ) use ( $extension ) {
0 ignored issues
show
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $reason is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
118 4
			if ( $extension->getSettings()->get( Settings::AUTO_REFRESH ) ) {
119
				$extension->getCacheInvalidator()->invalidateCaches( $article->getTitle() );
120
			}
121
122 4
			return true;
123
		};
124
125
		/**
126
		 * Occurs whenever a request to move an article is completed.
127
		 * https://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete
128
		 */
129
		$this->hooks['TitleMoveComplete'][] = function( Title &$title, Title &$newTitle, User &$user, $oldId, $newId ) use ( $extension ) {
0 ignored issues
show
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $oldId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $newId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
			if ( $extension->getSettings()->get( Settings::AUTO_REFRESH ) ) {
131
				$invalidator = $extension->getCacheInvalidator();
132
133
				$invalidator->invalidateCaches( $title );
134
				$invalidator->invalidateCaches( $newTitle );
135
			}
136
137
			return true;
138
		};
139 1
	}
140
141 1
	private function registerUnitTests() {
142 1
		$rootDirectory = $this->rootDirectory;
143
144
		/**
145
		 * Hook to add PHPUnit test cases.
146
		 * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
147
		 *
148
		 * @since 1.0
149
		 *
150
		 * @param array $files
151
		 *
152
		 * @return boolean
153
		 */
154
		$this->hooks['UnitTestsList'][]	= function( array &$files ) use ( $rootDirectory ) {
155
			$directoryIterator = new RecursiveDirectoryIterator( $rootDirectory . '/tests/' );
156
157
			/**
158
			 * @var SplFileInfo $fileInfo
159
			 */
160
			foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
161
				if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
162
					$files[] = $fileInfo->getPathname();
163
				}
164
			}
165
166
			return true;
167
		};
168 1
	}
169
170
}
171