Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| MovedImportRevision | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| getText | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Import\LiquidThreadsApi; |
| 4 | |
| 5 | use Flow\Import\ImportException; |
| 6 | use MediaWiki\MediaWikiServices; |
| 7 | use MediaWiki\Utils\MWTimestamp; |
| 8 | |
| 9 | class MovedImportRevision extends ImportRevision { |
| 10 | /** |
| 11 | * Rewrites the '#REDIRECT [[...]]' of an autogenerated lqt moved |
| 12 | * thread stub into a template. While we don't re-write the link |
| 13 | * here, after importing the referenced thread LqtRedirector will |
| 14 | * make that Thread page a redirect to the Flow topic, essentially |
| 15 | * making these links still work. |
| 16 | * @return string |
| 17 | * @throws ImportException |
| 18 | */ |
| 19 | public function getText() { |
| 20 | $text = parent::getText(); |
| 21 | $content = MediaWikiServices::getInstance() |
| 22 | ->getContentHandlerFactory() |
| 23 | ->getContentHandler( CONTENT_MODEL_WIKITEXT ) |
| 24 | ->unserializeContent( $text ); |
| 25 | $target = $content->getRedirectTarget(); |
| 26 | if ( !$target ) { |
| 27 | throw new ImportException( "Could not detect redirect within: $text" ); |
| 28 | } |
| 29 | |
| 30 | // To get the new talk page that this belongs to we would need to query the api |
| 31 | // for the new topic, for now not bothering. |
| 32 | $template = wfMessage( 'flow-importer-lqt-moved-thread-template' )->inContentLanguage()->plain(); |
| 33 | $arguments = implode( |
| 34 | '|', |
| 35 | [ |
| 36 | 'author=' . parent::getAuthor(), |
| 37 | 'date=' . MWTimestamp::getInstance( |
| 38 | $this->apiResponse['timestamp'] |
| 39 | )->timestamp->format( 'Y-m-d' ), |
| 40 | 'title=' . $target->getPrefixedText(), |
| 41 | ] |
| 42 | ); |
| 43 | |
| 44 | return "{{{$template}|$arguments}}"; |
| 45 | } |
| 46 | } |