Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| LegacyArticleIdAccess | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| getArticleId | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getWikiId | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Page; |
| 4 | |
| 5 | use MediaWiki\Title\Title; |
| 6 | |
| 7 | /** |
| 8 | * Convenience trait for conversion to PageIdentity. |
| 9 | * |
| 10 | * For the cross-wiki aware code, this should be used instead of PageIdentity::getId |
| 11 | * until Title is dropped. Before transition to PageIdentity, Title could exist for |
| 12 | * foreign wikis with no indication about it (Title does not have $wikiId). |
| 13 | * It was very brittle, but it worked. Until Title is deprecated in the codebase, |
| 14 | * most of the PageIdentity instances passed around are Titles. So for cross-wiki access, |
| 15 | * stricter domain validation of PageIdentity::getId will break wikis. |
| 16 | * |
| 17 | * Additionally, loose checks on Title regarding whether the page can exist or not |
| 18 | * have been depended upon in a number of places in the codebase. |
| 19 | * |
| 20 | * This trait is only supposed to be used in cross-wiki aware code, and only exists until |
| 21 | * code up the stack is guaranteed not to pass Title. |
| 22 | * |
| 23 | * @internal |
| 24 | */ |
| 25 | trait LegacyArticleIdAccess { |
| 26 | /** |
| 27 | * Before transition to PageIdentity, Title could exist for foreign wikis. |
| 28 | * It was very brittle, but it worked. Until Title is deprecated in the codebase, |
| 29 | * most of the PageIdentity instances passed around are Titles. |
| 30 | * So for cross-wiki access, stricter domain validation of PageIdentity::getId |
| 31 | * will break wikis. This method supposed to exist only for the transition period |
| 32 | * and will be removed after. |
| 33 | * |
| 34 | * Additionally, loose checks on Title regarding whether the page can exist or not |
| 35 | * have been depended upon in a number of places in the codebase. |
| 36 | * |
| 37 | * @param PageIdentity $title |
| 38 | * @return int |
| 39 | */ |
| 40 | protected function getArticleId( PageIdentity $title ): int { |
| 41 | if ( $title instanceof Title ) { |
| 42 | return $title->getArticleID(); |
| 43 | } |
| 44 | return $title->getId( $this->getWikiId() ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get the ID of the wiki this revision belongs to. |
| 49 | * |
| 50 | * @return string|false The wiki's logical name, of false to indicate the local wiki. |
| 51 | */ |
| 52 | abstract protected function getWikiId(); |
| 53 | } |