Commit graph

45 commits

Author SHA1 Message Date
daniel
272db6afde Replace "@stable for calling" by "@stable to call"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
2020-07-13 08:55:28 +00:00
daniel
128565505c Mark additional classes as newable for now.
The following glasses are marked as newable per the
Stable Interface Policy, even though logically, they should not be
newable. This is done for classes that are currently instantiated
by extensions, and lack an alternative.

A better way for obtaining an instance of these classes should be
created in the future. At that point, direct instantiation should
be deprecated and replaced.

- includes/ApiMain.php - needs factory
- includes/media/BitmapMetadataHandler.php - should become a stateless service or use handler pattern
- includes/GitInfo.php - should become a stateless service
- includes/logging/LogPage.php - should become a stateless service or use command pattern
- includes/logging/ManualLogEntry.php - should become a stateless service or use command pattern
- includes/poolcounter/PoolCounterWorkViaCallback.php - needs a factory
- includes/context/RequestContext.php - needs to be narrowed down, and should use a factory
- includes/search/SearchHighlighter.php - should have a factory
- includes/TitleArrayFromResult.php - should perhaps be part of TitleFactory
- includes/user/User.php - should at least get a factory method for anons
- includes/diff/Diff.php: needs a TextDiffGenerator service or a factory
- includes/EditPage.php: needs a factory

Bug: T247862
Change-Id: I033158e693c98630ee167d9528fc8c9936f978d4
2020-07-08 18:06:12 +02:00
星耀晨曦
f235f192bf GitInfo: Suppress is_file() warnings when checking $wgGitBin
Use AtEase::quietCall() to check $wgGitBin,
instead of direct check. Because `is_file( $wgGitBin )` may
produce a warning if the path is not within open_basedir.

Bug: T74445
Change-Id: I9d7111bea74b859e03873ceccf31ba0b5822b6aa
2020-06-28 22:24:26 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Seb35
d2347aa5e6 Wording
In GitInfo, the debug sentence "Computed cacheFile" could imply that some
file is written, but in reality "computed" refers to the name. Change to
"Candidate cacheFile".

Bug: T215722
Change-Id: I19448e5790a0f2fcb5202170ca03ab0f5e16d24e
2019-06-01 14:16:00 +02:00
Kunal Mehta
cc5d9a92a2 build: Updating mediawiki/mediawiki-codesniffer to 24.0.0
Change-Id: I66b1775b7c1d36076d9ca78cbeb42787a743f2aa
2019-02-07 18:39:42 +00:00
Kunal Mehta
d503ac7c94 GitInfo: Don't try shelling out if it's disabled
Bug: T198037
Change-Id: I364f9bc0e78439474101f4b2a171805c91f50a72
2018-06-24 23:55:43 +03:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Kunal Mehta
0d1a6a4d1f GitInfo: Fix shell restrictions for submodules
Submodules have their git directory in the master repository's directory
(../.git/modules/<name>). firejail does not allow whitelisted paths to
have ".." in them, so use realpath() to get rid of that.

`git show` still wants to be able to access the main repository
directory though, so we also need to whitelist the $repoDir itself.

Bug: T181919
Change-Id: I928df92b47733bc7fbb9c796bcfc1504d4a4598c
2017-12-02 23:19:24 -08:00
Kunal Mehta
bdb5b592f4 shell: Optionally restrict commands' access with firejail
Introduces a FirejailCommand class, which can be used to add additional
restrictions to a command, for increased security. For now, firejail
containment needs to be enabled on a per-command basis.

The following restrictions are implemented:
* NO_ROOT - disallows any root access, including via setuid binaries
* SECCOMP - block dangerous syscalls with seccomp
* PRIVATE_DEV - create a private /dev
* NO_NETWORK - deny all network access
* NO_EXECVE - block the execve syscall

A convenient Shell::RESTRICT_DEFAULT is equivalent to NO_ROOT | SECCOMP
| PRIVATE_DEV, with the expectation that more restrictions may be added
to it in the future.

In addition, specific paths can be whitelisted with
Command::whitelistPaths(). Any file/directory that isn't whitelisted in
that top level directory (e.g. /srv) won't exist inside the firejail.

$wgShellRestrictionMethod can be set to false for no restriction system,
'firejail' to explicitly use it, or 'autodetect' to autodetect whatever
system is available. In the future the default should be changed to
autodetection once firejail is tested more.

Bug: T173370
Change-Id: Id74df0dbba40e1e7c07c4368aacffb6eb06a17c5
2017-11-28 00:06:40 +00:00
Max Semenik
bf03f7bde3 Convert GitInfo to the new shell framework
Change-Id: I2fdebe8748708412c59a9de4028cc2e280c8d0c8
2017-10-17 03:43:30 +00:00
Seb35
125f83234e Improve GitInfo for reading packed refs
GitInfo only reads branches in files /refs/heads/*; it should also
read those in /.git/packed-refs.

There are 4 tests in this commit to test this new "feature" and add some
code coverage to other methods. Given this class tests Git behaviour and
MediaWiki itself is versioned with Git, the test data are created during
the tests and removed at the end to avoid interference with Git as CVS.

Bug: T155747
Change-Id: Icccdf3ec797788582f836e2d8e267a1d714d50dc
2017-10-02 03:47:33 +00:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
Chad Horohoe
4f40a159ec Use Diffusion for default Git Viewer
- Provide new %R parameter for $wgGitRepositoryViewers that gives
  a non-URL-encoded version of the repo name.
- Don't force repos to end in .git. That's not required and never
  has been.
- Finally swap Gitblit urls for Diffusion equivalents

Change-Id: I7d2fb3eea1587be66b88acc6a9b9d17382cb01d5
2016-03-14 13:03:34 -07:00
umherirrender
8678e32b8d Change remaining places to use short array syntax
Change-Id: I0785c73a239c11188ad7411c5cd8ed09a2dbc9b3
2016-03-11 18:41:26 +01:00
Kunal Mehta
a5ed38dc54 GitInfo: Allow cache to be in the extension directory itself
For ExtensionDistributor to provide git metadata, we need to be able to
store the cache file inside the extension directory itself. The GitInfo
class will now first check if the $wgGitInfoCacheDirectory is populated,
otherwise it will fallback to "$extensionDir/gitinfo.json".

Bug: T122769
Change-Id: Ib3457589ca6899925ae4610cfcdae22af8eaaaeb
2016-01-06 14:41:36 -08:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Aaron Schulz
e369f66d00 Replace wfRunHooks calls with direct Hooks::run calls
* This avoids the overhead of an extra function call

Change-Id: I8ee996f237fd111873ab51965bded3d91e61e4dd
2014-12-10 12:26:59 -08:00
umherirrender
1c68a1ee86 Cleanup some docs (includes/*.php)
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I783e4dbfe5f6f98b32b9a03ccf6439e13e132bcc
2014-07-24 19:42:24 +02:00
Bryan Davis
b6d18ab9f7 Fix GitInfo cache file path computation and storage location
Depending on the configuration used in LocalSettings.php, $IP can be
changed between the time that configuration is loaded and the wiki
runtime by logic in WebStart.php. Attempt to mitigate the effects of
such changes on the cache file name computation by canonicalizing both
$IP and the path using PHP's realpath() function.

Related but distinct is the possible need to configure the canonical
location for finding cache files on disk separately from
$wgCacheDirectory. This change introduces a new configuration variable
named $wgGitInfoCacheDirectory that can be set to a path that diverges
from the default location of $wgCacheDirectory/gitinfo. This will be
useful in the WMF cluster where $wgCacheDirectory points to a directory
that is not managed by the deployment system.

Finally add wfDebugLog logging to make tracking down issues such as
miscomputed cache paths easier.

Bug: 53972
Change-Id: Iceb9e1ce8d3b4bb08f89fa6ec5d5e7392aaafd46
2014-07-08 16:36:10 +00:00
Bryan Davis
831265410e Check for valid git repository in GitInfo::getHeadCommitDate
Ensure that GitInfo::getHead returns a valid value before attempting to
use the git binary to extract a commit date.

Bug: 64948
Change-Id: Ib0d245306842706dbb5d4b9522bb381a5f55526c
2014-05-06 13:19:43 -06:00
Bryan Davis
71fc32c303 Support precomputed data in GitInfo
Support reading git repository information from a JSON file in the cache
directory. When present, this file serves to provide information needed
by getHead, getHeadSHA1, getHeadCommitDate, getCurrentBranch and a new
getRemoteUrl method. A GitInfo::precomputeValues method is also provided
which can generate the cache file for a given GitInfo instance.

This support can be combined with a deployment step to reduce the need
to repeatedly gather information from the .git files/git binary. It also
allows computing information that can be lost when directory structures
differ between deployment staging hosts and hosts running MediaWiki.

This change also adds memoization of computed values for a given GitInfo
instance which may provide a small performance boost even for
deployments which are not using precomputed cache files.

Bug: 53972
Change-Id: I66e058acc5a71e5d82644f85d819f49d6ee9d1e6
2014-05-05 23:50:12 +00:00
umherirrender
7c314de876 Rename some local vars to start with a lowercase letter
Change-Id: I6e5975ed7351c1439eda19afaba5120c6afa50f1
2014-03-15 21:03:05 +00:00
Kunal Mehta
2f6056fab6 GitInfo: Suppress some wrong warnings
It's possible to have a ')' in a .git/config file, but
parse_ini_file will claim that's invalid and display a warning.

Also prevent another warning from occurring if the parse_ini_file
failed and $configArray is null.

Change-Id: Iba54220be266cb885e83cddfa6c8e9782aa77d01
2014-02-06 18:38:25 -08:00
tonythomas01
3afc76a4b5 Used DIRECTORY_SEPARATOR instead of '/' in GitInfo.php
Bug: 46482
Change-Id: If473bf60971b4c1a8c6a657d4cd7dd5a0bad659f
2014-02-07 01:28:05 +01:00
umherirrender
5ca5672aac Fixed spacing
- Place commas correct
- Moved comments
- Add space after if/foreach/catch
- Reformat some conditions
- Removed trailing spaces/tabs

Change-Id: I40ccda72c418c4a33fcd675773cb08d971510cdb
2013-12-01 20:58:51 +01:00
Timo Tijhof
90f6f5840e doc: Fix grammar in GitInfo documentation comment
Change-Id: I67da49398f1281b83700884475d364f6b30c05c8
2013-09-19 18:39:34 +02:00
Alex Monk
a1f1ccee35 Gitweb -> Gitblit
Change-Id: I54387a6ca5ed020e66594d4bf410a042d4ae010f
2013-06-07 23:05:13 +01:00
umherirrender
ef2f507d23 Fixed spacing in files direct in includes folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Ibb8dd102db045522d12ff939075ba7420d95ab6b
2013-04-21 06:38:49 +00:00
DaSch
e9e24cbfe7 Add git HEAD date to Special:Version for core and extensions
The patch adds the localised commit date of i) core and ii) extensions
in the Special:Version page tables. It requires the Git version control
system being installed, which is checked during the installation.

Introduces a new parameter for the git binary in DefaultSettings.php:
$wgGitBin = '/usr/bin/git';

Patch authored by DaSch <dasch@daschmedia.de> and updated and fixed
by Wikinaut<mail@tgries.de>.

Bug: 38783
Change-Id: I0931400ecacf91ed2ab4fc7aa46dceac17661768
2013-04-15 20:47:15 +00:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
umherirrender
b5e2ea0298 Do not read /.git if it is a directory
On my windows under eclipse with EGit there is a directory named .git,
but that gives warning, when read with file_get_contents:
Warning: file_get_contents(/.git) [function.file-get-contents]: failed
to open stream: Permission denied in \includes\GitInfo.php on line 49

Follow up Ieb79c0b4

Change-Id: I7c3ba323460a2fd3739d3912ee6420aa29311f4f
2013-02-27 18:43:57 +00:00
Kevin Israel
e951be59c6 Show HEADs for Git 1.7.8+ submodules
I implemented "the gitfile mechanism" in the GitInfo class so it
can access gitdirs for submodules again.

Bug: 44599
Change-Id: Ieb79c0b401a6bb0f5ca8bff98bb382a8c6ffbb01
2013-02-20 11:14:52 -05:00
Alexandre Emsenhuber
15e9fcca01 Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: Iaebd4e253ff3b35b568e9b394231a5691445ac95
2012-05-14 19:59:58 +02:00
saper
8bab490dec $wgGitRepositoryViewers to link to gitweb
My git remote is configured just to be ssh://review/mediawiki/core.git
and I have "review" set up in $HOME/.ssh/config.

Unfortunately, I need to change git remote URLs to make sure
the repository is linked from Special:Version.

This shouldn't be necessary; either we should fallback to the
official MediaWiki git repository or we should add the configuration
option to adapt to local needs.

Change-Id: I2e0b6470c16ec36d0e94cceab844f4a4c4334067
2012-05-06 22:12:14 +02:00
RobLa
576542a314 (bug 36361) Fix git links in Special:Version - removing extra space
Change-Id: I731e163e5f329b78402ed3c6307547c847264587
2012-05-01 22:07:35 -07:00
Simon Walker
6c29ec2921 Add GitViewers hook for extensions to add git viewers to SpecialVersion
This adds a GitViewers hook to GitInfo, and slightly refactors the
$viewers variable to be called through a function so the hook can be
called. This is so extensions can add their own git repository viewer
to the Special:Version git sha field.

Change-Id: Ifc8396984de6a51be85fb63cd9754d57333bde03
2012-04-16 16:57:58 +00:00
Reedy
2fcd7dbf7c Fixup/finish off function parameter documentation
Remove unused variable

Change-Id: I9b19388ded628c170d10ac371882a4debd845ea8
2012-04-13 04:10:46 +01:00
Alexandre Emsenhuber
17ccccda2a Follow-up I5b02aa914916f64492c85ce6dcc3272b6406551a (#4335), also put a link in the debug toolbar.
Now that there is a link on the revision hash in Special:Version, do the same in the debug toolbar.

Change-Id: I953ac70e17e72be68251e3908e164dfa46c68bf5
2012-04-10 22:44:26 +02:00
Antoine Musso
8196f3f11b makes gitweb URL points to full sha1
The URL we are crafting are using a short sha1 (7 chars long) which can
have some good chance of pointing to two different sha1. I have seen git
log to use 8 chars from time to time because of sha1 collisions, 62
occurences outu of 45315 commits as of now.

So to play it safe, this patch makes the URL points to the full sha1.

Follow https://gerrit.wikimedia.org/r/4335
5734eac351 (commit)
9afc1eff1c (merge)

Change-Id: Ic65d0ca89916fe43999b9e3f257d9f322198f9f8
2012-04-10 22:20:15 +02:00
grunny
08165793fc (bug 35751) Fix git revision links on Special:Version
When .git isn't used in the clone URL, links currently break

Change-Id: Ia69e1bfea91ef50c126896b374a083447db4481f
2012-04-06 23:56:26 +10:00
Alexandre Emsenhuber
5734eac351 (bug 35728) Git revisions are now linked on Special:Version
Change-Id: I5b02aa914916f64492c85ce6dcc3272b6406551a
2012-04-05 18:22:48 +02:00
Reedy
b5adbc772c Bug 35583 - GitInfo::isSHA1 returns true for non-sha1 values
Patch by Alexis

Change-Id: I6c69d017d2d6ad1237b0c34ffa8a7ae5fb518178
2012-03-29 15:38:36 +01:00
Daniel Friesen
36b1172147 Add GitInfo class.
This adds GitInfo which is used by Special:Version to get the SHA1 of
the git repo.
It's also useful for development to put blocks of config in
LocalSettings.php that only apply to branches where you are developing
large features:

  if ( GitInfo::currentBranch() == 'myrewriteproject' ) {
    // […]
  }

Change-Id: I2a76662bb40080be6556d4edf60ac6714f36a727
2012-03-23 15:55:12 +01:00