24require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
39 $this->
addDescription(
'Check syntax for all PHP files in MediaWiki' );
40 $this->
addOption(
'with-extensions',
'Also recurse the extensions folder' );
43 'Specific path (file or directory) to check, either with absolute path or '
44 .
'relative to the root of this MediaWiki installation',
50 'Text file containing list of files or directories to check',
56 'Check only files that were modified (requires Git command-line client)'
58 $this->
addOption(
'syntax-only',
'Check for syntax validity only, skip code style warnings' );
68 $this->
output(
"Checking syntax (using php -l, this can take a long time)\n" );
69 foreach ( $this->mFiles
as $f ) {
71 if ( !$this->
hasOption(
'syntax-only' ) ) {
75 $this->
output(
"\nDone! " . count( $this->mFiles ) .
" files checked, " .
76 count( $this->mFailures ) .
" failures and " . count( $this->mWarnings ) .
77 " warnings found\n" );
86 $this->mIgnorePaths = [
89 $this->mNoStyleCheckPaths = [
92 "EmailPage/PHPMailer",
93 "FCKeditor/fckeditor/",
106 $this->
error(
"Error: can't find file or directory $path\n",
true );
110 } elseif ( $this->
hasOption(
'list-file' ) ) {
112 MediaWiki\suppressWarnings();
113 $f = fopen( $file,
'r' );
114 MediaWiki\restoreWarnings();
116 $this->
error(
"Can't open file $file\n",
true );
118 $path = trim( fgets( $f ) );
125 } elseif ( $this->
hasOption(
'modified' ) ) {
126 $this->
output(
"Retrieving list from Git... " );
128 $this->
output(
"done\n" );
131 $this->mFiles[] = $file;
138 $this->
output(
'Building file list...',
'listfiles' );
146 $IP .
'/maintenance',
149 if ( $this->
hasOption(
'with-extensions' ) ) {
150 $dirs[] = $IP .
'/extensions';
158 if ( file_exists(
"$IP/LocalSettings.php" ) ) {
159 $this->mFiles[] =
"$IP/LocalSettings.php";
162 $this->
output(
'done.',
'listfiles' );
174 if ( !is_dir(
"$path/.git" ) ) {
175 $this->
error(
"Error: Not a Git repository!\n",
true );
188 $cmd =
"cd $ePath && git merge-base master HEAD";
192 $this->
error(
"Error retrieving base SHA1 from Git!\n",
true );
197 $cmd =
"cd $ePath && git diff --name-only --diff-filter AM $eBase";
201 $this->
error(
"Error retrieving list from Git!\n",
true );
207 $filename = strtok(
$output,
"\n" );
208 while ( $filename !==
false ) {
209 if ( $filename !==
'' ) {
210 $arr[] =
"$path/$filename";
212 $filename = strtok(
"\n" );
224 $file = str_replace(
'\\',
'/', $file );
225 $ext = pathinfo( $file, PATHINFO_EXTENSION );
226 if (
$ext !=
'php' &&
$ext !=
'inc' &&
$ext !=
'php5' ) {
229 foreach ( $this->mIgnorePaths
as $regex ) {
231 if ( preg_match(
"~{$regex}~", $file, $m ) ) {
256 if ( is_dir(
$path ) ) {
258 } elseif ( file_exists(
$path ) ) {
259 $this->mFiles[] =
$path;
273 $iterator =
new RecursiveIteratorIterator(
274 new RecursiveDirectoryIterator(
$dir ),
275 RecursiveIteratorIterator::SELF_FIRST
277 foreach ( $iterator
as $file ) {
279 $this->mFiles[] = $file->getRealPath();
291 if ( strpos(
$res,
'No syntax errors detected' ) ===
false ) {
292 $this->mFailures[$file] =
$res;
308 foreach ( $this->mNoStyleCheckPaths
as $regex ) {
310 if ( preg_match(
"~{$regex}~", $file, $m ) ) {
315 $text = file_get_contents( $file );
316 $tokens = token_get_all( $text );
319 $this->
checkRegex( $file, $text,
'/^[\s\r\n]+<\?/',
'leading whitespace' );
320 $this->
checkRegex( $file, $text,
'/\?>[\s\r\n]*$/',
'trailing ?>' );
321 $this->
checkRegex( $file, $text,
'/^[\xFF\xFE\xEF]/',
'byte-order mark' );
325 if ( !preg_match( $regex, $text ) ) {
329 if ( !isset( $this->mWarnings[$file] ) ) {
330 $this->mWarnings[$file] = [];
332 $this->mWarnings[$file][] = $desc;
333 $this->
output(
"Warning in file $file: $desc found.\n" );
337 if ( !in_array( $evilToken,
$tokens ) ) {
341 if ( !isset( $this->mWarnings[$file] ) ) {
342 $this->mWarnings[$file] = [];
344 $this->mWarnings[$file][] = $desc;
345 $this->
output(
"Warning in file $file: $desc found.\n" );
$wgMaxShellMemory
Maximum amount of virtual memory available to shell processes under linux, in KB.
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
wfEscapeShellArg()
Version of escapeshellarg() that works better on Windows.
Maintenance script to check syntax of all PHP files in MediaWiki.
getGitModifiedFiles( $path)
Returns a list of tracked files in a Git work tree differing from the master branch.
addFileOrDir( $path)
Add given file to file list, or, if it's a directory, add its content.
execute()
Do the actual work.
isSuitableFile( $file)
Returns true if $file is of a type we can check.
checkFileWithCli( $file)
Check a file for syntax errors using php -l.
__construct()
Default constructor.
addPath( $path)
Add given path to file list, searching it in include path if needed.
checkEvilToken( $file, $tokens, $evilToken, $desc)
addDirectoryContent( $dir)
Add all suitable files in given directory or its subdirectories to the file list.
buildFileList()
Build the list of files we'll check for syntax errors.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
checkForMistakes( $file)
Check a file for non-fatal coding errors, such as byte-order marks in the beginning or pointless ?...
checkRegex( $file, $text, $regex, $desc)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
const DB_NONE
Constants for DB access type.
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
when a variable name is used in a it is silently declared as a new local masking the global
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
if(count( $args)==0) $dir
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
require_once RUN_MAINTENANCE_IF_MAIN