Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SpecialMyWiki | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | /** |
3 | * Special page to go to a page on one's test wiki as set in the |
4 | * preferences. Goes to the default Main Page if the test wiki or |
5 | * an unprefixed page if the test wiki preference is set no |
6 | * None/All or Incubator. |
7 | * |
8 | * @file |
9 | * @ingroup SpecialPage |
10 | * @author Robin Pepermans (SPQRobin) |
11 | * @author Jon Harald Søby |
12 | */ |
13 | |
14 | namespace MediaWiki\Extension\WikimediaIncubator; |
15 | |
16 | use MediaWiki\SpecialPage\UnlistedSpecialPage; |
17 | use MediaWiki\Title\Title; |
18 | |
19 | class SpecialMyWiki extends UnlistedSpecialPage { |
20 | |
21 | public function __construct() { |
22 | parent::__construct( 'MyWiki' ); |
23 | } |
24 | |
25 | public function execute( $subpage ) { |
26 | $title = ''; |
27 | // Remove a single initial colon from the subpage if there are any. |
28 | // If there are several, that's an invalid title, which is handled |
29 | // differently. |
30 | $subpage = $subpage ? trim( $subpage ) : ''; |
31 | $subpage = preg_replace( '/^:(?!:)/', '', $subpage ); |
32 | // We want to pass any parameters that are used, except for 'title' |
33 | $params = $this->getRequest()->getValues(); |
34 | unset( $params['title'] ); |
35 | |
36 | $userHasTestWiki = WikimediaIncubator::isContentProject( $this->getUser() ); |
37 | $prefix = $userHasTestWiki ? WikimediaIncubator::displayPrefix() : ''; |
38 | |
39 | if ( $subpage === '' ) { |
40 | if ( $this->getRequest()->getVal( 'goto' ) !== 'infopage' ) { |
41 | $params['goto'] = 'mainpage'; |
42 | } |
43 | |
44 | if ( !$userHasTestWiki ) { |
45 | $title = Title::newMainPage(); |
46 | } else { |
47 | $title = Title::newFromText( $prefix ); |
48 | } |
49 | } elseif ( Title::newFromText( $subpage ) ) { |
50 | $target = Title::newFromText( $subpage ); |
51 | $targetNs = $target->getNamespace(); |
52 | $targetPagename = $target->getBaseText(); |
53 | |
54 | $originalPagename = $subpage; |
55 | // Get the original pagename without namespace |
56 | // if it is not an article |
57 | if ( $targetNs !== 0 ) { |
58 | $originalPagename = explode( ':', $originalPagename, 2 )[1]; |
59 | } |
60 | // Remove any initial spaces or underscores from the given title |
61 | $originalPagename = preg_replace( '/^[_\s]+/', '', $originalPagename ); |
62 | |
63 | // The given page name may have been given an uppercase initial |
64 | // by getBaseText above. If they are not equal, prefer the one that was |
65 | // given. |
66 | // TODO: Whether or not the title's initial should be uppercased |
67 | // should depend on the project (Wiktionaries are lowercase), but also |
68 | // language (some languages don't use uppercase initially). |
69 | if ( $originalPagename !== $targetPagename ) { |
70 | $targetPagename = $originalPagename; |
71 | } |
72 | |
73 | if ( $userHasTestWiki ) { |
74 | $title = WikimediaIncubator::displayPrefixedTitle( $targetPagename, $targetNs, false ); |
75 | } else { |
76 | $title = $target; |
77 | } |
78 | } else { |
79 | // Fallback in case the given title is invalid |
80 | $title = Title::newMainPage(); |
81 | } |
82 | |
83 | $this->getOutput()->redirect( $title->getLocalURL( $params ) ); |
84 | } |
85 | } |