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