Mattflaschen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351743 )

Change subject: Revert "Convert mwdoc-filter.php to Maintenance", rm 
wfShellWikiCmd
......................................................................

Revert "Convert mwdoc-filter.php to Maintenance", rm wfShellWikiCmd

Revert a58948d64 and instead remove wfShellWikiCmd and escape
shell arguments directly.

This should be fine since mwdoc-filter.php does not depend on per-wiki
state.

Change-Id: Id9c6ca84bab827675b71ca16bf688fd3f5c993a1
---
M autoload.php
M maintenance/mwdoc-filter.php
M maintenance/mwdocgen.php
3 files changed, 67 insertions(+), 77 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/43/351743/1

diff --git a/autoload.php b/autoload.php
index 06e863f..1141c39 100644
--- a/autoload.php
+++ b/autoload.php
@@ -786,7 +786,6 @@
        'MWCryptRand' => __DIR__ . '/includes/utils/MWCryptRand.php',
        'MWDebug' => __DIR__ . '/includes/debug/MWDebug.php',
        'MWDocGen' => __DIR__ . '/maintenance/mwdocgen.php',
-       'MWDocGenFilter' => __DIR__ . '/maintenance/mwdoc-filter.php',
        'MWException' => __DIR__ . '/includes/exception/MWException.php',
        'MWExceptionHandler' => __DIR__ . 
'/includes/exception/MWExceptionHandler.php',
        'MWExceptionRenderer' => __DIR__ . 
'/includes/exception/MWExceptionRenderer.php',
diff --git a/maintenance/mwdoc-filter.php b/maintenance/mwdoc-filter.php
index 46c5a00..176333f 100644
--- a/maintenance/mwdoc-filter.php
+++ b/maintenance/mwdoc-filter.php
@@ -38,80 +38,65 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-require_once __DIR__ . '/Maintenance.php';
 
-/**
- * Maintenance script that builds doxygen documentation.
- * @ingroup Maintenance
- */
-class MWDocGenFilter extends Maintenance {
-       public function __construct() {
-               parent::__construct();
-               $this->addDescription( 'Doxygen filter to fix member variable 
types in documentation. '
-                       . 'Used by mwdocgen.php'
-               );
-               $this->addArg( 'filename', 'PHP file to filter', true );
-       }
-
-       public function execute() {
-               $source = file_get_contents( $this->getArg( 0 ) );
-               $tokens = token_get_all( $source );
-
-               $buffer = $bufferType = null;
-               foreach ( $tokens as $token ) {
-                       if ( is_string( $token ) ) {
-                               if ( $buffer !== null && $token === ';' ) {
-                                       // If we still have a buffer and the 
statement has ended,
-                                       // flush it and move on.
-                                       echo $buffer;
-                                       $buffer = $bufferType = null;
-                               }
-                               echo $token;
-                               continue;
-                       }
-                       list( $id, $content ) = $token;
-                       switch ( $id ) {
-                               case T_DOC_COMMENT:
-                                       // Escape slashes so that references to 
namespaces are not
-                                       // wrongly interpreted as a Doxygen 
"\command".
-                                       $content = addcslashes( $content, '\\' 
);
-                                       // Look for instances of "@var Type" 
not followed by $name.
-                                       if ( preg_match( 
'#@var\s+([^\s]+)\s+([^\$]+)#s', $content ) ) {
-                                               $buffer = preg_replace_callback(
-                                                       // Strip the "@var 
Type" part and remember the type
-                                                       '#(@var\s+)([^\s]+)#s',
-                                                       function ( $matches ) 
use ( &$bufferType ) {
-                                                               $bufferType = 
$matches[2];
-                                                               return '';
-                                                       },
-                                                       $content
-                                               );
-                                       } else {
-                                               echo $content;
-                                       }
-                                       break;
-
-                               case T_VARIABLE:
-                                       if ( $buffer !== null ) {
-                                               echo $buffer;
-                                               echo "$bufferType $content";
-                                               $buffer = $bufferType = null;
-                                       } else {
-                                               echo $content;
-                                       }
-                                       break;
-
-                               default:
-                                       if ( $buffer !== null ) {
-                                               $buffer .= $content;
-                                       } else {
-                                               echo $content;
-                                       }
-                                       break;
-                       }
-               }
-       }
+// Warning: Converting this to a Maintenance script may reduce performance.
+if ( PHP_SAPI != 'cli' ) {
+       die( "This filter can only be run from the command line.\n" );
 }
 
-$maintClass = 'MWDocGenFilter';
-require_once RUN_MAINTENANCE_IF_MAIN;
+$source = file_get_contents( $argv[1] );
+$tokens = token_get_all( $source );
+
+$buffer = $bufferType = null;
+foreach ( $tokens as $token ) {
+       if ( is_string( $token ) ) {
+               if ( $buffer !== null && $token === ';' ) {
+                       // If we still have a buffer and the statement has 
ended,
+                       // flush it and move on.
+                       echo $buffer;
+                       $buffer = $bufferType = null;
+               }
+               echo $token;
+               continue;
+       }
+       list( $id, $content ) = $token;
+       switch ( $id ) {
+               case T_DOC_COMMENT:
+                       // Escape slashes so that references to namespaces are 
not
+                       // wrongly interpreted as a Doxygen "\command".
+                       $content = addcslashes( $content, '\\' );
+                       // Look for instances of "@var Type" not followed by 
$name.
+                       if ( preg_match( '#@var\s+([^\s]+)\s+([^\$]+)#s', 
$content ) ) {
+                               $buffer = preg_replace_callback(
+                                       // Strip the "@var Type" part and 
remember the type
+                                       '#(@var\s+)([^\s]+)#s',
+                                       function ( $matches ) use ( 
&$bufferType ) {
+                                               $bufferType = $matches[2];
+                                               return '';
+                                       },
+                                       $content
+                               );
+                       } else {
+                               echo $content;
+                       }
+                       break;
+
+               case T_VARIABLE:
+                       if ( $buffer !== null ) {
+                               echo $buffer;
+                               echo "$bufferType $content";
+                               $buffer = $bufferType = null;
+                       } else {
+                               echo $content;
+                       }
+                       break;
+
+               default:
+                       if ( $buffer !== null ) {
+                               $buffer .= $content;
+                       } else {
+                               echo $content;
+                       }
+                       break;
+       }
+}
diff --git a/maintenance/mwdocgen.php b/maintenance/mwdocgen.php
index dc2eccd..d005629 100644
--- a/maintenance/mwdocgen.php
+++ b/maintenance/mwdocgen.php
@@ -72,7 +72,7 @@
        }
 
        protected function init() {
-               global $IP;
+               global $wgPhpCli, $IP;
 
                $this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
                $this->mwVersion = $this->getOption( 'version', 'master' );
@@ -86,7 +86,13 @@
 
                $this->output = $this->getOption( 'output', "$IP/docs" );
 
-               $this->inputFilter = wfShellWikiCmd( $IP . 
'/maintenance/mwdoc-filter.php' );
+               // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
+               // a Maintenance script.
+               $this->inputFilter = wfEscapeShellArg( [
+                       $wgPhpCli,
+                       $IP . '/maintenance/mwdoc-filter.php'
+               ] );
+
                $this->template = $IP . '/maintenance/Doxyfile';
                $this->excludes = [
                        'vendor',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9c6ca84bab827675b71ca16bf688fd3f5c993a1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to