X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2Fmwdoc-filter.php;h=89fc44bd6ec0c64ba6726197f01cff083cabc33c;hp=46c5a00c3e3afab90f42da0dcc4ad6cbdf13ff9d;hb=86d7bd86fa08db2dbf3651a656d8238a34703c4f;hpb=cf35ff756c89ca6d6e003b440076df5ebe7ccef7 diff --git a/maintenance/mwdoc-filter.php b/maintenance/mwdoc-filter.php index 46c5a00c3e..89fc44bd6e 100644 --- a/maintenance/mwdoc-filter.php +++ b/maintenance/mwdoc-filter.php @@ -38,80 +38,64 @@ * 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 ); - } +// Warning: Converting this to a Maintenance script may reduce performance. +if ( PHP_SAPI != 'cli' && PHP_SAPI != 'phpdbg' ) { + die( "This filter can only be run from the command line.\n" ); +} - public function execute() { - $source = file_get_contents( $this->getArg( 0 ) ); - $tokens = token_get_all( $source ); +$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; +$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; } - 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; + break; - case T_VARIABLE: - if ( $buffer !== null ) { - echo $buffer; - echo "$bufferType $content"; - $buffer = $bufferType = null; - } 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; + default: + if ( $buffer !== null ) { + $buffer .= $content; + } else { + echo $content; } - } + break; } } - -$maintClass = 'MWDocGenFilter'; -require_once RUN_MAINTENANCE_IF_MAIN;