Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SimpleSourceWork | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
newFromPageId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadFromDb | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CreditSource; |
4 | |
5 | use MediaWiki\MediaWikiServices; |
6 | |
7 | class SimpleSourceWork { |
8 | /** @var string|null */ |
9 | public $mId; |
10 | /** @var string|null */ |
11 | public $mUri; |
12 | /** @var string|null */ |
13 | public $mTs; |
14 | /** @var string|null */ |
15 | public $mTitle; |
16 | /** @var string|null */ |
17 | public $mSiteName; |
18 | /** @var string|null */ |
19 | public $mSiteShortName; |
20 | /** @var string|null */ |
21 | public $mSiteUri; |
22 | |
23 | /** |
24 | * @param string|int $pageId |
25 | * @param int $limit Limits the max length of the returned array |
26 | * @return SimpleSourceWork[] |
27 | */ |
28 | public static function newFromPageId( $pageId, $limit = 10 ) { |
29 | return self::loadFromDb( $pageId, $limit ); |
30 | } |
31 | |
32 | /** |
33 | * @param string|int $pageId |
34 | * @param int $limit Limits the max length of the returned array |
35 | * @return SimpleSourceWork[] |
36 | */ |
37 | protected static function loadFromDb( $pageId, $limit = 10 ) { |
38 | $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
39 | |
40 | $rows = $dbr->newSelectQueryBuilder() |
41 | ->select( [ |
42 | 'srcwork_id', 'srcwork_uri_part', 'srcwork_date', 'srcwork_title', |
43 | 'sws_name', 'sws_short_name', 'sws_site_uri', 'sws_work_uri' |
44 | ] ) |
45 | ->from( 'revision' ) |
46 | ->join( 'revsrc', null, 'revsrc_revid = rev_id' ) |
47 | ->join( 'srcwork', null, 'srcwork_id = revsrc_srcworkid' ) |
48 | ->leftJoin( 'swsite', null, 'srcwork_site = sws_id' ) |
49 | ->where( [ 'rev_page' => $pageId ] ) |
50 | ->limit( $limit ) |
51 | ->caller( __METHOD__ ) |
52 | ->fetchResultSet(); |
53 | |
54 | $sources = []; |
55 | foreach ( $rows as $row ) { |
56 | $me = new self; |
57 | $me->mId = $row->srcwork_id; |
58 | $me->mUri = $row->sws_work_uri . $row->srcwork_uri_part; |
59 | $me->mTs = $row->srcwork_date; |
60 | $me->mTitle = $row->srcwork_title; |
61 | $me->mSiteName = $row->sws_name; |
62 | $me->mSiteShortName = $row->sws_short_name; |
63 | $me->mSiteUri = $row->sws_site_uri; |
64 | |
65 | $sources[] = $me; |
66 | } |
67 | |
68 | return $sources; |
69 | } |
70 | } |