26 require_once __DIR__ .
'/Maintenance.php';
27 require_once __DIR__ .
'/../vendor/autoload.php';
33 private $currentFile =
null;
36 $retVal = parent::enterNode( $node );
37 $node->filename = $this->currentFile;
42 $this->currentFile = $filename;
46 return $this->currentFile;
55 private $currentClass =
null;
57 private $foundNodes = [];
61 foreach ( $this->foundNodes as &$nodes ) {
62 uasort( $nodes,
static function ( $a, $b ) {
63 return ( $a[
'filename'] . $a[
'name'] ) <=> ( $b[
'filename'] . $b[
'name'] );
66 ksort( $this->foundNodes );
67 return $this->foundNodes;
77 if ( !$node->stmts ) {
80 foreach ( $node->stmts as $stmt ) {
82 $stmt instanceof PhpParser\Node\Expr\FuncCall
83 && $stmt->name->toString() ===
'wfDeprecated'
92 $retVal = parent::enterNode( $node );
94 if ( $node instanceof PhpParser\Node\Stmt\ClassLike ) {
95 $this->currentClass = $node->name;
98 if ( $node instanceof PhpParser\Node\FunctionLike ) {
99 $docComment = $node->getDocComment();
100 if ( !$docComment ) {
103 if ( !preg_match(
'/@deprecated.*(\d+\.\d+)/', $docComment->getText(),
$matches ) ) {
108 if ( $node instanceof PhpParser\Node\Stmt\ClassMethod ) {
109 $name = $this->currentClass .
'::' . $node->name;
114 $this->foundNodes[ $version ][] = [
115 'filename' => $node->filename,
116 'line' => $node->getLine(),
132 parent::__construct();
142 $files =
new RecursiveDirectoryIterator(
$IP .
'/includes' );
143 $files =
new RecursiveIteratorIterator( $files );
144 $files =
new RegexIterator( $files,
'/\.php$/' );
145 return iterator_to_array( $files,
false );
152 $chunkSize = (int)ceil( count( $files ) / 72 );
154 $parser = (
new PhpParser\ParserFactory )->create( PhpParser\ParserFactory::PREFER_PHP7 );
155 $traverser =
new PhpParser\NodeTraverser;
157 $traverser->addVisitor( $finder );
159 $fileCount = count( $files );
161 for ( $i = 0; $i < $fileCount; $i++ ) {
163 $code = file_get_contents(
$file );
165 if ( strpos( $code,
'@deprecated' ) === -1 ) {
169 $finder->setCurrentFile( substr(
$file->getPathname(), strlen(
$IP ) + 1 ) );
170 $nodes = $parser->parse( $code );
171 $traverser->traverse( $nodes );
173 if ( $i % $chunkSize === 0 ) {
174 $percentDone = 100 * $i / $fileCount;
175 fprintf( STDERR,
"\r[%-72s] %d%%", str_repeat(
'#', $i / $chunkSize ), $percentDone );
179 fprintf( STDERR,
"\r[%'#-72s] 100%%\n",
'' );
183 $versionFmt =
"\n* Deprecated since \033[37;1m%s\033[0m:\n";
184 $entryFmt =
" %s \033[33;1m%s\033[0m (%s:%d)\n";
186 $versionFmt =
"\n* Deprecated since %s:\n";
187 $entryFmt =
" %s %s (%s:%d)\n";
190 foreach ( $finder->getFoundNodes() as $version => $nodes ) {
191 printf( $versionFmt, $version );
192 foreach ( $nodes as $node ) {
195 $node[
'hard'] ?
'+' :
'-',
202 printf(
"\nlegend:\n -: soft-deprecated\n +: hard-deprecated (via wfDeprecated())\n" );
207 require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined( 'MEDIAWIKI')) if(ini_get( 'mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
A PHPParser node visitor that finds deprecated functions and methods.
enterNode(PhpParser\Node $node)
isHardDeprecated(PhpParser\Node $node)
Check whether a function or method includes a call to wfDeprecated(), indicating that it is a hard-de...
A PHPParser node visitor that associates each node with its file name.
setCurrentFile( $filename)
enterNode(PhpParser\Node $node)
Maintenance task that recursively scans MediaWiki PHP files for deprecated functions and interfaces a...
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
static posix_isatty( $fd)
Wrapper for posix_isatty() We default as considering stdin a tty (for nice readline methods) but trea...
addDescription( $text)
Set the description text.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.