X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=add48d99b919d6c504d37c0fbdeac4890b9efb1b;hb=c13fee87d42bdd6fdf6764edb6f6475c14c27749;hp=23cdc3b9111cf077b7344c4f177b0a33634cd17b;hpb=f2b01310d90060ba2ccba3e6d36b67e942bff978;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 23cdc3b911..add48d99b9 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -869,7 +869,7 @@ class EditPage { } elseif ( $this->section == 'new' ) { // Nothing *to* preview for new sections return false; - } elseif ( ( $request->getVal( 'preload' ) !== null || $this->mTitle->exists() ) + } elseif ( ( $request->getCheck( 'preload' ) || $this->mTitle->exists() ) && $this->context->getUser()->getOption( 'previewonfirst' ) ) { // Standard preference behavior @@ -975,7 +975,7 @@ class EditPage { $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' ); - if ( $this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null ) { + if ( $this->textbox1 === '' && !$request->getCheck( 'wpTextbox1' ) ) { // wpTextbox1 field is missing, possibly due to being "too big" // according to some filter rules such as Suhosin's setting for // suhosin.request.max_value_length (d'oh) @@ -1214,149 +1214,147 @@ class EditPage { $content = $this->getPreloadedContent( $preload, $params ); } // For existing pages, get text based on "undo" or section parameters. - } else { - if ( $this->section != '' ) { - // Get section edit text (returns $def_text for invalid sections) - $orig = $this->getOriginalContent( $user ); - $content = $orig ? $orig->getSection( $this->section ) : null; + } elseif ( $this->section != '' ) { + // Get section edit text (returns $def_text for invalid sections) + $orig = $this->getOriginalContent( $user ); + $content = $orig ? $orig->getSection( $this->section ) : null; - if ( !$content ) { - $content = $def_content; - } - } else { - $undoafter = $request->getInt( 'undoafter' ); - $undo = $request->getInt( 'undo' ); - - if ( $undo > 0 && $undoafter > 0 ) { - $undorev = Revision::newFromId( $undo ); - $oldrev = Revision::newFromId( $undoafter ); - $undoMsg = null; - - # Sanity check, make sure it's the right page, - # the revisions exist and they were not deleted. - # Otherwise, $content will be left as-is. - if ( !is_null( $undorev ) && !is_null( $oldrev ) && - !$undorev->isDeleted( Revision::DELETED_TEXT ) && - !$oldrev->isDeleted( Revision::DELETED_TEXT ) + if ( !$content ) { + $content = $def_content; + } + } else { + $undoafter = $request->getInt( 'undoafter' ); + $undo = $request->getInt( 'undo' ); + + if ( $undo > 0 && $undoafter > 0 ) { + $undorev = Revision::newFromId( $undo ); + $oldrev = Revision::newFromId( $undoafter ); + $undoMsg = null; + + # Sanity check, make sure it's the right page, + # the revisions exist and they were not deleted. + # Otherwise, $content will be left as-is. + if ( !is_null( $undorev ) && !is_null( $oldrev ) && + !$undorev->isDeleted( Revision::DELETED_TEXT ) && + !$oldrev->isDeleted( Revision::DELETED_TEXT ) + ) { + if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev ) + || !$this->isSupportedContentModel( $oldrev->getContentModel() ) ) { - if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev ) - || !$this->isSupportedContentModel( $oldrev->getContentModel() ) - ) { - // Hack for undo while EditPage can't handle multi-slot editing - $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [ - 'action' => 'mcrundo', - 'undo' => $undo, - 'undoafter' => $undoafter, - ] ) ); - return false; - } else { - $content = $this->page->getUndoContent( $undorev, $oldrev ); + // Hack for undo while EditPage can't handle multi-slot editing + $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [ + 'action' => 'mcrundo', + 'undo' => $undo, + 'undoafter' => $undoafter, + ] ) ); + return false; + } else { + $content = $this->page->getUndoContent( $undorev, $oldrev ); - if ( $content === false ) { - # Warn the user that something went wrong - $undoMsg = 'failure'; - } + if ( $content === false ) { + # Warn the user that something went wrong + $undoMsg = 'failure'; } + } - if ( $undoMsg === null ) { - $oldContent = $this->page->getContent( Revision::RAW ); - $popts = ParserOptions::newFromUserAndLang( - $user, MediaWikiServices::getInstance()->getContentLanguage() ); - $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts ); - if ( $newContent->getModel() !== $oldContent->getModel() ) { - // The undo may change content - // model if its reverting the top - // edit. This can result in - // mismatched content model/format. - $this->contentModel = $newContent->getModel(); - $this->contentFormat = $oldrev->getContentFormat(); - } + if ( $undoMsg === null ) { + $oldContent = $this->page->getContent( Revision::RAW ); + $popts = ParserOptions::newFromUserAndLang( + $user, MediaWikiServices::getInstance()->getContentLanguage() ); + $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts ); + if ( $newContent->getModel() !== $oldContent->getModel() ) { + // The undo may change content + // model if its reverting the top + // edit. This can result in + // mismatched content model/format. + $this->contentModel = $newContent->getModel(); + $this->contentFormat = $oldrev->getContentFormat(); + } - 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 = $this->context->msg( - 'undo-summary-username-hidden', - $undo - )->inContentLanguage()->text(); - } else { - $undoSummary = $this->context->msg( - 'undo-summary', - $undo, - $userText - )->inContentLanguage()->text(); - } - if ( $this->summary === '' ) { - $this->summary = $undoSummary; - } else { - $this->summary = $undoSummary . $this->context->msg( 'colon-separator' ) - ->inContentLanguage()->text() . $this->summary; - } - $this->undidRev = $undo; + 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 = $this->context->msg( + 'undo-summary-username-hidden', + $undo + )->inContentLanguage()->text(); + } else { + $undoSummary = $this->context->msg( + 'undo-summary', + $undo, + $userText + )->inContentLanguage()->text(); + } + if ( $this->summary === '' ) { + $this->summary = $undoSummary; + } else { + $this->summary = $undoSummary . $this->context->msg( 'colon-separator' ) + ->inContentLanguage()->text() . $this->summary; } - $this->formtype = 'diff'; + $this->undidRev = $undo; } + $this->formtype = 'diff'; } - } else { - // Failed basic sanity checks. - // Older revisions may have been removed since the link - // was created, or we may simply have got bogus input. - $undoMsg = 'norev'; } - - $out = $this->context->getOutput(); - // Messages: undo-success, undo-failure, undo-main-slot-only, undo-norev, - // undo-nochange. - $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}"; - $this->editFormPageTop .= Html::rawElement( - 'div', [ 'class' => $class ], - $out->parseAsInterface( - $this->context->msg( 'undo-' . $undoMsg )->plain() - ) - ); + } else { + // Failed basic sanity checks. + // Older revisions may have been removed since the link + // was created, or we may simply have got bogus input. + $undoMsg = 'norev'; } - if ( $content === false ) { - // Hack for restoring old revisions while EditPage - // can't handle multi-slot editing. + $out = $this->context->getOutput(); + // Messages: undo-success, undo-failure, undo-main-slot-only, undo-norev, + // undo-nochange. + $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}"; + $this->editFormPageTop .= Html::rawElement( + 'div', [ 'class' => $class ], + $out->parseAsInterface( + $this->context->msg( 'undo-' . $undoMsg )->plain() + ) + ); + } - $curRevision = $this->page->getRevision(); - $oldRevision = $this->mArticle->getRevisionFetched(); + if ( $content === false ) { + // Hack for restoring old revisions while EditPage + // can't handle multi-slot editing. - if ( $curRevision - && $oldRevision - && $curRevision->getId() !== $oldRevision->getId() - && ( WikiPage::hasDifferencesOutsideMainSlot( $oldRevision, $curRevision ) - || !$this->isSupportedContentModel( $oldRevision->getContentModel() ) ) - ) { - $this->context->getOutput()->redirect( - $this->mTitle->getFullURL( - [ - 'action' => 'mcrrestore', - 'restore' => $oldRevision->getId(), - ] - ) - ); + $curRevision = $this->page->getRevision(); + $oldRevision = $this->mArticle->getRevisionFetched(); - return false; - } - } + if ( $curRevision + && $oldRevision + && $curRevision->getId() !== $oldRevision->getId() + && ( WikiPage::hasDifferencesOutsideMainSlot( $oldRevision, $curRevision ) + || !$this->isSupportedContentModel( $oldRevision->getContentModel() ) ) + ) { + $this->context->getOutput()->redirect( + $this->mTitle->getFullURL( + [ + 'action' => 'mcrrestore', + 'restore' => $oldRevision->getId(), + ] + ) + ); - if ( $content === false ) { - $content = $this->getOriginalContent( $user ); + return false; } } + + if ( $content === false ) { + $content = $this->getOriginalContent( $user ); + } } return $content; @@ -2804,11 +2802,9 @@ ERROR; $out->addHTML( $this->editFormTextTop ); - if ( $this->wasDeletedSinceLastEdit() ) { - if ( $this->formtype !== 'save' ) { - $out->wrapWikiMsg( "
\n$1\n
", - 'deletedwhileediting' ); - } + if ( $this->wasDeletedSinceLastEdit() && $this->formtype !== 'save' ) { + $out->wrapWikiMsg( "
\n$1\n
", + 'deletedwhileediting' ); } // @todo add EditForm plugin interface and use it here! @@ -3076,12 +3072,12 @@ ERROR; $this->addExplainConflictHeader( $out ); $this->editRevId = $this->page->getLatest(); } else { - if ( $this->section != '' && $this->section != 'new' ) { - if ( !$this->summary && !$this->preview && !$this->diff ) { - $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object - if ( $sectionTitle !== false ) { - $this->summary = "/* $sectionTitle */ "; - } + if ( $this->section != '' && $this->section != 'new' && !$this->summary && + !$this->preview && !$this->diff + ) { + $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object + if ( $sectionTitle !== false ) { + $this->summary = "/* $sectionTitle */ "; } } @@ -3188,44 +3184,42 @@ ERROR; 'anonpreviewwarning' ); } - } else { - if ( $this->mTitle->isUserConfigPage() ) { - # Check the skin exists - if ( $this->isWrongCaseUserConfigPage() ) { - $out->wrapWikiMsg( - "
\n$1\n
", - [ 'userinvalidconfigtitle', $this->mTitle->getSkinFromConfigSubpage() ] - ); - } - if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) { - $isUserCssConfig = $this->mTitle->isUserCssConfigPage(); - $isUserJsonConfig = $this->mTitle->isUserJsonConfigPage(); - $isUserJsConfig = $this->mTitle->isUserJsConfigPage(); - - $warning = $isUserCssConfig - ? 'usercssispublic' - : ( $isUserJsonConfig ? 'userjsonispublic' : 'userjsispublic' ); - - $out->wrapWikiMsg( '
$1
', $warning ); - - if ( $this->formtype !== 'preview' ) { - $config = $this->context->getConfig(); - if ( $isUserCssConfig && $config->get( 'AllowUserCss' ) ) { - $out->wrapWikiMsg( - "
\n$1\n
", - [ 'usercssyoucanpreview' ] - ); - } elseif ( $isUserJsonConfig /* No comparable 'AllowUserJson' */ ) { - $out->wrapWikiMsg( - "
\n$1\n
", - [ 'userjsonyoucanpreview' ] - ); - } elseif ( $isUserJsConfig && $config->get( 'AllowUserJs' ) ) { - $out->wrapWikiMsg( - "
\n$1\n
", - [ 'userjsyoucanpreview' ] - ); - } + } elseif ( $this->mTitle->isUserConfigPage() ) { + # Check the skin exists + if ( $this->isWrongCaseUserConfigPage() ) { + $out->wrapWikiMsg( + "
\n$1\n
", + [ 'userinvalidconfigtitle', $this->mTitle->getSkinFromConfigSubpage() ] + ); + } + if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) { + $isUserCssConfig = $this->mTitle->isUserCssConfigPage(); + $isUserJsonConfig = $this->mTitle->isUserJsonConfigPage(); + $isUserJsConfig = $this->mTitle->isUserJsConfigPage(); + + $warning = $isUserCssConfig + ? 'usercssispublic' + : ( $isUserJsonConfig ? 'userjsonispublic' : 'userjsispublic' ); + + $out->wrapWikiMsg( '
$1
', $warning ); + + if ( $this->formtype !== 'preview' ) { + $config = $this->context->getConfig(); + if ( $isUserCssConfig && $config->get( 'AllowUserCss' ) ) { + $out->wrapWikiMsg( + "
\n$1\n
", + [ 'usercssyoucanpreview' ] + ); + } elseif ( $isUserJsonConfig /* No comparable 'AllowUserJson' */ ) { + $out->wrapWikiMsg( + "
\n$1\n
", + [ 'userjsonyoucanpreview' ] + ); + } elseif ( $isUserJsConfig && $config->get( 'AllowUserJs' ) ) { + $out->wrapWikiMsg( + "
\n$1\n
", + [ 'userjsyoucanpreview' ] + ); } } } @@ -3309,10 +3303,8 @@ ERROR; if ( $this->nosummary ) { return; } - } else { - if ( !$this->mShowSummaryField ) { - return; - } + } elseif ( !$this->mShowSummaryField ) { + return; } $labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse(); @@ -4450,16 +4442,14 @@ ERROR; $lang->formatNum( $maxArticleSize ) ] ); - } else { - if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) { - $out->wrapWikiMsg( "
\n$1\n
", - [ - 'longpage-hint', - $lang->formatSize( strlen( $this->textbox1 ) ), - strlen( $this->textbox1 ) - ] - ); - } + } elseif ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) { + $out->wrapWikiMsg( "
\n$1\n
", + [ + 'longpage-hint', + $lang->formatSize( strlen( $this->textbox1 ) ), + strlen( $this->textbox1 ) + ] + ); } }