X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialMergeHistory.php;h=162ef60d8fd64614d5ae207e5b12c551ac8d90db;hb=5cbada9dea3f22e7bb33250197b156e8628b8e4a;hp=b916c1fc7860bfe2ed35ade8733dd90dcad0b6a9;hpb=8eac2feedb7ee093d2c48504e1eb2b8a9dbc8452;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index b916c1fc78..162ef60d8f 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -28,38 +28,14 @@ * @ingroup SpecialPage */ class SpecialMergeHistory extends SpecialPage { - /** @var string */ - protected $mAction; + /** @var FormOptions */ + protected $mOpts; - /** @var string */ - protected $mTarget; + /** @var Status */ + protected $mStatus; - /** @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 Title|null */ + protected $mTargetObj, $mDestObj; /** @var int[] */ public $prevId; @@ -72,124 +48,107 @@ 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(); - if ( $this->mTargetID && $this->mDestID && $this->mAction == 'submit' && $this->mMerge ) { + $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 && $opts->getValue( 'mergepoint' ) !== '' ) { $this->merge(); return; } - if ( !$this->mSubmitted ) { + if ( $target === '' && $dest === '' ) { $this->showMergeForm(); return; } - $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 ( !$targetObj instanceof Title ) { + $status->merge( Status::newFatal( 'mergehistory-invalid-source' ) ); + } elseif ( !$targetObj->exists() ) { + $status->merge( Status::newFatal( 'mergehistory-no-source', + wfEscapeWikiText( $targetObj->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 ( !$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->mTargetObj && $this->mDestObj && $this->mTargetObj->equals( $this->mDestObj ) ) { - $errors[] = $this->msg( 'mergehistory-same-destination' )->parseAsBlock(); + if ( $targetObj && $destObj && $targetObj->equals( $destObj ) ) { + $status->merge( Status::newFatal( 'mergehistory-same-destination' ) ); } - if ( count( $errors ) ) { - $this->showMergeForm(); - $this->getOutput()->addHTML( implode( "\n", $errors ) ); - } else { + $this->mStatus = $status; + + $this->showMergeForm(); + + if ( $status->isOK() ) { $this->showHistory(); } } function showMergeForm() { - $out = $this->getOutput(); - $out->addWikiMsg( 'mergehistory-header' ); - - $out->addHTML( - Xml::openElement( 'form', [ - 'method' => 'get', - 'action' => wfScript() ] ) . - '
' . - '' - ); - - $this->addHelpLink( 'Help:Merge history' ); + $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 ); } private function showHistory() { - $this->showMergeForm(); - # List all stored revisions $revisions = new MergeHistoryPager( $this, [], $this->mTargetObj, $this->mDestObj @@ -197,62 +156,46 @@ class SpecialMergeHistory extends SpecialPage { $haveRevisions = $revisions && $revisions->getNumRows() > 0; $out = $this->getOutput(); - $titleObj = $this->getPageTitle(); - $action = $titleObj->getLocalURL( [ 'action' => 'submit' ] ); - # Start the form here - $top = Xml::openElement( - 'form', - [ - 'method' => 'post', - 'action' => $action, - 'id' => 'merge' - ] - ); - $out->addHTML( $top ); - - if ( $haveRevisions ) { - # Format the user-visible controls (comment field, submission button) - # in a nice little table - $table = - Xml::openElement( 'fieldset' ) . - $this->msg( 'mergehistory-merge', $this->mTargetObj->getPrefixedText(), - $this->mDestObj->getPrefixedText() )->parse() . - Xml::openElement( 'table', [ 'id' => 'mw-mergehistory-table' ] ) . - '