MediaWiki  1.23.0
mergeMessageFileList.php
Go to the documentation of this file.
1 <?php
25 # Start from scratch
26 define( 'MW_NO_EXTENSION_MESSAGES', 1 );
27 
28 require_once __DIR__ . '/Maintenance.php';
29 $maintClass = 'MergeMessageFileList';
30 $mmfl = false;
31 
42  protected $hasError;
43 
44  function __construct() {
45  parent::__construct();
46  $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', false, true );
47  $this->addOption( 'extensions-dir', 'Path where extensions can be found.', false, true );
48  $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
49  $this->mDescription = 'Merge $wgExtensionMessagesFiles and $wgMessagesDirs from ' .
50  ' various extensions to produce a single file listing all message files and dirs.';
51  }
52 
53  public function execute() {
54  global $mmfl, $wgExtensionEntryPointListFiles;
55 
56  if ( !count( $wgExtensionEntryPointListFiles )
57  && !$this->hasOption( 'list-file' )
58  && !$this->hasOption( 'extensions-dir' )
59  ) {
60  $this->error( "Either --list-file or --extensions-dir must be provided if " .
61  "\$wgExtensionEntryPointListFiles is not set", 1 );
62  }
63 
64  $mmfl = array( 'setupFiles' => array() );
65 
66  # Add setup files contained in file passed to --list-file
67  if ( $this->hasOption( 'list-file' ) ) {
68  $extensionPaths = $this->readFile( $this->getOption( 'list-file' ) );
69  $mmfl['setupFiles'] = array_merge( $mmfl['setupFiles'], $extensionPaths );
70  }
71 
72  # Now find out files in a directory
73  if ( $this->hasOption( 'extensions-dir' ) ) {
74  $extdir = $this->getOption( 'extensions-dir' );
75  $entries = scandir( $extdir );
76  foreach ( $entries as $extname ) {
77  if ( $extname == '.' || $extname == '..' || !is_dir( "$extdir/$extname" ) ) {
78  continue;
79  }
80  $extfile = "{$extdir}/{$extname}/{$extname}.php";
81  if ( file_exists( $extfile ) ) {
82  $mmfl['setupFiles'][] = $extfile;
83  } else {
84  $this->hasError = true;
85  $this->error( "Extension {$extname} in {$extdir} lacks expected {$extname}.php" );
86  }
87  }
88  }
89 
90  # Add setup files defined via configuration
91  foreach ( $wgExtensionEntryPointListFiles as $points ) {
92  $extensionPaths = $this->readFile( $points );
93  $mmfl['setupFiles'] = array_merge( $mmfl['setupFiles'], $extensionPaths );
94  }
95 
96  if ( $this->hasError ) {
97  $this->error( "Some files are missing (see above). Giving up.", 1 );
98  }
99 
100  if ( $this->hasOption( 'output' ) ) {
101  $mmfl['output'] = $this->getOption( 'output' );
102  }
103  if ( $this->hasOption( 'quiet' ) ) {
104  $mmfl['quiet'] = true;
105  }
106  }
107 
112  private function readFile( $fileName ) {
113  global $IP;
114 
115  $files = array();
116  $fileLines = file( $fileName );
117  if ( $fileLines === false ) {
118  $this->hasError = true;
119  $this->error( "Unable to open list file $fileName." );
120  return $files;
121  }
122  # Strip comments, discard empty lines, and trim leading and trailing
123  # whitespace. Comments start with '#' and extend to the end of the line.
124  foreach ( $fileLines as $extension ) {
125  $extension = trim( preg_replace( '/#.*/', '', $extension ) );
126  if ( $extension !== '' ) {
127  # Paths may use the string $IP to be substituted by the actual value
128  $extension = str_replace( '$IP', $IP, $extension );
129  if ( file_exists( $extension ) ) {
130  $files[] = $extension;
131  } else {
132  $this->hasError = true;
133  $this->error( "Extension {$extension} doesn't exist" );
134  }
135  }
136  }
137  return $files;
138  }
139 }
140 
141 require_once RUN_MAINTENANCE_IF_MAIN;
142 
143 foreach ( $mmfl['setupFiles'] as $fileName ) {
144  if ( strval( $fileName ) === '' ) {
145  continue;
146  }
147  if ( empty( $mmfl['quiet'] ) ) {
148  fwrite( STDERR, "Loading data from $fileName\n" );
149  }
150  // Include the extension to update $wgExtensionMessagesFiles
151  if ( !( include_once $fileName ) ) {
152  fwrite( STDERR, "Unable to read $fileName\n" );
153  exit( 1 );
154  }
155 }
156 fwrite( STDERR, "\n" );
157 $s =
158  "<" . "?php\n" .
159  "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
160  "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
161  '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n" .
162  '$wgMessagesDirs = ' . var_export( $wgMessagesDirs, true ) . ";\n\n";
163 
164 $dirs = array(
165  $IP,
166  dirname( __DIR__ ),
167  realpath( $IP )
168 );
169 
170 foreach ( $dirs as $dir ) {
171  $s = preg_replace( "/'" . preg_quote( $dir, '/' ) . "([^']*)'/", '"$IP\1"', $s );
172 }
173 
174 if ( isset( $mmfl['output'] ) ) {
175  file_put_contents( $mmfl['output'], $s );
176 } else {
177  echo $s;
178 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$files
$files
Definition: importImages.php:67
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
$maintClass
$maintClass
Definition: mergeMessageFileList.php:29
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$s
$s
Definition: mergeMessageFileList.php:156
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
MergeMessageFileList
Maintenance script that merges $wgExtensionMessagesFiles from various extensions to produce a single ...
Definition: mergeMessageFileList.php:38
MergeMessageFileList\readFile
readFile( $fileName)
Definition: mergeMessageFileList.php:111
file
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition: hooks.txt:93
$mmfl
$mmfl
Definition: mergeMessageFileList.php:30
$points
$points
Definition: profileinfo.php:361
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$dirs
$dirs
Definition: mergeMessageFileList.php:163
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MergeMessageFileList\__construct
__construct()
Default constructor.
Definition: mergeMessageFileList.php:43
MergeMessageFileList\execute
execute()
Do the actual work.
Definition: mergeMessageFileList.php:52
MergeMessageFileList\$hasError
bool $hasError
Definition: mergeMessageFileList.php:41
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
$wgExtensionMessagesFiles
$wgExtensionMessagesFiles['ExtensionNameMagic']
Definition: magicword.txt:43
as
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
Definition: distributors.txt:9
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
$IP
$IP
Definition: WebStart.php:88