MediaWiki  master
MediaWiki\Shell\Command Class Reference

Class used for executing shell commands. More...

Inheritance diagram for MediaWiki\Shell\Command:
Collaboration diagram for MediaWiki\Shell\Command:

Public Member Functions

 __construct (UnboxedExecutor $executor)
 Don't call directly, instead use Shell::command() More...
 
 __destruct ()
 Makes sure the programmer didn't forget to execute the command after all. More...
 
 __toString ()
 Returns the final command line before environment/limiting, etc are applied. More...
 
 cgroup ( $cgroup)
 Sets cgroup for this command. More...
 
 execute ()
 Executes command. More...
 
 input (string $inputString)
 Sends the provided input to the command. More...
 
 limits (array $limits)
 Sets execution limits. More...
 
 profileMethod (string $method)
 Sets calling function for profiler. More...
 
 restrict (int $restrictions)
 Set restrictions for this request, overwriting any previously set restrictions. More...
 
 setLogger (LoggerInterface $logger)
 
 whitelistPaths (array $paths)
 If called, only the files/directories that are whitelisted will be available to the shell command. More...
 

Protected Attributes

LoggerInterface $logger
 

Private Attributes

bool $everExecuted = false
 
string $method
 

Detailed Description

Class used for executing shell commands.

Since
1.30

Definition at line 39 of file Command.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Shell\Command::__construct ( UnboxedExecutor  $executor)

Don't call directly, instead use Shell::command()

Parameters
UnboxedExecutor$executor
Exceptions
ShellDisabledError

Definition at line 55 of file Command.php.

References MediaWiki\Shell\Shell\isDisabled(), and MediaWiki\Shell\Command\setLogger().

◆ __destruct()

MediaWiki\Shell\Command::__destruct ( )

Makes sure the programmer didn't forget to execute the command after all.

Definition at line 66 of file Command.php.

References MediaWiki\$context, and MediaWiki\Shell\Command\$method.

Member Function Documentation

◆ __toString()

MediaWiki\Shell\Command::__toString ( )

Returns the final command line before environment/limiting, etc are applied.

Use string conversion only for debugging, don't try to pass this to some other execution medium.

Returns
string

Definition at line 239 of file Command.php.

◆ cgroup()

MediaWiki\Shell\Command::cgroup (   $cgroup)

Sets cgroup for this command.

Has no effect since MW 1.36. This setting is injected into the executor from CommandFactory instead.

Deprecated:
since 1.36
Parameters
string | false$cgroupAbsolute file path to the cgroup, or false to not use a cgroup
Returns
$this

Definition at line 147 of file Command.php.

References wfDeprecated().

◆ execute()

MediaWiki\Shell\Command::execute ( )

Executes command.

Afterwards, getExitCode() and getOutput() can be used to access execution results.

Returns
UnboxedResult
Exceptions
Exception
ProcOpenError
ShellDisabledError

Definition at line 223 of file Command.php.

References Profiler\instance(), and wfGetCaller().

◆ input()

MediaWiki\Shell\Command::input ( string  $inputString)

Sends the provided input to the command.

Defaults to an empty string. If you want to pass stdin through to the command instead, use passStdin().

Parameters
string$inputString
Returns
$this

Definition at line 135 of file Command.php.

◆ limits()

MediaWiki\Shell\Command::limits ( array  $limits)

Sets execution limits.

Parameters
array$limitsAssociative array of limits. Keys (all optional): filesize (for ulimit -f), memory, time, walltime.
Returns
$this

Definition at line 93 of file Command.php.

◆ profileMethod()

MediaWiki\Shell\Command::profileMethod ( string  $method)

Sets calling function for profiler.

By default, the caller for execute() will be used.

Parameters
string$method
Returns
$this

Definition at line 121 of file Command.php.

References MediaWiki\Shell\Command\$method.

◆ restrict()

MediaWiki\Shell\Command::restrict ( int  $restrictions)

Set restrictions for this request, overwriting any previously set restrictions.

Add the "no network" restriction:

Allow LocalSettings.php access:

Disable all restrictions:

Deprecated:
since 1.36 Set the options using their separate accessors
Since
1.31
Parameters
int$restrictions
Returns
$this

Definition at line 176 of file Command.php.

References MediaWiki\Shell\Shell\NO_EXECVE, MediaWiki\Shell\Shell\NO_LOCALSETTINGS, MediaWiki\Shell\Shell\NO_NETWORK, MediaWiki\Shell\Shell\NO_ROOT, MediaWiki\Shell\Shell\PRIVATE_DEV, and MediaWiki\Shell\Shell\SECCOMP.

◆ setLogger()

MediaWiki\Shell\Command::setLogger ( LoggerInterface  $logger)

Definition at line 79 of file Command.php.

References MediaWiki\Shell\Command\$logger.

Referenced by MediaWiki\Shell\Command\__construct().

◆ whitelistPaths()

MediaWiki\Shell\Command::whitelistPaths ( array  $paths)

If called, only the files/directories that are whitelisted will be available to the shell command.

limit.sh will always be whitelisted

Deprecated:
since 1.36 Use allowPath/disallowPath
Parameters
string[]$paths
Returns
$this

Definition at line 209 of file Command.php.

Member Data Documentation

◆ $everExecuted

bool MediaWiki\Shell\Command::$everExecuted = false
private

Definition at line 41 of file Command.php.

◆ $logger

LoggerInterface MediaWiki\Shell\Command::$logger
protected

Definition at line 47 of file Command.php.

Referenced by MediaWiki\Shell\Command\setLogger().

◆ $method

string MediaWiki\Shell\Command::$method
private

The documentation for this class was generated from the following file:
MediaWiki\Shell\Shell\RESTRICT_DEFAULT
const RESTRICT_DEFAULT
Apply a default set of restrictions for improved security out of the box.
Definition: Shell.php:101
$command
$command
Definition: mcc.php:125
MediaWiki\Shell\Shell\NO_NETWORK
const NO_NETWORK
Restrict the request to have no network access.
Definition: Shell.php:76
MediaWiki\Shell\Shell\RESTRICT_NONE
const RESTRICT_NONE
Don't apply any restrictions.
Definition: Shell.php:109
MediaWiki\Shell\Shell\NO_LOCALSETTINGS
const NO_LOCALSETTINGS
Deny access to LocalSettings.php (MW_CONFIG_FILE)
Definition: Shell.php:91