Go to the documentation of this file.
22 require_once __DIR__ .
'/../Maintenance.php';
38 parent::__construct();
40 Manage foreign resources registered with ResourceLoader.
43 libraries registered
as ResourceLoader modules. See also foreign-resources.yaml.
45 For sources
that don
't publish an integrity hash, omit "integrity" (or leave empty)
46 and run the "make-sri" action to compute the missing hashes.
48 This script runs in dry-run mode by default. Use --update to actually change,
49 remove, or add files to resources/lib/.
52 $this->addArg( 'action', 'One
of "update",
"verify" or "make-sri"', true );
53 $this->addArg( 'module
', 'Name
of a single module (Default: all)
', false );
56 // Use a directory in $IP instead of wfTempDir() because
58 $this->tmpParentDir =
"{$IP}/resources/tmp";
64 if ( !in_array( $this->
action, [
'update',
'verify',
'make-sri' ] ) ) {
65 $this->
fatalError(
"Invalid action argument." );
69 file_get_contents( __DIR__ .
'/foreign-resources.yaml' )
71 $module = $this->
getArg( 1,
'all' );
72 if ( $module ===
'all' ) {
74 } elseif ( isset( $registry[ $module ] ) ) {
75 $modules = [ $module => $registry[ $module ] ];
81 $this->
verbose(
"\n### {$moduleName}\n\n" );
82 $destDir =
"{$IP}/resources/lib/$moduleName";
84 if ( $this->
action ===
'update' ) {
85 $this->
output(
"... updating '{$moduleName}'\n" );
86 $this->
verbose(
"... emptying /resources/lib/$moduleName\n" );
88 } elseif ( $this->
action ===
'verify' ) {
89 $this->
output(
"... verifying '{$moduleName}'\n" );
91 $this->
output(
"... checking '{$moduleName}'\n" );
94 $this->
verbose(
"... preparing {$this->tmpParentDir}\n" );
97 $this->
fatalError(
"Unable to create {$this->tmpParentDir}" );
100 if ( !isset( $info[
'type'] ) ) {
101 $this->
fatalError(
"Module '$moduleName' must have a 'type' key." );
103 switch ( $info[
'type'] ) {
114 $this->
fatalError(
"Unknown type '{$info['type']}' for '$moduleName'" );
119 $this->
output(
"\nDone!\n" );
120 if ( $this->failAfterOutput ) {
126 private function fetch( $src, $integrity ) {
127 $data =
Http::get( $src, [
'followRedirects' =>
false ] );
128 if ( $data ===
false ) {
129 $this->
fatalError(
"Failed to download resource at {$src}" );
131 $algo = $integrity ===
null ? $this->defaultAlgo : explode(
'-', $integrity )[0];
132 $actualIntegrity = $algo .
'-' . base64_encode( hash( $algo, $data,
true ) );
133 if ( $integrity === $actualIntegrity ) {
134 $this->
verbose(
"... passed integrity check for {$src}\n" );
136 if ( $this->
action ===
'make-sri' ) {
137 $this->
output(
"Integrity for {$src}\n\tintegrity: ${actualIntegrity}\n" );
139 $this->
fatalError(
"Integrity check failed for {$src}\n" .
140 "\tExpected: {$integrity}\n" .
141 "\tActual: {$actualIntegrity}"
149 if ( !isset( $info[
'src'] ) ) {
150 $this->
fatalError(
"Module '$moduleName' must have a 'src' key." );
152 $data = $this->
fetch( $info[
'src'], $info[
'integrity'] ??
null );
153 $dest = $info[
'dest'] ?? basename( $info[
'src'] );
154 $path =
"$destDir/$dest";
155 if ( $this->
action ===
'verify' && sha1_file(
$path ) !== sha1( $data ) ) {
156 $this->
fatalError(
"File for '$moduleName' is different." );
157 } elseif ( $this->
action ===
'update' ) {
159 file_put_contents(
"$destDir/$dest", $data );
164 if ( !isset( $info[
'files'] ) ) {
165 $this->
fatalError(
"Module '$moduleName' must have a 'files' key." );
167 foreach ( $info[
'files']
as $dest => $file ) {
168 if ( !isset( $file[
'src'] ) ) {
169 $this->
fatalError(
"Module '$moduleName' file '$dest' must have a 'src' key." );
171 $data = $this->
fetch( $file[
'src'], $file[
'integrity'] ??
null );
172 $path =
"$destDir/$dest";
173 if ( $this->
action ===
'verify' && sha1_file(
$path ) !== sha1( $data ) ) {
174 $this->
fatalError(
"File '$dest' for '$moduleName' is different." );
175 } elseif ( $this->
action ===
'update' ) {
177 file_put_contents(
"$destDir/$dest", $data );
183 $info += [
'src' =>
null,
'integrity' =>
null,
'dest' => null ];
184 if ( $info[
'src'] ===
null ) {
185 $this->
fatalError(
"Module '$moduleName' must have a 'src' key." );
188 $data = $this->
fetch( $info[
'src'], $info[
'integrity' ] );
189 $tmpFile =
"{$this->tmpParentDir}/$moduleName.tar";
190 $this->
verbose(
"... writing '$moduleName' src to $tmpFile\n" );
191 file_put_contents( $tmpFile, $data );
192 $p =
new PharData( $tmpFile );
193 $tmpDir =
"{$this->tmpParentDir}/$moduleName";
194 $p->extractTo( $tmpDir );
197 if ( $info[
'dest'] ===
null ) {
199 $toCopy = [ $tmpDir => $destDir ];
203 foreach ( $info[
'dest']
as $fromSubPath => $toSubPath ) {
205 $fromPaths = glob(
"{$tmpDir}/{$fromSubPath}", GLOB_BRACE );
207 $this->
fatalError(
"Path '$fromSubPath' of '$moduleName' not found." );
209 foreach ( $fromPaths
as $fromPath ) {
210 $toCopy[$fromPath] = $toSubPath ===
null
211 ?
"$destDir/" . basename( $fromPath )
212 :
"$destDir/$toSubPath/" . basename( $fromPath );
216 foreach ( $toCopy
as $from => $to ) {
217 if ( $this->
action ===
'verify' ) {
218 $this->
verbose(
"... verifying $to\n" );
219 if ( is_dir( $from ) ) {
220 $rii =
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
222 RecursiveDirectoryIterator::SKIP_DOTS
224 foreach ( $rii
as $file ) {
225 $remote = $file->getPathname();
226 $local = strtr( $remote, [ $from => $to ] );
227 if ( sha1_file( $remote ) !== sha1_file( $local ) ) {
228 $this->
error(
"File '$local' is different." );
229 $this->failAfterOutput =
true;
232 } elseif ( sha1_file( $from ) !== sha1_file( $to ) ) {
233 $this->
error(
"File '$to' is different." );
234 $this->failAfterOutput =
true;
236 } elseif ( $this->
action ===
'update' ) {
237 $this->
verbose(
"... moving $from to $to\n" );
239 if ( !rename( $from, $to ) ) {
240 $this->
fatalError(
"Could not move $from to $to." );
258 parent::fatalError( $msg, $exitCode );
277 $trimmed = ltrim( $text,
' ' );
278 if ( $trimmed ===
'' || $trimmed[0] ===
'#' ) {
281 $indent = strlen( $text ) - strlen( $trimmed );
282 if ( $indent % 2 !== 0 ) {
283 throw new Exception( __METHOD__ .
": Odd indentation on line $line." );
285 $depth = $indent === 0 ? 0 : ( $indent / 2 );
286 if ( $depth < $prev ) {
288 array_splice( $stack, $depth + 1 );
290 if ( !array_key_exists( $depth, $stack ) ) {
291 throw new Exception( __METHOD__ .
": Too much indentation on line $line." );
293 if ( strpos( $trimmed,
':' ) ===
false ) {
294 throw new Exception( __METHOD__ .
": Missing colon on line $line." );
296 $dest =& $stack[ $depth ];
297 if ( $dest ===
null ) {
301 list( $key, $val ) = explode(
':', $trimmed, 2 );
302 $val = ltrim( $val,
' ' );
305 $dest[ $key ] = $val;
310 $dest[ $key ] = &$val;
313 unset( $dest, $val );
handleTypeFile( $moduleName, $destDir, array $info)
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function 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
Manage foreign resources registered with ResourceLoader.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
addDescription( $text)
Set the description text.
require_once RUN_MAINTENANCE_IF_MAIN
</source > ! result< div class="mw-highlight mw-content-ltr" dir="ltr">< pre >< span ></span >< span class="kd"> var</span >< span class="nx"> a</span >< span class="p"></span ></pre ></div > ! end ! test Multiline< source/> in lists !input *< source > a b</source > *foo< source > a b</source > ! html< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! html tidy< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! end ! test Custom attributes !input< source lang="javascript" id="foo" class="bar" dir="rtl" style="font-size: larger;"> var a
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
parseBasicYaml( $input)
Basic YAML parser.
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
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control systems
handleTypeMultiFile( $moduleName, $destDir, array $info)
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
if(is_array( $mode)) switch( $mode) $input
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or work
handleTypeTar( $moduleName, $destDir, array $info)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
static get( $url, $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
__construct()
Default constructor.
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
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
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
execute()
Do the actual work.
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if that
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is and will automatically terminate your rights under this License parties who have received copies
hasOption( $name)
Checks to see if a particular option exists.
getArg( $argId=0, $default=null)
Get an argument.