| 1 |
<?php |
| 2 |
|
| 3 |
r |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
use MediaWiki\Context\IContextSource; |
| 24 |
use MediaWiki\HTMLForm\HTMLForm; |
| 25 |
use MediaWiki\Linker\LinkRenderer; |
| 26 |
use MediaWiki\Message\Message; |
| 27 |
use MediaWiki\SpecialPage\SpecialPage; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class MarkpatrolledAction extends FormAction { |
| 35 |
|
| 36 |
private LinkRenderer $linkRenderer; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function __construct( |
| 44 |
Article $article, |
| 45 |
IContextSource $context, |
| 46 |
LinkRenderer $linkRenderer |
| 47 |
) { |
| 48 |
parent::__construct( $article, $context ); |
| 49 |
$this->linkRenderer = $linkRenderer; |
| 50 |
} |
| 51 |
|
| 52 |
public function getName() { |
| 53 |
return 'markpatrolled'; |
| 54 |
} |
| 55 |
|
| 56 |
protected function getDescription() { |
| 57 |
|
| 58 |
return ''; |
| 59 |
} |
| 60 |
|
| 61 |
public function getRestriction() { |
| 62 |
return 'patrol'; |
| 63 |
} |
| 64 |
|
| 65 |
protected function usesOOUI() { |
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
protected function getRecentChange( $data = null ) { |
| 70 |
$rc = null; |
| 71 |
|
| 72 |
$rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' ); |
| 73 |
if ( $rcId ) { |
| 74 |
$rc = RecentChange::newFromId( $rcId ); |
| 75 |
} |
| 76 |
if ( !$rc ) { |
| 77 |
throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' ); |
| 78 |
} |
| 79 |
return $rc; |
| 80 |
} |
| 81 |
|
| 82 |
protected function preText() { |
| 83 |
$rc = $this->getRecentChange(); |
| 84 |
$title = $rc->getTitle(); |
| 85 |
|
| 86 |
|
| 87 |
$revId = $rc->getAttribute( 'rc_this_oldid' ); |
| 88 |
$query = [ |
| 89 |
'curid' => $rc->getAttribute( 'rc_cur_id' ), |
| 90 |
'diff' => $revId, |
| 91 |
'oldid' => $rc->getAttribute( 'rc_last_oldid' ) |
| 92 |
]; |
| 93 |
$revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query ); |
| 94 |
$pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() ); |
| 95 |
|
| 96 |
return $this->msg( 'confirm-markpatrolled-top' )->params( |
| 97 |
$title->getPrefixedText(), |
| 98 |
|
| 99 |
Message::rawParam( $pagelink ), |
| 100 |
Message::rawParam( $revlink ) |
| 101 |
)->parse(); |
| 102 |
} |
| 103 |
|
| 104 |
protected function alterForm( HTMLForm $form ) { |
| 105 |
$form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) ); |
| 106 |
$form->setTokenSalt( 'patrol' ); |
| 107 |
$form->setSubmitTextMsg( 'confirm-markpatrolled-button' ); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public function onSubmit( $data ) { |
| 115 |
$rc = $this->getRecentChange( $data ); |
| 116 |
$status = $rc->markPatrolled( $this->getAuthority() ); |
| 117 |
|
| 118 |
if ( $status->hasMessage( 'rcpatroldisabled' ) ) { |
| 119 |
throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' ); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) { |
| 125 |
$returnTo = 'Newpages'; |
| 126 |
} elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) { |
| 127 |
$returnTo = 'Newfiles'; |
| 128 |
} else { |
| 129 |
$returnTo = 'Recentchanges'; |
| 130 |
} |
| 131 |
$return = SpecialPage::getTitleFor( $returnTo ); |
| 132 |
|
| 133 |
if ( $status->hasMessage( 'markedaspatrollederror-noautopatrol' ) ) { |
| 134 |
$this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrollederror' ) ); |
| 135 |
$this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' ); |
| 136 |
$this->getOutput()->returnToMain( null, $return ); |
| 137 |
return true; |
| 138 |
} |
| 139 |
|
| 140 |
if ( !$status->isGood() ) { |
| 141 |
if ( !$status->hasMessage( 'hookaborted' ) ) { |
| 142 |
throw new PermissionsError( 'patrol', $status ); |
| 143 |
} |
| 144 |
|
| 145 |
return $status; |
| 146 |
} |
| 147 |
|
| 148 |
$this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrolled' ) ); |
| 149 |
$this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() ); |
| 150 |
$this->getOutput()->returnToMain( null, $return ); |
| 151 |
return true; |
| 152 |
} |
| 153 |
|
| 154 |
public function onSuccess() { |
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
public function doesWrites() { |
| 159 |
return true; |
| 160 |
} |
| 161 |
} |