Debian Codegraph @

includes/debug/MW.php

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