Issues (4122)

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.

maintenance/deleteBatch.php (4 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 38 and the first side effect is on line 31.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Deletes a batch of pages.
4
 * Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] [listfile]
5
 * where
6
 *   [listfile] is a file where each line contains the title of a page to be
7
 *     deleted, standard input is used if listfile is not given.
8
 *   <user> is the username
9
 *   <reason> is the delete reason
10
 *   <interval> is the number of seconds to sleep for after each delete
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License along
23
 * with this program; if not, write to the Free Software Foundation, Inc.,
24
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
 * http://www.gnu.org/copyleft/gpl.html
26
 *
27
 * @file
28
 * @ingroup Maintenance
29
 */
30
31
require_once __DIR__ . '/Maintenance.php';
32
33
/**
34
 * Maintenance script to delete a batch of pages.
35
 *
36
 * @ingroup Maintenance
37
 */
38
class DeleteBatch extends Maintenance {
39
40 View Code Duplication
	public function __construct() {
41
		parent::__construct();
42
		$this->addDescription( 'Deletes a batch of pages' );
43
		$this->addOption( 'u', "User to perform deletion", false, true );
44
		$this->addOption( 'r', "Reason to delete page", false, true );
45
		$this->addOption( 'i', "Interval to sleep between deletions" );
46
		$this->addArg( 'listfile', 'File with titles to delete, separated by newlines. ' .
47
			'If not given, stdin will be used.', false );
48
	}
49
50
	public function execute() {
51
		global $wgUser;
52
53
		# Change to current working directory
54
		$oldCwd = getcwd();
55
		chdir( $oldCwd );
56
57
		# Options processing
58
		$username = $this->getOption( 'u', false );
59
		$reason = $this->getOption( 'r', '' );
60
		$interval = $this->getOption( 'i', 0 );
61
62 View Code Duplication
		if ( $username === false ) {
63
			$user = User::newSystemUser( 'Delete page script', [ 'steal' => true ] );
64
		} else {
65
			$user = User::newFromName( $username );
66
		}
67
		if ( !$user ) {
68
			$this->error( "Invalid username", true );
69
		}
70
		$wgUser = $user;
71
72
		if ( $this->hasArg() ) {
73
			$file = fopen( $this->getArg(), 'r' );
74
		} else {
75
			$file = $this->getStdin();
76
		}
77
78
		# Setup
79
		if ( !$file ) {
80
			$this->error( "Unable to read file, exiting", true );
81
		}
82
83
		$dbw = $this->getDB( DB_MASTER );
0 ignored issues
show
$dbw 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...
84
85
		# Handle each entry
86
		// @codingStandardsIgnoreStart Ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
87
		for ( $linenum = 1; !feof( $file ); $linenum++ ) {
88
			// @codingStandardsIgnoreEnd
89
			$line = trim( fgets( $file ) );
90
			if ( $line == '' ) {
91
				continue;
92
			}
93
			$title = Title::newFromText( $line );
94
			if ( is_null( $title ) ) {
95
				$this->output( "Invalid title '$line' on line $linenum\n" );
96
				continue;
97
			}
98
			if ( !$title->exists() ) {
99
				$this->output( "Skipping nonexistent page '$line'\n" );
100
				continue;
101
			}
102
103
			$this->output( $title->getPrefixedText() );
104
			if ( $title->getNamespace() == NS_FILE ) {
105
				$img = wfFindFile( $title, [ 'ignoreRedirect' => true ] );
106
				if ( $img && $img->isLocal() && !$img->delete( $reason ) ) {
107
					$this->output( " FAILED to delete associated file... " );
108
				}
109
			}
110
			$page = WikiPage::factory( $title );
111
			$error = '';
112
			$success = $page->doDeleteArticle( $reason, false, 0, true, $error, $user );
0 ignored issues
show
It seems like $user defined by \User::newFromName($username) on line 65 can also be of type false; however, WikiPage::doDeleteArticle() does only seem to accept null|object<User>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
113
			if ( $success ) {
114
				$this->output( " Deleted!\n" );
115
			} else {
116
				$this->output( " FAILED to delete article\n" );
117
			}
118
119
			if ( $interval ) {
120
				sleep( $interval );
121
			}
122
			wfWaitForSlaves();
0 ignored issues
show
Deprecated Code introduced by
The function wfWaitForSlaves() has been deprecated with message: since 1.27 Use LBFactory::waitForReplication

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
123
		}
124
	}
125
}
126
127
$maintClass = "DeleteBatch";
128
require_once RUN_MAINTENANCE_IF_MAIN;
129