Mailing List Archive

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Deprecate wfShellWikiCmd()
MaxSem has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/405974 )

Change subject: Deprecate wfShellWikiCmd()
......................................................................

Deprecate wfShellWikiCmd()

Bug: T184339

Change-Id: Ic86a451e0e9d609e06865a4969560d151efa844c
---
M RELEASE-NOTES-1.31
M includes/GlobalFunctions.php
M includes/SiteConfiguration.php
M includes/specialpage/LoginSignupSpecialPage.php
M maintenance/Maintenance.php
M tests/phpunit/maintenance/MaintenanceTest.php
6 files changed, 114 insertions(+), 8 deletions(-)


git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/74/405974/1

diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31
index 5e14aee..629321b 100644
--- a/RELEASE-NOTES-1.31
+++ b/RELEASE-NOTES-1.31
@@ -186,6 +186,7 @@
* The driver 'mysql' for MySQL, deprecated in MediaWiki 1.30, has been removed.
The driver has been deprecated since PHP 5.5 and was removed in PHP 7.0. The
default driver for MySQL has been 'mysqli' since MediaWiki 1.22.
+* The function wfShellWikiCmd() has been deprecated, use Maintenance::makeScriptCommand().

== Compatibility ==
MediaWiki 1.31 requires PHP 5.5.9 or later. Although HHVM 3.18.5 or later is supported,
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index a06d721..d6ace5a 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -2375,6 +2375,8 @@
* Note that $parameters should be a flat array and an option with an argument
* should consist of two consecutive items in the array (do not use "--option value").
*
+ * @deprecated since 1.31, use Maintenance::executeMaintenanceScript()
+ *
* @param string $script MediaWiki cli script path
* @param array $parameters Arguments and options to the script
* @param array $options Associative array of options:
diff --git a/includes/SiteConfiguration.php b/includes/SiteConfiguration.php
index 2d1d961..93f26f4 100644
--- a/includes/SiteConfiguration.php
+++ b/includes/SiteConfiguration.php
@@ -546,19 +546,21 @@
} else {
$this->cfgCache[$wiki] = [];
}
- $retVal = 1;
- $cmd = wfShellWikiCmd(
+ $result = Maintenance::makeScriptCommand(
"$IP/maintenance/getConfiguration.php",
[.
'--wiki', $wiki,
'--settings', implode( ' ', $settings ),
- '--format', 'PHP'
+ '--format', 'PHP',
]
- );
- // ulimit5.sh breaks this call
- $data = trim( wfShellExec( $cmd, $retVal, [], [ 'memory' => 0, 'filesize' => 0 ] ) );
- if ( $retVal != 0 || !strlen( $data ) ) {
- throw new MWException( "Failed to run getConfiguration.php." );
+ )
+ // limit.sh breaks this call
+ ->limits( [ 'memory' => 0, 'filesize' => 0 ] )
+ ->execute();
+
+ $data = trim( $result->getStdout() );
+ if ( $result->getExitCode() != 0 || !strlen( $data ) ) {
+ throw new MWException( "Failed to run getConfiguration.php: {$result->getStdout()}" );
}
$res = unserialize( $data );
if ( !is_array( $res ) ) {
diff --git a/includes/specialpage/LoginSignupSpecialPage.php b/includes/specialpage/LoginSignupSpecialPage.php
index d6ace0a..f1f422d 100644
--- a/includes/specialpage/LoginSignupSpecialPage.php
+++ b/includes/specialpage/LoginSignupSpecialPage.php
@@ -735,6 +735,7 @@

$titleObj = $this->getPageTitle();
$user = $this->getUser();
+ $this->getConfig();
$template = new FakeAuthTemplate();

// Pre-fill username (if not creating an account, T46775).
diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php
index 5adbee5..ef2edde 100644
--- a/maintenance/Maintenance.php
+++ b/maintenance/Maintenance.php
@@ -25,6 +25,8 @@
require_once __DIR__ . '/../includes/PHPVersionCheck.php';
wfEntryPointCheck( 'cli' );

+use MediaWiki\Shell\Command;
+use MediaWiki\Shell\Shell;
use Wikimedia\Rdbms\DBReplicationWaitError;

/**
@@ -670,6 +672,34 @@
}

/**
+ * Generate a Command object to run a MediaWiki CLI script.
+ * Note that $parameters should be a flat array and an option with an argument
+ * should consist of two consecutive items in the array (do not use "--option value").
+ *
+ * @param string $script MediaWiki CLI script path
+ * @param string[] $parameters Arguments and options to the script
+ * @param array $options Associative array of options:
+ * 'php': The path to the php executable
+ * 'wrapper': Path to a PHP wrapper to handle the maintenance script
+ * @return Command
+ */
+ public static function makeScriptCommand( $script, $parameters, $options = [] ) {
+ global $wgPhpCli;
+ // Give site config file a chance to run the script in a wrapper.
+ // The caller may likely want to call wfBasename() on $script.
+ Hooks::run( 'wfShellWikiCmd', [ &$script, &$parameters, &$options ] );
+ $cmd = isset( $options['php'] ) ? [ $options['php'] ] : [ $wgPhpCli ];
+ if ( isset( $options['wrapper'] ) ) {
+ $cmd[] = $options['wrapper'];
+ }
+ $cmd[] = $script;
+
+ return Shell::command( $cmd )
+ ->params( $parameters )
+ ->restrict( Shell::RESTRICT_DEFAULT & ~Shell::NO_LOCALSETTINGS );
+ }
+
+ /**
* Do some sanity checking and basic setup
*/
public function setup() {
diff --git a/tests/phpunit/maintenance/MaintenanceTest.php b/tests/phpunit/maintenance/MaintenanceTest.php
index 141561f..928be7e 100644
--- a/tests/phpunit/maintenance/MaintenanceTest.php
+++ b/tests/phpunit/maintenance/MaintenanceTest.php
@@ -4,6 +4,8 @@

use Maintenance;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Command;
+use MediaWiki\Shell\Shell;
use Wikimedia\TestingAccessWrapper;

/**
@@ -533,4 +535,72 @@

$m2->cleanupChanneled();
}
+
+ /**
+ * @covers Maintenance::makeScriptCommand
+ * @dataProvider provideMakeScriptCommand
+ *
+ * @param string $expected
+ * @param string $script
+ * @param string[] $parameters
+ * @param string[] $options
+ * @param callable|null $hook
+ */
+ public function testMakeScriptCommand( $expected,
+ $script,
+ $parameters,
+ $options = [],
+ $hook = null
+ ) {
+ // Running tests under Vagrant involves MWMultiVersion that uses the below hook
+ $this->setMwGlobals( 'wgHooks', [] );
+
+ if ( $hook ) {
+ $this->setTemporaryHook( 'wfShellWikiCmd', $hook );
+ }
+
+ $command = Maintenance::makeScriptCommand( $script, $parameters, $options );
+ $command->params( 'safe' )
+ ->unsafeParams( 'unsafe' );
+
+ $this->assertType( Command::class, $command );
+
+ $wrapper = TestingAccessWrapper::newFromObject( $command );
+ $this->assertEquals( $expected, $wrapper->command );
+ $this->assertEquals( 0, $wrapper->restrictions & Shell::NO_LOCALSETTINGS );
+ }
+
+ public function provideMakeScriptCommand() {
+ global $wgPhpCli;
+
+ return [.
+ [.
+ "'$wgPhpCli' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe",
+ 'maintenance/foobar.php',
+ [ 'bar\'"baz' ],
+ ],
+ [.
+ "'$wgPhpCli' 'changed.php' '--wiki=somewiki' 'bar'\\''\"baz' 'safe' unsafe",
+ 'maintenance/foobar.php',
+ [ 'bar\'"baz' ],
+ [],
+ function ( &$script, array &$parameters ) {
+ $script = 'changed.php';
+ array_unshift( $parameters, '--wiki=somewiki' );
+ }
+ ],
+ [.
+ "'/bin/perl' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe",
+ 'maintenance/foobar.php',
+ [ 'bar\'"baz' ],
+ [ 'php' => '/bin/perl' ],
+ ],
+ [.
+ "'$wgPhpCli' 'foobinize' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe",
+ 'maintenance/foobar.php',
+ [ 'bar\'"baz' ],
+ [ 'wrapper' => 'foobinize' ],
+ ],
+ ];
+ }
}

--
To view, visit https://gerrit.wikimedia.org/r/405974
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic86a451e0e9d609e06865a4969560d151efa844c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MaxSem <maxsem.wiki@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits