Merge "parser: Validate $length in padleft/padright parser functions"
[lhc/web/wiklou.git] / includes / SiteConfiguration.php
index 5b9bdfa..8e77956 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\Shell\Shell;
+
 /**
  * This is a class for holding configuration settings, particularly for
  * multi-wiki sites.
  *
  * @code
  * $conf = new SiteConfiguration;
- * $conf->wikis = array( 'de', 'en', 'beta' );
+ * $conf->wikis = [ 'de', 'en', 'beta' ];
  * @endcode
  *
  * When configuring the MediaWiki global settings (the $wg variables),
  * the identifiers will be available to specify settings on a per wiki basis.
  *
  * @code
- * $conf->settings = array(
- *     'wgSomeSetting' => array(
+ * $conf->settings = [
+ *     'wgSomeSetting' => [
  *
  *             # production:
  *             'de'     => false,
@@ -52,8 +54,8 @@
  *
  *             # test:
  *             'beta    => true,
- *     ),
- * );
+ *     ],
+ * ];
  * @endcode
  *
  * With three wikis, that is easy to manage. But what about a farm with
  * the above code could be written:
  *
  * @code
- * $conf->settings = array(
- *     'wgSomeSetting' => array(
+ * $conf->settings = [
+ *     'wgSomeSetting' => [
  *
  *             'default' => false,
  *
  *             # Enable feature on test
  *             'beta'    => true,
- *     ),
- * );
+ *     ],
+ * ];
  * @endcode
  *
  *
  * on a per wiki basis.
  *
  * @code
- * $conf->settings = array(
- *     'wgMergeSetting' = array(
+ * $conf->settings = [
+ *     'wgMergeSetting' = [
  *             # Value that will be shared among all wikis:
- *             'default' => array( NS_USER => true ),
+ *             'default' => [ NS_USER => true ],
  *
  *             # Leading '+' means merging the array of value with the defaults
- *             '+beta' => array( NS_HELP => true ),
- *     ),
- * );
+ *             '+beta' => [ NS_HELP => true ],
+ *     ],
+ * ];
  *
  * # Get configuration for the German site:
  * $conf->get( 'wgMergeSetting', 'de' );
- * // --> array( NS_USER => true );
+ * // --> [ NS_USER => true ];
  *
  * # Get configuration for the testing site:
  * $conf->get( 'wgMergeSetting', 'beta' );
- * // --> array( NS_USER => true, NS_HELP => true );
+ * // --> [ NS_USER => true, NS_HELP => true ];
  * @endcode
  *
  * Finally, to load all configuration settings, extract them in global context:
  * extract( $globals );
  * @endcode
  *
+ * @note For WikiMap to function, the configuration must define string values for
+ *  $wgServer (or $wgCanonicalServer) and $wgArticlePath, even if these are the
+ *  same for all wikis or can be correctly determined by the logic in
+ *  Setup.php.
+ *
  * @todo Give examples for,
  * suffixes:
- * $conf->suffixes = array( 'wiki' );
+ * $conf->suffixes = [ 'wiki' ];
  * localVHosts
  * callbacks!
  */
@@ -269,7 +276,7 @@ class SiteConfiguration {
         * @param string $from
         * @param string $to
         * @param string|array $in
-        * @return string
+        * @return string|array
         */
        function doReplace( $from, $to, $in ) {
                if ( is_string( $in ) ) {
@@ -340,7 +347,7 @@ class SiteConfiguration {
         * @param string $setting ID of the setting name to retrieve
         * @param string $wiki Wiki ID of the wiki in question.
         * @param string $suffix The suffix of the wiki in question.
-        * @param array $var Reference The variable to insert the value into.
+        * @param array &$var Reference The variable to insert the value into.
         * @param array $params List of parameters. $.'key' is replaced by $value in all returned data.
         * @param array $wikiTags The tags assigned to the wiki.
         */
@@ -425,7 +432,7 @@ class SiteConfiguration {
                        return $default;
                }
 
-               $ret = call_user_func_array( $this->siteParamsCallback, [ $this, $wiki ] );
+               $ret = ( $this->siteParamsCallback )( $this, $wiki );
                # Validate the returned value
                if ( !is_array( $ret ) ) {
                        return $default;
@@ -541,19 +548,21 @@ class SiteConfiguration {
                        } else {
                                $this->cfgCache[$wiki] = [];
                        }
-                       $retVal = 1;
-                       $cmd = wfShellWikiCmd(
+                       $result = Shell::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 ] ) );
-                       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 ) ) {
@@ -597,7 +606,7 @@ class SiteConfiguration {
 
        public function loadFullData() {
                if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
-                       call_user_func( $this->fullLoadCallback, $this );
+                       ( $this->fullLoadCallback )( $this );
                        $this->fullLoadDone = true;
                }
        }