use MediaWiki\EditPage\TextConflictHelper;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
-use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Revision\RevisionRecord;
use Wikimedia\ScopedCallback;
/**
# checking, etc.
if ( $this->formtype == 'initial' || $this->firsttime ) {
if ( $this->initialiseForm() === false ) {
- $out = $this->context->getOutput();
- if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it
- $this->noSuchSectionPage();
- }
return;
}
* @return string|null
*/
protected function importContentFormData( &$request ) {
- return; // Don't do anything, EditPage already extracted wpTextbox1
+ return null; // Don't do anything, EditPage already extracted wpTextbox1
}
/**
$content = $this->getContentObject( false ); # TODO: track content object?!
if ( $content === false ) {
+ $out = $this->context->getOutput();
+ if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it
+ $this->noSuchSectionPage();
+ }
+ return false;
+ }
+
+ if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
+ $modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() );
+ $modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel();
+
+ $out = $this->context->getOutput();
+ $out->showErrorPage(
+ 'modeleditnotsupported-title',
+ 'modeleditnotsupported-text',
+ [ $modelName ]
+ );
return false;
}
+
$this->textbox1 = $this->toEditText( $content );
$user = $this->context->getUser();
/**
* @param Content|null $def_content The default value to return
*
- * @return Content|null Content on success, $def_content for invalid sections
+ * @return Content|false|null Content on success, $def_content for invalid sections
*
* @since 1.21
*/
protected function getContentObject( $def_content = null ) {
+ global $wgDisableAnonTalk;
+
$content = false;
$user = $this->context->getUser();
$undo
)->inContentLanguage()->text();
} else {
+ $undoMessage = ( $undorev->getUser() === 0 && $wgDisableAnonTalk ) ?
+ 'undo-summary-anon' :
+ 'undo-summary';
$undoSummary = $this->context->msg(
- 'undo-summary',
+ $undoMessage,
$undo,
$userText
)->inContentLanguage()->text();
// This is needed since PageUpdater no longer checks these rights!
// Allow bots to exempt some edits from bot flagging
- $bot = $this->context->getUser()->isAllowed( 'bot' ) && $this->bot;
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+ $bot = $permissionManager->userHasRight( $this->context->getUser(), 'bot' ) && $this->bot;
$status = $this->internalAttemptSave( $resultDetails, $bot );
Hooks::run( 'EditPage::attemptSave:after', [ $this, $status, $resultDetails ] );
case self::AS_CANNOT_USE_CUSTOM_MODEL:
case self::AS_PARSE_ERROR:
case self::AS_UNICODE_NOT_SUPPORTED:
- $out->wrapWikiTextAsInterface( 'error', $status->getWikiText() );
+ $out->wrapWikiTextAsInterface( 'error',
+ $status->getWikiText( false, false, $this->context->getLanguage() )
+ );
return true;
case self::AS_SUCCESS_NEW_ARTICLE:
// is if an extension hook aborted from inside ArticleSave.
// Render the status object into $this->hookError
// FIXME this sucks, we should just use the Status object throughout
- $this->hookError = '<div class="error">' . "\n" . $status->getWikiText() .
+ $this->hookError = '<div class="error">' . "\n" .
+ $status->getWikiText( false, false, $this->context->getLanguage() ) .
'</div>';
return true;
}
} elseif ( !$status->isOK() ) {
# ...or the hook could be expecting us to produce an error
// FIXME this sucks, we should just use the Status object throughout
+ if ( !$status->getErrors() ) {
+ // Provide a fallback error message if none was set
+ $status->fatal( 'hookaborted' );
+ }
$this->hookError = $this->formatStatusErrors( $status );
- $status->fatal( 'hookaborted' );
$status->value = self::AS_HOOK_ERROR_EXPECTED;
return false;
}
public function internalAttemptSave( &$result, $bot = false ) {
$status = Status::newGood();
$user = $this->context->getUser();
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ( !Hooks::run( 'EditPage::attemptSave', [ $this ] ) ) {
wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
# Check image redirect
if ( $this->mTitle->getNamespace() == NS_FILE &&
$textbox_content->isRedirect() &&
- !$user->isAllowed( 'upload' )
+ !$permissionManager->userHasRight( $user, 'upload' )
) {
$code = $user->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED;
$status->setResult( false, $code );
return $status;
}
- if ( $user->isBlockedFrom( $this->mTitle ) ) {
+ if ( $permissionManager->isBlockedFrom( $user, $this->mTitle ) ) {
// Auto-block user's IP if the account was "hard" blocked
if ( !wfReadOnly() ) {
$user->spreadAnyEditBlock();
return $status;
}
- if ( !$user->isAllowed( 'edit' ) ) {
+ if ( !$permissionManager->userHasRight( $user, 'edit' ) ) {
if ( $user->isAnon() ) {
$status->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
return $status;
}
}
- $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
-
$changingContentModel = false;
if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
if ( !$config->get( 'ContentHandlerUseDB' ) ) {
$status->fatal( 'editpage-cannot-use-custom-model' );
$status->value = self::AS_CANNOT_USE_CUSTOM_MODEL;
return $status;
- } elseif ( !$user->isAllowed( 'editcontentmodel' ) ) {
+ } elseif ( !$permissionManager->userHasRight( $user, 'editcontentmodel' ) ) {
$status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
return $status;
}
* content.
*
* @param Content|null|bool|string $content
- * @return string The editable text form of the content.
+ * @return string|false|null The editable text form of the content.
*
* @throws MWException If $content is not an instance of TextContent and
* $this->allowNonTextContent is not true.
if ( $this->isConflict ) {
$conflict = Html::rawElement(
- 'h2', [ 'id' => 'mw-previewconflict' ],
+ 'div', [ 'id' => 'mw-previewconflict', 'class' => 'warningbox' ],
$this->context->msg( 'previewconflict' )->escaped()
);
} else {
- $conflict = '<hr />';
+ $conflict = '';
}
$previewhead = Html::rawElement(
'h2', [ 'id' => 'mw-previewheader' ],
$this->context->msg( 'preview' )->escaped()
) .
- $out->parseAsInterface( $note ) . $conflict
+ Html::rawElement( 'div', [ 'class' => 'warningbox' ],
+ $out->parseAsInterface( $note )
+ ) . $conflict
);
$pageViewLang = $this->mTitle->getPageViewLanguage();
* - 'legacy-name' (optional): short name for backwards-compatibility
* @param array $checked Array of checkbox name (matching the 'legacy-name') => bool,
* where bool indicates the checked status of the checkbox
- * @return array
+ * @return array[]
*/
public function getCheckboxesDefinition( $checked ) {
$checkboxes = [];
$user = $this->context->getUser();
// don't show the minor edit checkbox if it's a new page or section
- if ( !$this->isNew && $user->isAllowed( 'minoredit' ) ) {
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+ if ( !$this->isNew && $permissionManager->userHasRight( $user, 'minoredit' ) ) {
$checkboxes['wpMinoredit'] = [
'id' => 'wpMinoredit',
'label-message' => 'minoredit',
protected function addPageProtectionWarningHeaders() {
$out = $this->context->getOutput();
if ( $this->mTitle->isProtected( 'edit' ) &&
- MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
- $this->mTitle->getNamespace()
+ MediaWikiServices::getInstance()->getPermissionManager()->getNamespaceRestrictionLevels(
+ $this->getTitle()->getNamespace()
) !== [ '' ]
) {
# Is the title semi-protected?