Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialReadingLists | |
0.00% |
0 / 52 |
|
0.00% |
0 / 5 |
462 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
executeReadingList | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
272 | |||
getAssociatedNavigationLinks | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ReadingLists; |
4 | |
5 | use MediaWiki\Html\Html; |
6 | use MediaWiki\Message\Message; |
7 | use MediaWiki\SpecialPage\SpecialPage; |
8 | use MediaWiki\SpecialPage\UnlistedSpecialPage; |
9 | use MediaWiki\User\User; |
10 | use PermissionsError; |
11 | |
12 | class SpecialReadingLists extends UnlistedSpecialPage { |
13 | /** |
14 | * Construct function |
15 | */ |
16 | public function __construct() { |
17 | parent::__construct( 'ReadingLists' ); |
18 | } |
19 | |
20 | /** |
21 | * Render readinglist(s) app shell |
22 | * |
23 | * @param Message $pageTitle |
24 | */ |
25 | private function executeReadingList( Message $pageTitle ) { |
26 | $out = $this->getOutput(); |
27 | $out->addModuleStyles( [ 'special.readinglist.styles' ] ); |
28 | $out->addModules( [ 'special.readinglist.scripts' ] ); |
29 | $out->setPageTitleMsg( $pageTitle ); |
30 | $html = Html::errorBox( |
31 | $this->msg( 'readinglists-error' )->text(), |
32 | '', |
33 | 'reading-list__errorbox' |
34 | ); |
35 | $html .= Html::element( 'div', [ 'id' => 'reading-list-container' ], |
36 | $this->msg( 'readinglists-loading' )->text() |
37 | ); |
38 | $out->addHTML( $html ); |
39 | } |
40 | |
41 | /** |
42 | * Render Special Page ReadingLists |
43 | * @param string $par Parameter submitted as subpage |
44 | */ |
45 | public function execute( $par = '' ) { |
46 | $out = $this->getOutput(); |
47 | $config = $out->getConfig(); |
48 | // If the feature isn't ready, redirect to Special:SpecialPages |
49 | $params = $par ? explode( '/', $par ) : []; |
50 | $listOwner = $params[0] ?? null; |
51 | $listId = $params[1] ?? null; |
52 | $req = $this->getRequest(); |
53 | $exportFeature = $req->getText( 'limport' ) !== '' || $req->getText( 'lexport' ) !== ''; |
54 | $user = $this->getUser(); |
55 | $this->setHeaders(); |
56 | $this->outputHeader(); |
57 | |
58 | if ( !$user->isNamed() && !$exportFeature ) { |
59 | $this->requireNamedUser( 'reading-list-purpose' ); |
60 | } else { |
61 | if ( $listOwner || $exportFeature ) { |
62 | $owner = !$listOwner ? null : User::newFromName( $listOwner ); |
63 | $privateEnabled = $config->get( 'ReadingListsWebAuthenticatedPreviews' ); |
64 | $isWatchlist = $listId === '-10'; |
65 | $canDisplayPrivateLists = $privateEnabled && $owner && |
66 | $owner->getId() === $user->getId(); |
67 | $pageTitle = $isWatchlist ? |
68 | $this->msg( 'watchlist' ) : |
69 | $this->msg( 'readinglists-special-title' ); |
70 | if ( !$privateEnabled ) { |
71 | $out->addHtmlClasses( 'mw-special-readinglist-watchlist-only' ); |
72 | } |
73 | if ( $exportFeature ) { |
74 | $pageTitle = $this->msg( 'readinglists-special-title-imported' ); |
75 | $out->addHtmlClasses( 'mw-special-readinglist-export-only' ); |
76 | } |
77 | if ( $exportFeature || $isWatchlist || $privateEnabled ) { |
78 | $this->executeReadingList( $pageTitle ); |
79 | } else { |
80 | throw new PermissionsError( 'action-readinglist-private' ); |
81 | } |
82 | } else { |
83 | $out = $this->getOutput(); |
84 | $out->redirect( SpecialPage::getTitleFor( 'ReadingLists', |
85 | $user->getName() )->getLocalURL() ); |
86 | } |
87 | } |
88 | } |
89 | |
90 | /** |
91 | * @inheritDoc |
92 | */ |
93 | public function getAssociatedNavigationLinks(): array { |
94 | $config = $this->getConfig(); |
95 | $privateEnabled = $config->get( 'ReadingListsWebAuthenticatedPreviews' ); |
96 | return $privateEnabled ? [ |
97 | self::getTitleFor( $this->getName() )->getPrefixedText(), |
98 | ] : []; |
99 | } |
100 | |
101 | /** |
102 | * @return string |
103 | */ |
104 | protected function getGroupName() { |
105 | return 'pages'; |
106 | } |
107 | } |