Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
MW | |
0.00% |
0 / 17 |
|
0.00% |
0 / 7 |
72 | |
0.00% |
0 / 1 |
srv | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
wan | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
title | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
file | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
page | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
rev | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | use MediaWiki\Revision\RevisionRecord; |
5 | use MediaWiki\User\User; |
6 | |
7 | /** |
8 | * Helper class to reduce typing in manual debugging tools like shell.php. |
9 | * @internal must not be used in code, anywhere |
10 | */ |
11 | class MW { |
12 | |
13 | public static function srv(): MediaWikiServices { |
14 | return MediaWikiServices::getInstance(); |
15 | } |
16 | |
17 | public static function wan(): WANObjectCache { |
18 | return self::srv()->getMainWANObjectCache(); |
19 | } |
20 | |
21 | public static function user( string $username ): User { |
22 | $user = self::srv()->getUserFactory()->newFromName( $username ); |
23 | if ( !$user ) { |
24 | throw new DomainException( "Invalid username: $username" ); |
25 | } |
26 | // preload so dumping the object is more informative |
27 | $user->load(); |
28 | return $user; |
29 | } |
30 | |
31 | public static function title( string $title ): Title { |
32 | $title = self::srv()->getTitleFactory()->newFromTextThrow( $title ); |
33 | // preload so dumping the object is more informative |
34 | $title->getArticleID(); |
35 | return $title; |
36 | } |
37 | |
38 | public static function file( string $filename ): File { |
39 | $file = self::srv()->getRepoGroup()->findFile( $filename ); |
40 | $file->load(); |
41 | return $file; |
42 | } |
43 | |
44 | public static function page( string $title ): WikiPage { |
45 | $page = self::srv()->getWikiPageFactory()->newFromTitle( self::title( $title ) ); |
46 | $page->loadPageData(); |
47 | return $page; |
48 | } |
49 | |
50 | public static function rev( int $id ): ?RevisionRecord { |
51 | return self::srv()->getRevisionStore()->getRevisionById( $id ); |
52 | } |
53 | |
54 | } |