Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AbstractContentHistoryAction | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| getPageTitle | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WikiLambda history action for Abstract Wiki content, just to set a nicer title |
| 4 | * |
| 5 | * @file |
| 6 | * @ingroup Extensions |
| 7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 8 | * @license MIT |
| 9 | */ |
| 10 | |
| 11 | namespace MediaWiki\Extension\WikiLambda\AbstractContent; |
| 12 | |
| 13 | use MediaWiki\Actions\HistoryAction; |
| 14 | use MediaWiki\Extension\WikiLambda\WikiLambdaServices; |
| 15 | |
| 16 | class AbstractContentHistoryAction extends HistoryAction { |
| 17 | /** |
| 18 | * Returns a formatted page title for the history view, using the Wikibase label |
| 19 | * for the entity if available. Falls back to the Abstract Article history title format |
| 20 | * ("Revision history of QID") if the page doesn't exist, the label can't be fetched, |
| 21 | * or anything goes wrong. |
| 22 | * |
| 23 | * @inheritDoc |
| 24 | */ |
| 25 | protected function getPageTitle() { |
| 26 | if ( !$this->getTitle()->exists() ) { |
| 27 | return parent::getPageTitle(); |
| 28 | } |
| 29 | |
| 30 | $entityId = $this->getTitle()->getText(); |
| 31 | $languageCode = $this->getLanguage()->getCode(); |
| 32 | |
| 33 | $entityLookup = WikiLambdaServices::getWikidataEntityLookup(); |
| 34 | $label = $entityLookup->resolveAbstractLabel( $entityId, $languageCode ); |
| 35 | |
| 36 | if ( $label === null ) { |
| 37 | // (T426833) When no Wikibase label is available, still render the Abstract Article |
| 38 | // history title format ("Revision history of QID"), so that /wiki/, edit, history and |
| 39 | // Special:ViewAbstract stay consistent. |
| 40 | return $this->msg( 'wikilambda-abstract-content-history-title-no-label' ) |
| 41 | ->params( $entityId ); |
| 42 | } |
| 43 | |
| 44 | return $this->msg( 'wikilambda-abstract-content-history-title' ) |
| 45 | ->rawParams( htmlspecialchars( $label ), $entityId ); |
| 46 | } |
| 47 | } |