X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=2bddc3ee737ec5d6b6a94c3d1f6ecc373beaddc9;hb=1d41a1a7345c38a87c047f06c5f75d3dace43a29;hp=8571cd79a980e98ceb0b5bbc08d4e4cef3de71a2;hpb=bf0b1f8822b964456a23c417249ef4e026a46c1d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 8571cd79a9..2bddc3ee73 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -537,6 +537,20 @@ class EditPage { return; } + $revision = $this->mArticle->getRevisionFetched(); + // Disallow editing revisions with content models different from the current one + if ( $revision && $revision->getContentModel() !== $this->contentModel ) { + $this->displayViewSourcePage( + $this->getContentObject(), + wfMessage( + 'contentmodelediterror', + $revision->getContentModel(), + $this->contentModel + )->plain() + ); + return; + } + $this->isConflict = false; // css / js subpages of user pages get a special treatment $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage(); @@ -647,6 +661,20 @@ class EditPage { throw new PermissionsError( $action, $permErrors ); } + $this->displayViewSourcePage( + $content, + $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) + ); + } + + /** + * Display a read-only View Source page + * @param Content $content content object + * @param string $errorMessage additional wikitext error message to display + */ + protected function displayViewSourcePage( Content $content, $errorMessage = '' ) { + global $wgOut; + Hooks::run( 'EditPage::showReadOnlyForm:initial', array( $this, &$wgOut ) ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); @@ -658,8 +686,10 @@ class EditPage { $wgOut->addHTML( $this->editFormPageTop ); $wgOut->addHTML( $this->editFormTextTop ); - $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) ); - $wgOut->addHTML( "
\n" ); + if ( $errorMessage !== '' ) { + $wgOut->addWikiText( $errorMessage ); + $wgOut->addHTML( "
\n" ); + } # If the user made changes, preserve them when showing the markup # (This happens when a user is blocked during edit, for instance) @@ -667,7 +697,13 @@ class EditPage { $text = $this->textbox1; $wgOut->addWikiMsg( 'viewyourtext' ); } else { - $text = $this->toEditText( $content ); + try { + $text = $this->toEditText( $content ); + } catch ( MWException $e ) { + # Serialize using the default format if the content model is not supported + # (e.g. for an old revision with a different model) + $text = $content->serialize(); + } $wgOut->addWikiMsg( 'viewsourcetext' ); } @@ -2005,7 +2041,7 @@ class EditPage { } /** - * @param Title $title + * @param User $user * @param string $oldModel * @param string $newModel * @param string $reason @@ -2023,26 +2059,26 @@ class EditPage { $log->publish( $logid ); } - /** * Register the change of watch status */ protected function updateWatchlist() { global $wgUser; - if ( $wgUser->isLoggedIn() - && $this->watchthis != $wgUser->isWatched( $this->mTitle, WatchedItem::IGNORE_USER_RIGHTS ) - ) { - $fname = __METHOD__; - $title = $this->mTitle; - $watch = $this->watchthis; - - // Do this in its own transaction to reduce contention... - $dbw = wfGetDB( DB_MASTER ); - $dbw->onTransactionIdle( function () use ( $dbw, $title, $watch, $wgUser, $fname ) { - WatchAction::doWatchOrUnwatch( $watch, $title, $wgUser ); - } ); + if ( !$wgUser->isLoggedIn() ) { + return; } + + $user = $wgUser; + $title = $this->mTitle; + $watch = $this->watchthis; + // Do this in its own transaction to reduce contention... + DeferredUpdates::addCallableUpdate( function () use ( $user, $title, $watch ) { + if ( $watch == $user->isWatched( $title, WatchedItem::IGNORE_USER_RIGHTS ) ) { + return; // nothing to change + } + WatchAction::doWatchOrUnwatch( $watch, $title, $user ); + } ); } /**