Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ImportRevision | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getText | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| getTimestamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAuthor | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getObjectKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Import\LiquidThreadsApi; |
| 4 | |
| 5 | use Flow\Import\IImportObject; |
| 6 | use Flow\Import\IObjectRevision; |
| 7 | use MediaWiki\User\User; |
| 8 | |
| 9 | class ImportRevision implements IObjectRevision { |
| 10 | /** @var IImportObject */ |
| 11 | protected $parent; |
| 12 | |
| 13 | /** @var array */ |
| 14 | protected $apiResponse; |
| 15 | |
| 16 | /** |
| 17 | * @var User Account used when the imported revision is by a suppressed user |
| 18 | */ |
| 19 | protected $scriptUser; |
| 20 | |
| 21 | /** |
| 22 | * Creates an ImportRevision based on a MW page revision |
| 23 | * |
| 24 | * @param array $apiResponse An element from api.query.revisions |
| 25 | * @param IImportObject $parentObject |
| 26 | * @param User $scriptUser Account used when the imported revision is by a suppressed user |
| 27 | */ |
| 28 | public function __construct( array $apiResponse, IImportObject $parentObject, User $scriptUser ) { |
| 29 | $this->apiResponse = $apiResponse; |
| 30 | $this->parent = $parentObject; |
| 31 | $this->scriptUser = $scriptUser; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @return string |
| 36 | */ |
| 37 | public function getText() { |
| 38 | $contentKey = 'content'; |
| 39 | |
| 40 | $content = $this->apiResponse[$contentKey]; |
| 41 | |
| 42 | if ( isset( $this->apiResponse['userhidden'] ) ) { |
| 43 | $template = wfMessage( |
| 44 | 'flow-importer-lqt-suppressed-user-template' |
| 45 | )->inContentLanguage()->plain(); |
| 46 | |
| 47 | $content .= "\n\n{{{$template}}}"; |
| 48 | } |
| 49 | |
| 50 | return $content; |
| 51 | } |
| 52 | |
| 53 | public function getTimestamp() { |
| 54 | return wfTimestamp( TS_MW, $this->apiResponse['timestamp'] ); |
| 55 | } |
| 56 | |
| 57 | public function getAuthor() { |
| 58 | if ( isset( $this->apiResponse['userhidden'] ) ) { |
| 59 | return $this->scriptUser->getName(); |
| 60 | } else { |
| 61 | return $this->apiResponse['user']; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | public function getObjectKey() { |
| 66 | return $this->parent->getObjectKey() . ':rev:' . $this->apiResponse['revid']; |
| 67 | } |
| 68 | } |