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