Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ZObjectHistoryAction | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| getPageTitle | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WikiLambda history action for ZObjects, 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; |
| 12 | |
| 13 | use Exception; |
| 14 | use MediaWiki\Actions\HistoryAction; |
| 15 | |
| 16 | class ZObjectHistoryAction extends HistoryAction { |
| 17 | /** |
| 18 | * @inheritDoc |
| 19 | */ |
| 20 | protected function getPageTitle() { |
| 21 | // Fallback to parent if the page doesn't exist yet, as we have nothing to do. |
| 22 | if ( !$this->getTitle()->exists() ) { |
| 23 | return parent::getPageTitle(); |
| 24 | } |
| 25 | |
| 26 | try { |
| 27 | $zObjectStore = WikiLambdaServices::getZObjectStore(); |
| 28 | $targetZObject = $zObjectStore->fetchZObjectByTitle( $this->getTitle() ); |
| 29 | } catch ( Exception ) { |
| 30 | // Something went wrong (e.g. corrupted ZObject), so fall back. |
| 31 | return parent::getPageTitle(); |
| 32 | } |
| 33 | |
| 34 | // Fallback to parent if somehow after all that it's not loadable. |
| 35 | if ( !$targetZObject ) { |
| 36 | return parent::getPageTitle(); |
| 37 | } |
| 38 | |
| 39 | $label = $targetZObject->getLabels()->buildStringForLanguage( $this->getLanguage() ) |
| 40 | ->fallbackWithEnglish() |
| 41 | ->placeholderNoFallback() |
| 42 | ->getString(); |
| 43 | |
| 44 | return $this->msg( 'wikilambda-history-title' ) |
| 45 | ->rawParams( htmlspecialchars( $label ?? '' ), $this->getTitle()->getText() ); |
| 46 | } |
| 47 | |
| 48 | } |