Commit graph

71 commits

Author SHA1 Message Date
Kunal Mehta
4de667f3c2 maintenance: Allow having a nicer error message if an extension isn't enabled
Maintenance scripts can be invoked regardless of whether an extension is
enabled on a wiki or not. On wiki farms where some wikis may have an
extension or not, this can potentially be rather confusing. Especially
when the script bails out with a fatal class missing error or a database
table missing.

This allows maintenance scripts to specify that they require an
extension by calling:
 $this->requireExtension( 'ExtensionName' );
in the script's constructor.

Bug: T141531
Change-Id: Icfbf063bb9c9ac9e55c3a5a8ed815528a2c1ce1e
2016-07-30 10:38:51 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Aaron Schulz
58cffd04b8 Pass __METHOD__ to load balancer commit/rollback methods
Change-Id: I3fd87908c2a493fae49de6a29efe79f8d433c112
2015-12-22 18:30:20 -08:00
Aaron Schulz
a8590172c8 Make DeferredUpdates::doUpdates always commit per task
* All callers are either using commit already or would be fine
  using it (e.g. Maintenance scripts and JobRunner that have
  no real transaction open).

Change-Id: I9f54b27619da6dac2cb63d255995aabc4ee78002
2015-10-22 01:27:08 +00:00
Kunal Mehta
a0d422e67f maintenance: Defer initilization of 'main' Config until after Setup.php runs
Bug: T90680
Change-Id: I72d6306404bc1f6c7a605853130a026e9858b493
2015-03-03 23:51:44 -08:00
Erik Bernhardson
d99963bc2a No such method Exception::getText()
It looks like a recent change converted this try/catch
statement from MWException to Exception, unfortunatly it
is still calling a method that only exists on MWException.

We arn't doing anything with the exception but exiting.  Lets
just allow the exception to be uncaught and fail naturally. The
uncaught exception will still output an error and return
a non-0 exit code.

Change-Id: I3e0e9d283c255d2aba8139d675943e93d7cb021a
2015-02-03 11:09:54 -08:00
Aaron Schulz
6921770414 Updated some try-catch statements: MWException -> Exception
Change-Id: I76601a86e30f4984e3b1a8c8ec5ef5a0f652433a
2015-01-09 17:20:22 -08:00
Kunal Mehta
bfe4ddd810 Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.

Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.

The basic flow of loading an extension goes like:
 * Get the ExtensionRegistry singleton instance
 * ExtensionRegistry takes a filename, reads the file or tries
   to get the parsed JSON from APC if possible.
 * The JSON is run through a Processor instance,
   which registers things with the appropriate
   global settings.
 * The output of the processor is cached in APC if possible.
 * The extension/skin is marked as loaded in the
   ExtensionRegistry and a callback function is executed
   if one was specified.

For ideal performance, a batch loading method is also provided:
 * The absolute path name to the JSON file is queued
   in the ExtensionRegistry instance.
 * When loadFromQueue() is called, it constructs a hash
   unique to the members of the current queue, and sees
   if the queue has been cached in APC. If not, it processes
   each file individually, and combines the result of each
   Processor into one giant array, which is cached in APC.
 * The giant array then sets various global settings,
   defines constants, and calls callbacks.

To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.

Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2015-01-08 01:40:01 +00:00
Chad Horohoe
4e61f1bb8b Profiler code cleanup
- Put Profiler, ProfileSection and TransactionProfiler in their own
  files and rely on Autoloader to use them (maintenance has been
  using the autoloader here for some time--we don't profile the
  autoloader manually)
- This reduces overhead in WebStart/doMaintenance by only loading
  three functions at profiler initialization and defers until the
  first profiling call happens
- Inline callback functions in ProfilerSimpleText rather than having
  public static functions.
- Small comment and code formatting changes in various touched files.

Change-Id: Idf27677c068c50b847152c523a33e7f0c33fdeeb
2014-11-04 21:14:51 +00:00
Kunal Mehta
b016aa66dc Maintenance: Add an easy way to access Config instances
Change-Id: I97d50c624e988c70bb2ac0da4fc33957ce3cf524
2014-09-09 17:37:03 -07:00
withoutaname
2997b116f3 Remove check for wikimedia-mode file, which no longer exists
Change-Id: Ib463e7687b7b35147bddef68b9548e7b86c5ef52
2014-07-19 21:31:08 -07:00
Siebrand Mazeland
752c708149 Pass phpcs-strict on maintenance/ (6/8)
Change-Id: Icefd7660072aedb963fe3082ec40fb8ffcfd6286
2014-04-23 09:27:41 +00:00
Chad Horohoe
518fa756f2 Remove $wgTitle from all maintenance scripts
Shouldn't be needed and aren't for any core operations. If any
extension relies on these $wgTitles being set in maintenance
environments those extensions are broken and should be fixed.

Change-Id: Ie02a5042ab96e155d783d56d5340dd0da8e3d55c
2014-03-12 18:28:47 -07:00
Chad Horohoe
4d6dad7100 Remove vestiges of AdminSettings.php
This has been deprecated and mostly unused for quite some time.
Remove the few remaining uses that exist.

Change-Id: I522ef138d291cf7567250fef1de34bb41673bc6c
2014-01-29 15:09:33 -08:00
umherirrender
0bc583af2c Move closing parenthesis from multi line if and function to own line
The Line continuation Coding conventions prefers the closing parenthesis
on the same line than the beginning curly braces. This is done for ifs
and functions.
Also move some boolean operator from the end of a line to the beginning
and changed some indentation to make the condition hopefully better
readable.

Change-Id: Id0437b06bde86eb5a75bc59eefa19e7edb624426
2013-12-01 21:39:00 +01:00
Siebrand Mazeland
e711503e7a Remove underscore from classes LCStore_*
iPart of program to remove underscores from class names. Checked core and
600+ extensions for occurrences. All uses are in core, and are updated in
this change.

Change-Id: I432dc249d22053728013ae7d0d56c3c398021c5e
2013-11-17 22:09:31 +01:00
Kevin Israel
12c61d3e7f Remove remaining calls to MWInit methods
... as well as the require_once statements in includes/WebStart.php
and maintenance/doMaintenance.php, now that the autoloader lists
MWInit (since r85807 / c68957c5e3).

Also removed code paths in maintenance/userDupes.inc that seem to be
dead (class_exists( 'Revision' ) should always be true) and useless
global/require_once statements in languages/Language.php.

Follows-up Ic3e769f1fbad4f7ad26dd819406796fee48c6b45.

Change-Id: I48fd6810fdb923b3065ae98024912eb18d394415
2013-09-15 19:04:08 +00:00
Kevin Israel
052f1fcf30 Deprecate MWFunction::call and ::callArray
These functions existed to work around a bug (fixed in PHP 5.3) and
a missing feature (added in PHP 5.2) in older versions of PHP;
therefore, they are no longer necessary.

Change-Id: Ifebbe3d449fc57fd83f8350c28f467605c1a07b7
2013-07-19 18:48:51 -04:00
jeroendedauw
b1c73fc670 Move inclusion of the Composer autoloader to after inclusion of DefaultSettings
If it is before, settings set by extensions will end up being overriden.

Change-Id: Ibe80d621cfaa7258cfd759094a1e9f0008a469b1
2013-07-15 17:33:50 +02:00
Daniel Friesen
2740518620 Support installing PHPUnit using composer.
"phpunit/phpunit" already exists inside our composer.json's "require-dev" however this has been
entirely useless as we don't include the autoloader which would load composer's PHPUnit.

This change begins including composer's autoloader when present and also tweaks phpunit.php
to ensure PHPUnit isn't double loaded. As a result besides supporting PHPUnit via composer this
also means that we're ready to make use of any library we add to our composer.json in the future.

Change-Id: I891740e8fd3d237c5f473862027205d951f564b9
2013-06-07 02:07:27 -07:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
umherirrender
21751b9ba7 echo is not a function
Removed parenthesis after echo

Change-Id: Ia533aedf63b11d15dcc6a5cf75a56134a4b11d86
2013-05-09 19:52:45 +00:00
Tim Starling
1fe9340bb3 Remove hphpc support and deprecate related functions
hphpc has been superseded by hhvm, so support for hphpc is no longer
needed.

* Continue to use Preprocessor_Hash under HipHop since it is still
  faster under hhvm
* Keep $wgCompiledFiles for now, so that wikihiero doesn't give an error
  before Ic9d1e795 is merged
* Migrate the run-server script and associated configuration file to
  hhvm. Enable EnableStaticContentFromDisk since it doesn't seem
  ridiculously inefficient at first glance. Run from $IP rather than
  $IP/.. since hhvm is apparently not picky about sourcing files from
  outside of the current directory.

Change-Id: Ic3e769f1fbad4f7ad26dd819406796fee48c6b45
2013-05-09 08:28:05 +10:00
umherirrender
b114f5e1c1 Fixed some spacing in maintenance folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9657f72996358f8c1c154cea1ea97970d973723c
2013-04-18 20:48:44 +02:00
Aaron Schulz
820de0f13b Set up the profiler in CLI mode.
Change-Id: I7f36786573870b66b4f1e93c2fc2e444f1ae1252
2013-04-17 10:05:00 -07:00
Tyler Anthony Romeo
c628b6d121 (bug 42600) (bug 24375) Fix doMaintenance.php exit procedures.
Fixed the post-execution calls in doMaintenance.php
to perform proper cleanup after the maintenance
script runs (modeled after MediaWiki::restInPeace).

Added a global call to wfWaitForSlaves() and then
wfDoUpdates() in doMaintenance.php to ensure that
deferred updates are always performed at the end
of maintenance scripts (and that they're performed
after the slaves catch up to avoid lag).

Also added calls to shutdown the DB factory so
that implicit transactions are committed and the
connections are closed.

Change-Id: I6f9580559d75f4761c5ddb504b2e3380e2e562a3
2013-02-20 14:25:44 -05:00
Antoine Musso
f6b92231fd style: normalize end of files
By PSR2 PHP Standard, the files should ends with exactly one newline.
Some of our files have 2 or more and some other were missing a newline.

Fix almost all occurences of CodeSniffer sniff:
PSR2.Files.EndFileNewline.TooMany

I have not fixed the selenium files, I believe we will drop them.

Change-Id: I89fca8c1786fee94855b7b77bb0f364001ee84b6
2013-02-03 15:04:39 +01:00
daniel
2926b29da3 Log profiling info from maintenance scripts.
Previously, maintenance scripts did not log profiling info.

Change-Id: Ib63dd54b815cca774cd764f28505f9dbdfd02cfc
2013-02-01 11:23:21 +01:00
Platonides
1bb25971f2 Disable the db LCStore if the maintenance script doesn't need a db.
If $wgLanguageCode != 'en', loading of the language class will
go to the LCStore looking for the fallbacks, even if the script
doesn't need a database.

Change-Id: I6a1920ba02d146622f3a5647bf02ddec3e3da54b
2012-06-26 18:58:37 +02:00
Antoine Musso
27bfa2854f revert r102636
This move back the maintenance finalSetup code above core Setup.
If we really need to do any setup after core Setup has run, we should use
a new method in the Maintenance class. For example afterCoreSetup()
2011-11-24 09:41:54 +00:00
Antoine Musso
513a094b09 load up includes/Setup.php before Maintenance::finalSetup()
This let us get access to global functions and the autoloader when trying
to do some final setup for our maintenance scripts.
2011-11-10 11:18:50 +00:00
Chad Horohoe
34e0645068 Stupid merge conflicts, fix r96537 2011-09-08 01:54:27 +00:00
Chad Horohoe
51dcadd537 Last fix for r96529, I swear...only CommonSettings.php needs interpretPath(). Core loadSettings() already returns LocalSettings with $IP prefixed. 2011-09-08 01:52:36 +00:00
Chad Horohoe
d489ca4518 Another fix for r96529: using MW_CONFIG_CALLBACK should halt normal settings file loading. Broke command-line installer 2011-09-08 00:59:58 +00:00
Chad Horohoe
321de8502c Tweaks to WikimediaMaintenance:
* Rename Site to WMFSite, less likely to conflict
* Create generic inclusion point for these scripts, so they don't have to duplicate the $IP detection
* Make them all subclass WikimediaMaintenance and move some of the wmf-specific hacks out of core -- almost resolved this crap :D
* Fix rebuildInterwiki to be protocol-relative (like r96139)
* By the way: rebuildInterwiki and dumpInterwiki seem awfully alike...maybe we can merge the two :)
2011-09-08 00:35:16 +00:00
Aaron Schulz
8d0dcbbad3 Updated doMaintenance since wmf-config/ was moved up a dir 2011-07-18 17:23:56 +00:00
Chad Horohoe
226b5730a3 Remove superfluous inclusion of SiteConfiguration in doMaintenance. It's in the AutoLoader and has already been initialized by DefaultSettings by this point.
As a result: rm DIY inclusion protection, since this was the only reason it was still needed.
2011-06-30 21:25:52 +00:00
Chad Horohoe
4081fcabad Kill $wgWikiFarm. Only use in a wmf code path, and I can't find any evidence of this being use in WMF anywhere. 2011-06-03 03:38:52 +00:00
Tim Starling
ff1dc8a175 HipHop improvements:
* Added the ability to compile extensions. The build process is bootstrapped by running MediaWiki in interpreted mode. Extension setup file inclusions are slightly modified in a way that makes them register themselves for compilation. Then the same LocalSettings.php uses the compiled extension setup file when the compiled binary runs.
* Tested with Cite and ParserFunctions. The code which lets you have an extensions directory in a place other than $IP/../extensions is untested.
* Simplified WebStart.php slightly by using a custom $_SERVER variable to mark compiled mode. It will break if you don't use the supplied server.conf, but that will break a lot of things so don't do that.
* Fixed the core web entry points to include WebStart.php in compiled mode instead of interpreted.
* Made the build directory configurable. This is mostly so that I can grep the source tree without seeing loads of generated C++.
* In server.conf, added a rewrite rule allowing a /wiki/$1 article path.
* Removed server.conf log file location "/dev/stdout", breaks when you switch user
* Disable static content cache, breaks horribly when you set SourceRoot to a directory containing 7GB of files.
* Rewrote the run-server script in PHP, mostly to support the configurable build directory feature.
* Added an option to the run-server script to allow running in interpreted (hphpi) mode.
2011-05-30 13:49:09 +00:00
Siebrand Mazeland
75c6696aa8 Use consistent notation for "@todo FIXME". Should update http://svn.wikimedia.org/doc/todo.html nicely. 2011-05-17 22:03:20 +00:00
Sam Reed
b0c3fc9fe6 Remove install-utils.inc marked for 1.19 removal 2011-05-06 20:35:52 +00:00
Chad Horohoe
e5d496b121 Followup r86228 (profiling cleanup):
* Move autoloader up in Maintenance as well
* Add setInstance() method to Profiler, dumpHTML will need it
2011-04-16 19:23:45 +00:00
Chad Horohoe
5a6d1ee2d3 More profiler cleanup:
* Move autoloader up a little bit so the profiler classes can use it
* Make Profiler into a singleton so it's lazy-constructed, $wgProfiler is now a configuration array (used 'visible' in ProfilerSimpleText as an example of other globals we can move into this array). If $wgProfiler is set to an object, it'll use that for back-compat
* Maintenance: rather than setting up the profiler and then disabling it, just disable it from the start
* Kill $wgProfiling -> now that ProfilerStub overrides profileIn() and profileOut(), it's not needed
* dumpHTML needs some fixes still
2011-04-16 19:00:54 +00:00
Chad Horohoe
e376ee65f7 First step of reorganizing profiling files:
* Move them all to includes/profiling/* - If you're using StartProfiler, you'll need to update that
* Make ProfileStub subclass the Profiler rather than duplicating function definitions conditionally
* Removed unused params to wfGetProfilingOutput(), only used in the stub, and they didn't do anything with them
* TODO: Kill $wgProfiling, make $wgProfiler a config array and move the various options to that. Also make into a singleton, rather than global (not much calls it outside of core)
2011-04-16 02:19:40 +00:00
Tim Starling
7bb50c630a The beginnings of HipHop compiled mode support. It works now for parser cache hits.
* Work around HipHop issue 314 (volatile broken) and issue 308 (no compilation detection) by adding some large and ugly compilation detection code to WebStart.php and doMaintenance.php.
* Provide an MW_COMPILED constant which can be used to detect compiled mode throughout the codebase.
* Introduced wfIsHipHop(), which detects either compiled or interpreted mode. Used this to work around unusual eval() return value in eval.php.
* Work around lack of ini_get() in Maintenance.php, by duplicating wfIsHipHop(). 
* In Maintenance::shouldExecute(), accept "include" as an inclusion function name, since all kinds of inclusion give this string in HipHop.
* Introduced new class MWInit, which provides some static functions in the pre-autoloader environment.
* Introduced MWInit::compiledPath(), which provides a relative path for invoking a compiled file, and MWInit::interpretedPath(), which provides an absolute path for interpreting a PHP file. Used these new functions in the appropriate places.
* When we are running compiled code, don't include files which would generate duplicate class, function or constant definitions. Documented the new requirements on the contents of Defines.php and UtfNormalDefines.php.
* In HipHop compiled mode, it's not possible to have executable code in the same file as a class definition. 
  ** Moved MimeMagic initialisation to the constructor.
  ** Moved Namespace.php global variable initialisation to Setup.php.
  ** Moved MemcachedSessions.php initialisation to the caller in GlobalFunctions.php.
  ** Moved Sanitizer.php constants and global variables to static class members. Introduced an accessor function for the attribs regex, as a new place to put code formerly at file level. 
  ** Moved Language.php initialisation of $wgLanguageNames to Language::getLanguageNames(). Removed the global variable, marked "private" since forever.

* In two places: don't use error_log() with type=3 to append to a file, HipHop doesn't support it. Use file_put_contents() with FILE_APPEND instead.
* Work around the terrible breakage of class_exists() by using MWInit::classExists() instead in various places. In WebInstaller::getPageByName(), the class_exists() was marked with a fixme comment already, so I replaced it with an autoloader solution.
2011-04-04 12:59:55 +00:00
Chad Horohoe
16467d576f Followup r80205: scripts using commandLine.inc were failing the shouldExecute() check due to extra require()s.
Scripts using this entry point cannot be included standalone for uses as classes, they will always execute.

But then again, if you're not subclassing Maintenance then why are you bothering to write a class in a command line script?
2011-01-14 02:13:30 +00:00
Chad Horohoe
26505b170a Fix concern raised by Brion in r74108 (but has really existed since the maintenance rewrite). Right now, including a maintenance script causes it to execute. This is bad when you want to reuse the particular class but not have it start executing all by itself.
Until now, we relied on setting MW_NO_SETUP which was a) hacky, b) irreversable, and c) likely to be forgotten if you didn't use one of the wrappers like runChild().

Instead, move the freaky magic to doMaintenance and have *it* check if it's in a specific call stack that indicates this is being run from the file scope and should be executed. Rename DO_MAINTENANCE to RUN_MAINTENANCE_IF_MAIN so it's nice and clear what magic happens behind the require_once().
2011-01-13 22:58:55 +00:00
X!
3589532db4 Per my comment on r68760: Make MWfunction class, complete with call_user_func helper functions that automatically
make the callback PHP 5.1 compatible with the Class::Method syntax. Add Unit tests to supplement it.
2011-01-02 06:48:07 +00:00
Tim Starling
07bb8ce5b5 Remove some of the rubbish that has been accumulating in the default LocalSettings.php for years, especially code as opposed to configuration data:
* Don't set $IP. The entry point already sets it, so there's no point. Users can still set it if they can figure out a way to do it without breaking things.
* Don't include DefaultSettings.php. Doing that is code, not configuration, and it can easily be done in WebStart/Maintenance. Some non-standard entry points in extensions may be broken by this. That's their fault for being non-standard. Backwards compatibility is preserved thanks to require_once().
* Introduce $wgInvalidateCacheOnLocalSettingsChange, which when set, causes $wgCacheEpoch to be updated in the way that it previously was in the default LocalSettings.php.
* Don't set $wgLocalInterwiki to some nonsense value (possibly including spaces and punctuation in the new installer). It should be only for actual interwiki prefixes. Since most wikis don't have them, I set this to false by default and adjusted the referring code to accept this. 
* Removed the guard for web invocation with $wgCommandLineMode set. This ancient code is redundant with modern protections in doMaintenance.php. 
* In DefaultSettings.php, fixed fold terminator placement near $wgLoadScript
* Add a web entry point guard. That's one piece of code which really is necessary.
2010-12-06 15:00:56 +00:00
Sam Reed
0a5e36d6fa Revert r77358, didn't have intended affect, and broke unittests 2010-11-27 15:35:57 +00:00