X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/actions/MarkpatrolledAction.php diff --git a/includes/actions/MarkpatrolledAction.php b/includes/actions/MarkpatrolledAction.php new file mode 100644 index 00000000..66bedb2b --- /dev/null +++ b/includes/actions/MarkpatrolledAction.php @@ -0,0 +1,139 @@ +getRequest()->getInt( 'rcid' ); + if ( $rcId ) { + $rc = RecentChange::newFromId( $rcId ); + } + if ( !$rc ) { + throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' ); + } + return $rc; + } + + protected function preText() { + $rc = $this->getRecentChange(); + $title = $rc->getTitle(); + $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); + + // Based on logentry-patrol-patrol (see PatrolLogFormatter) + $revId = $rc->getAttribute( 'rc_this_oldid' ); + $query = [ + 'curid' => $rc->getAttribute( 'rc_cur_id' ), + 'diff' => $revId, + 'oldid' => $rc->getAttribute( 'rc_last_oldid' ) + ]; + $revlink = $linkRenderer->makeLink( $title, $revId, [], $query ); + $pagelink = $linkRenderer->makeLink( $title, $title->getPrefixedText() ); + + return $this->msg( 'confirm-markpatrolled-top' )->params( + $title->getPrefixedText(), + // Provide pre-rendered link as parser would render [[:$1]] as bold non-link + Message::rawParam( $pagelink ), + Message::rawParam( $revlink ) + )->parse(); + } + + protected function alterForm( HTMLForm $form ) { + $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) ); + $form->setTokenSalt( 'patrol' ); + $form->setSubmitTextMsg( 'confirm-markpatrolled-button' ); + } + + /** + * @param array $data + * @return bool|array True for success, false for didn't-try, array of errors on failure + */ + public function onSubmit( $data ) { + $user = $this->getUser(); + $rc = $this->getRecentChange( $data ); + $errors = $rc->doMarkPatrolled( $user ); + + if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) { + throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' ); + } + + // Guess where the user came from + // TODO: Would be nice to see where the user actually came from + if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) { + $returnTo = 'Newpages'; + } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) { + $returnTo = 'Newfiles'; + } else { + $returnTo = 'Recentchanges'; + } + $return = SpecialPage::getTitleFor( $returnTo ); + + if ( in_array( [ 'markedaspatrollederror-noautopatrol' ], $errors ) ) { + $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrollederror' ) ); + $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' ); + $this->getOutput()->returnToMain( null, $return ); + return true; + } + + if ( $errors ) { + if ( !in_array( [ 'hookaborted' ], $errors ) ) { + throw new PermissionsError( 'patrol', $errors ); + } + // The hook itself has handled any output + return $errors; + } + + $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrolled' ) ); + $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() ); + $this->getOutput()->returnToMain( null, $return ); + return true; + } + + public function onSuccess() { + // Required by parent class. Redundant as our onSubmit handles output already. + } + + public function doesWrites() { + return true; + } +}