Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
77.78% |
49 / 63 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| SpecialNewPagesFeed | |
77.78% |
49 / 63 |
|
60.00% |
3 / 5 |
18.81 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
38 / 38 |
|
100.00% |
1 / 1 |
5 | |||
| getListViewHtml | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| maybeAddShowIpModule | |
13.33% |
2 / 15 |
|
0.00% |
0 / 1 |
49.66 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\PageTriage; |
| 4 | |
| 5 | use MediaWiki\Config\ConfigException; |
| 6 | use MediaWiki\Html\Html; |
| 7 | use MediaWiki\Html\TemplateParser; |
| 8 | use MediaWiki\MediaWikiServices; |
| 9 | use MediaWiki\Output\OutputPage; |
| 10 | use MediaWiki\Registration\ExtensionRegistry; |
| 11 | use MediaWiki\SpecialPage\SpecialPage; |
| 12 | use MediaWiki\User\Options\UserOptionsLookup; |
| 13 | |
| 14 | /** |
| 15 | * This file defines the SpecialNewPagesFeed class which handles the functionality for the |
| 16 | * New Pages Feed (Special:NewPagesFeed). |
| 17 | * |
| 18 | * @ingroup Extensions |
| 19 | * @author Ryan Kaldari |
| 20 | */ |
| 21 | class SpecialNewPagesFeed extends SpecialPage { |
| 22 | public function __construct( |
| 23 | private readonly UserOptionsLookup $userOptionsLookup, |
| 24 | ) { |
| 25 | parent::__construct( 'NewPagesFeed' ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Define what happens when the special page is loaded by the user. |
| 30 | * @param string $sub The subpage, if any |
| 31 | * @throws ConfigException |
| 32 | */ |
| 33 | public function execute( $sub ) { |
| 34 | $this->addHelpLink( 'Help:New_pages_feed' ); |
| 35 | |
| 36 | $config = $this->getConfig(); |
| 37 | |
| 38 | $request = $this->getRequest(); |
| 39 | $showOresFilters = PageTriageUtil::oresIsAvailable() && |
| 40 | ( $config->get( 'PageTriageEnableOresFilters' ) || $request->getBool( 'ores' ) ); |
| 41 | $showCopyvio = $showOresFilters && |
| 42 | ( $config->get( 'PageTriageEnableCopyvio' ) || $request->getBool( 'copyvio' ) ); |
| 43 | $this->setHeaders(); |
| 44 | $out = $this->getOutput(); |
| 45 | |
| 46 | // Output the title of the page |
| 47 | $out->setPageTitleMsg( $this->msg( 'newpagesfeed' ) ); |
| 48 | |
| 49 | // Load common interface css |
| 50 | $out->addModuleStyles( [ 'mediawiki.interface.helpers.styles' ] ); |
| 51 | |
| 52 | // Set the config flags in JavaScript |
| 53 | $globalVars = [ |
| 54 | 'pageTriageNamespaces' => PageTriageUtil::getNamespaces(), |
| 55 | 'wgPageTriageEnableExtendedFeatures' => $config->get( 'PageTriageEnableExtendedFeatures' ), |
| 56 | 'wgShowOresFilters' => $showOresFilters, |
| 57 | 'wgShowCopyvio' => $showCopyvio, |
| 58 | ]; |
| 59 | $out->addJsConfigVars( $globalVars ); |
| 60 | // Load the JS |
| 61 | $out->addModules( [ |
| 62 | 'ext.pageTriage.external', |
| 63 | 'ext.pageTriage.util', |
| 64 | 'ext.pageTriage.newPagesFeed' |
| 65 | ] ); |
| 66 | |
| 67 | $header = ''; |
| 68 | $header .= '<div id="mwe-pt-list-warnings" style="display: none;">'; |
| 69 | $parsedWelcomeMessage = $this->msg( |
| 70 | 'pagetriage-welcome', |
| 71 | $config->get( 'PageTriageLearnMoreUrl' ), |
| 72 | $config->get( 'PageTriageFeedbackUrl' ) |
| 73 | )->parse(); |
| 74 | $header .= Html::rawElement( 'div', [ 'class' => 'plainlinks' ], $parsedWelcomeMessage ); |
| 75 | $header .= '</div>'; |
| 76 | $out->addHTML( $header ); |
| 77 | $out->addInlineStyle( |
| 78 | '.client-nojs #mwe-pt-list-view, .client-js #mwe-pt-list-view-no-js { display: none; }' |
| 79 | ); |
| 80 | // Output the HTML for the triage interface |
| 81 | $out->addHTML( $this->getListViewHtml() ); |
| 82 | $this->maybeAddShowIpModule( $out ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Get the list control nav HTML. |
| 87 | * |
| 88 | * @return string |
| 89 | */ |
| 90 | private function getListViewHtml() { |
| 91 | $templateParser = new TemplateParser( __DIR__ . '/templates' ); |
| 92 | |
| 93 | // HTML for this is located in includes/templates/ListView.mustache |
| 94 | return $templateParser->processTemplate( |
| 95 | 'ListView', |
| 96 | [ |
| 97 | 'pagetriage-please-wait' => $this->msg( 'pagetriage-please-wait' ), |
| 98 | 'pagetriage-js-required' => $this->msg( 'pagetriage-js-required' ), |
| 99 | ] |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @param OutputPage $out |
| 105 | * @return void |
| 106 | */ |
| 107 | private function maybeAddShowIpModule( OutputPage $out ): void { |
| 108 | if ( !ExtensionRegistry::getInstance()->isLoaded( 'CheckUser' ) ) { |
| 109 | return; |
| 110 | } |
| 111 | if ( !MediaWikiServices::getInstance()->getTempUserConfig()->isKnown() ) { |
| 112 | return; |
| 113 | } else { |
| 114 | $authority = $out->getAuthority(); |
| 115 | // If the user isn't authorized to view temporary account IP data without having to accept the |
| 116 | // agreement, ensure they have relevant rights and have accepted the agreement. |
| 117 | if ( !$authority->isAllowed( 'checkuser-temporary-account-no-preference' ) ) { |
| 118 | if ( !$authority->isAllowed( 'checkuser-temporary-account' ) ) { |
| 119 | return; |
| 120 | } |
| 121 | if ( !$this->userOptionsLookup->getOption( $authority->getUser(), |
| 122 | 'checkuser-temporary-account-enable' ) ) { |
| 123 | return; |
| 124 | } |
| 125 | } |
| 126 | $block = $authority->getBlock(); |
| 127 | if ( $block !== null && $block->isSitewide() ) { |
| 128 | return; |
| 129 | } |
| 130 | } |
| 131 | $out->addModules( [ 'ext.pageTriage.showIp' ] ); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @inheritDoc |
| 136 | */ |
| 137 | protected function getGroupName() { |
| 138 | return 'changes'; |
| 139 | } |
| 140 | |
| 141 | } |