X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialMergeHistory.php;h=b916c1fc7860bfe2ed35ade8733dd90dcad0b6a9;hb=356b3420d6908f91510aa0cd94f3a363be7f8999;hp=058d1ced46943f220e926fc7f032650e56e9d52e;hpb=7160234ab2976d9ef7c36cb16f2101059388f2f2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index 058d1ced46..b916c1fc78 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -28,14 +28,38 @@ * @ingroup SpecialPage */ class SpecialMergeHistory extends SpecialPage { - /** @var FormOptions */ - protected $mOpts; + /** @var string */ + protected $mAction; - /** @var Status */ - protected $mStatus; + /** @var string */ + protected $mTarget; - /** @var Title|null */ - protected $mTargetObj, $mDestObj; + /** @var string */ + protected $mDest; + + /** @var string */ + protected $mTimestamp; + + /** @var int */ + protected $mTargetID; + + /** @var int */ + protected $mDestID; + + /** @var string */ + protected $mComment; + + /** @var bool Was posted? */ + protected $mMerge; + + /** @var bool Was submitted? */ + protected $mSubmitted; + + /** @var Title */ + protected $mTargetObj; + + /** @var Title */ + protected $mDestObj; /** @var int[] */ public $prevId; @@ -48,106 +72,124 @@ class SpecialMergeHistory extends SpecialPage { return true; } + /** + * @return void + */ + private function loadRequestParams() { + $request = $this->getRequest(); + $this->mAction = $request->getVal( 'action' ); + $this->mTarget = $request->getVal( 'target' ); + $this->mDest = $request->getVal( 'dest' ); + $this->mSubmitted = $request->getBool( 'submitted' ); + + $this->mTargetID = intval( $request->getVal( 'targetID' ) ); + $this->mDestID = intval( $request->getVal( 'destID' ) ); + $this->mTimestamp = $request->getVal( 'mergepoint' ); + if ( !preg_match( '/[0-9]{14}/', $this->mTimestamp ) ) { + $this->mTimestamp = ''; + } + $this->mComment = $request->getText( 'wpComment' ); + + $this->mMerge = $request->wasPosted() + && $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ); + + // target page + if ( $this->mSubmitted ) { + $this->mTargetObj = Title::newFromText( $this->mTarget ); + $this->mDestObj = Title::newFromText( $this->mDest ); + } else { + $this->mTargetObj = null; + $this->mDestObj = null; + } + } + public function execute( $par ) { $this->useTransactionalTimeLimit(); $this->checkPermissions(); $this->checkReadOnly(); + $this->loadRequestParams(); + $this->setHeaders(); $this->outputHeader(); - $this->addHelpLink( 'Help:Merge history' ); - - $opts = new FormOptions(); - - $opts->add( 'target', '' ); - $opts->add( 'dest', '' ); - $opts->add( 'target', '' ); - $opts->add( 'mergepoint', '' ); - $opts->add( 'reason', '' ); - $opts->add( 'merge', false ); - - $opts->fetchValuesFromRequest( $this->getRequest() ); - - $target = $opts->getValue( 'target' ); - $dest = $opts->getValue( 'dest' ); - $targetObj = Title::newFromText( $target ); - $destObj = Title::newFromText( $dest ); - $status = Status::newGood(); - - $this->mOpts = $opts; - $this->mTargetObj = $targetObj; - $this->mDestObj = $destObj; - - if ( $opts->getValue( 'merge' ) && $targetObj && $destObj ) { + if ( $this->mTargetID && $this->mDestID && $this->mAction == 'submit' && $this->mMerge ) { $this->merge(); return; } - if ( $target === '' && $dest === '' ) { + if ( !$this->mSubmitted ) { $this->showMergeForm(); return; } - if ( !$targetObj instanceof Title ) { - $status->merge( Status::newFatal( 'mergehistory-invalid-source' ) ); - } elseif ( !$targetObj->exists() ) { - $status->merge( Status::newFatal( 'mergehistory-no-source', - wfEscapeWikiText( $targetObj->getPrefixedText() ) - ) ); + $errors = []; + if ( !$this->mTargetObj instanceof Title ) { + $errors[] = $this->msg( 'mergehistory-invalid-source' )->parseAsBlock(); + } elseif ( !$this->mTargetObj->exists() ) { + $errors[] = $this->msg( 'mergehistory-no-source', + wfEscapeWikiText( $this->mTargetObj->getPrefixedText() ) + )->parseAsBlock(); } - if ( !$destObj instanceof Title ) { - $status->merge( Status::newFatal( 'mergehistory-invalid-destination' ) ); - } elseif ( !$destObj->exists() ) { - $status->merge( Status::newFatal( 'mergehistory-no-destination', - wfEscapeWikiText( $destObj->getPrefixedText() ) - ) ); + if ( !$this->mDestObj instanceof Title ) { + $errors[] = $this->msg( 'mergehistory-invalid-destination' )->parseAsBlock(); + } elseif ( !$this->mDestObj->exists() ) { + $errors[] = $this->msg( 'mergehistory-no-destination', + wfEscapeWikiText( $this->mDestObj->getPrefixedText() ) + )->parseAsBlock(); } - if ( $targetObj && $destObj && $targetObj->equals( $destObj ) ) { - $status->merge( Status::newFatal( 'mergehistory-same-destination' ) ); + if ( $this->mTargetObj && $this->mDestObj && $this->mTargetObj->equals( $this->mDestObj ) ) { + $errors[] = $this->msg( 'mergehistory-same-destination' )->parseAsBlock(); } - $this->mStatus = $status; - - $this->showMergeForm(); - - if ( $status->isOK() ) { + if ( count( $errors ) ) { + $this->showMergeForm(); + $this->getOutput()->addHTML( implode( "\n", $errors ) ); + } else { $this->showHistory(); } } function showMergeForm() { - $formDescriptor = [ - 'target' => [ - 'type' => 'title', - 'name' => 'target', - 'label-message' => 'mergehistory-from', - 'required' => true, - ], - - 'dest' => [ - 'type' => 'title', - 'name' => 'dest', - 'label-message' => 'mergehistory-into', - 'required' => true, - ], - ]; - - $form = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) - ->setIntro( $this->msg( 'mergehistory-header' ) ) - ->setWrapperLegendMsg( 'mergehistory-box' ) - ->setSubmitTextMsg( 'mergehistory-go' ) - ->setMethod( 'post' ) - ->prepareForm() - ->displayForm( $this->mStatus ); + $out = $this->getOutput(); + $out->addWikiMsg( 'mergehistory-header' ); + + $out->addHTML( + Xml::openElement( 'form', [ + 'method' => 'get', + 'action' => wfScript() ] ) . + '
' . + '' + ); + + $this->addHelpLink( 'Help:Merge history' ); } private function showHistory() { + $this->showMergeForm(); + # List all stored revisions $revisions = new MergeHistoryPager( $this, [], $this->mTargetObj, $this->mDestObj @@ -155,46 +197,62 @@ class SpecialMergeHistory extends SpecialPage { $haveRevisions = $revisions && $revisions->getNumRows() > 0; $out = $this->getOutput(); - $header = '