X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=9a27d23d21185353f21637d089e5c7c4782fbe88;hb=0bc431e7ecd810549eaccf340d8f4caaf85c3f17;hp=f86cae46f4ccf04073920dfd7db0f65c8eb3b020;hpb=8862991ce1b125f22a094399868d192c15a2115a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index f86cae46f4..9a27d23d21 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -319,6 +319,18 @@ class EditPage { } } + /** + * Returns if the given content model is editable. + * + * @param string $modelId The ID of the content model to test. Use CONTENT_MODEL_XXX constants. + * @return bool + * @throws MWException if $modelId has no known handler + */ + public function isSupportedContentModel( $modelId ) { + return $this->allowNonTextContent || + ContentHandler::getForModelID( $modelId ) instanceof TextContentHandler; + } + function submit() { $this->edit(); } @@ -613,6 +625,7 @@ class EditPage { /** * This function collects the form data and uses it to populate various member variables. * @param $request WebRequest + * @throws ErrorPageError */ function importFormData( &$request ) { global $wgContLang, $wgUser; @@ -777,12 +790,17 @@ class EditPage { $this->bot = $request->getBool( 'bot', true ); $this->nosummary = $request->getBool( 'nosummary' ); - $content_handler = ContentHandler::getForTitle( $this->mTitle ); - $this->contentModel = $request->getText( 'model', $content_handler->getModelID() ); #may be overridden by revision - $this->contentFormat = $request->getText( 'format', $content_handler->getDefaultFormat() ); #may be overridden by revision + $this->contentModel = $request->getText( 'model', $this->contentModel ); #may be overridden by revision + $this->contentFormat = $request->getText( 'format', $this->contentFormat ); #may be overridden by revision + if ( !ContentHandler::getForModelID( $this->contentModel )->isSupportedFormat( $this->contentFormat ) ) { + throw new ErrorPageError( + 'editpage-notsupportedcontentformat-title', + 'editpage-notsupportedcontentformat-text', + array( $this->contentFormat, ContentHandler::getLocalizedName( $this->contentModel ) ) + ); + } #TODO: check if the desired model is allowed in this namespace, and if a transition from the page's current model to the new model is allowed - #TODO: check if the desired content model supports the given content format! $this->live = $request->getCheck( 'live' ); $this->editintro = $request->getText( 'editintro', @@ -874,7 +892,7 @@ class EditPage { * @since 1.21 */ protected function getContentObject( $def_content = null ) { - global $wgOut, $wgRequest; + global $wgOut, $wgRequest, $wgUser, $wgContLang; wfProfileIn( __METHOD__ ); @@ -912,10 +930,6 @@ class EditPage { $undo = $wgRequest->getInt( 'undo' ); if ( $undo > 0 && $undoafter > 0 ) { - if ( $undo < $undoafter ) { - # If they got undoafter and undo round the wrong way, switch them - list( $undo, $undoafter ) = array( $undoafter, $undo ); - } $undorev = Revision::newFromId( $undo ); $oldrev = Revision::newFromId( $undoafter ); @@ -924,8 +938,6 @@ class EditPage { # the revisions exist and they were not deleted. # Otherwise, $content will be left as-is. if ( !is_null( $undorev ) && !is_null( $oldrev ) && - $undorev->getPage() == $oldrev->getPage() && - $undorev->getPage() == $this->mTitle->getArticleID() && !$undorev->isDeleted( Revision::DELETED_TEXT ) && !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) { @@ -935,34 +947,45 @@ class EditPage { # Warn the user that something went wrong $undoMsg = 'failure'; } else { - # Inform the user of our success and set an automatic edit summary - $undoMsg = 'success'; - - # If we just undid one rev, use an autosummary - $firstrev = $oldrev->getNext(); - if ( $firstrev && $firstrev->getId() == $undo ) { - $userText = $undorev->getUserText(); - if ( $userText === '' ) { - $undoSummary = wfMessage( - 'undo-summary-username-hidden', - $undo - )->inContentLanguage()->text(); - } else { - $undoSummary = wfMessage( - 'undo-summary', - $undo, - $userText - )->inContentLanguage()->text(); + $oldContent = $this->mArticle->getPage()->getContent( Revision::RAW ); + $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); + $newContent = $content->preSaveTransform( $this->mTitle, $wgUser, $popts ); + + if ( $newContent->equals( $oldContent ) ) { + # Tell the user that the undo results in no change, + # i.e. the revisions were already undone. + $undoMsg = 'nochange'; + $content = false; + } else { + # Inform the user of our success and set an automatic edit summary + $undoMsg = 'success'; + + # If we just undid one rev, use an autosummary + $firstrev = $oldrev->getNext(); + if ( $firstrev && $firstrev->getId() == $undo ) { + $userText = $undorev->getUserText(); + if ( $userText === '' ) { + $undoSummary = wfMessage( + 'undo-summary-username-hidden', + $undo + )->inContentLanguage()->text(); + } else { + $undoSummary = wfMessage( + 'undo-summary', + $undo, + $userText + )->inContentLanguage()->text(); + } + if ( $this->summary === '' ) { + $this->summary = $undoSummary; + } else { + $this->summary = $undoSummary . wfMessage( 'colon-separator' ) + ->inContentLanguage()->text() . $this->summary; + } + $this->undidRev = $undo; } - if ( $this->summary === '' ) { - $this->summary = $undoSummary; - } else { - $this->summary = $undoSummary . wfMessage( 'colon-separator' ) - ->inContentLanguage()->text() . $this->summary; - } - $this->undidRev = $undo; + $this->formtype = 'diff'; } - $this->formtype = 'diff'; } } else { // Failed basic sanity checks. @@ -971,7 +994,7 @@ class EditPage { $undoMsg = 'norev'; } - // Messages: undo-success, undo-failure, undo-norev + // Messages: undo-success, undo-failure, undo-norev, undo-nochange $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}"; $this->editFormPageTop .= $wgOut->parse( "