use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
+use Wikimedia\ScopedCallback;
/**
* The edit page/HTML interface (split from Article)
*/
protected $context;
+ /**
+ * @var bool Whether an old revision is edited
+ */
+ private $isOldRev = false;
+
/**
* @param Article $article
*/
// Allow extensions to modify form data
Hooks::run( 'EditPage::importFormData', [ $this, $request ] );
-
}
/**
protected function runPostMergeFilters( Content $content, Status $status, User $user ) {
// Run old style post-section-merge edit filter
if ( !ContentHandler::runLegacyHooks( 'EditFilterMerged',
- [ $this, $content, &$this->hookError, $this->summary ] )
- ) {
+ [ $this, $content, &$this->hookError, $this->summary ],
+ '1.21'
+ ) ) {
# Error messages etc. could be handled within the hook...
$status->fatal( 'hookaborted' );
$status->value = self::AS_HOOK_ERROR;
} elseif ( !$wgUser->isAllowed( 'editcontentmodel' ) ) {
$status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
return $status;
-
}
+ // Make sure the user can edit the page under the new content model too
+ $titleWithNewContentModel = clone $this->mTitle;
+ $titleWithNewContentModel->setContentModel( $this->contentModel );
+ if ( !$titleWithNewContentModel->userCan( 'editcontentmodel', $wgUser )
+ || !$titleWithNewContentModel->userCan( 'edit', $wgUser )
+ ) {
+ $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
+ return $status;
+ }
+
$changingContentModel = true;
$oldContentModel = $this->mTitle->getContentModel();
}
* @return bool
*/
private function mergeChangesIntoContent( &$editContent ) {
-
$db = wfGetDB( DB_MASTER );
// This is the revision the editor started from
$wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ],
Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) );
- if ( $this->mParserOutput ) {
- $wgOut->setLimitReportData( $this->mParserOutput->getLimitReportData() );
- }
+ $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ],
+ self::getPreviewLimitReport( $this->mParserOutput ) ) );
$wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
if ( !$wgUser->getOption( 'previewontop' ) ) {
$this->displayPreviewArea( $previewOutput, false );
}
-
}
/**
return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
$templateListFormatter->format( $templates, $type )
);
-
}
/**
global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
global $wgAllowUserCss, $wgAllowUserJs;
- if ( $this->mTitle->isTalkPage() ) {
- $wgOut->addWikiMsg( 'talkpagetext' );
- }
+ $this->addTalkPageText();
- // Add edit notices
- $editNotices = $this->mTitle->getEditNotices( $this->oldid );
- if ( count( $editNotices ) ) {
- $wgOut->addHTML( implode( "\n", $editNotices ) );
- } else {
- $msg = $this->context->msg( 'editnotice-notext' );
- if ( !$msg->isDisabled() ) {
- $wgOut->addHTML(
- '<div class="mw-editnotice-notext">'
- . $msg->parseAsBlock()
- . '</div>'
- );
- }
- }
+ $this->addEditNotices();
if ( $this->isConflict ) {
$wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
if ( !$revision->isCurrent() ) {
$this->mArticle->setOldSubtitle( $revision->getId() );
$wgOut->addWikiMsg( 'editingold' );
+ $this->isOldRev = true;
}
} elseif ( $this->mTitle->exists() ) {
// Something went wrong
$classes[] = 'mw-textarea-cprotected';
}
}
+ # Is an old revision being edited?
+ if ( $this->isOldRev ) {
+ $classes[] = 'mw-textarea-oldrev';
+ }
$attribs = [ 'tabindex' => 1 ];
'style' => ''
];
+ // The following classes can be used here:
+ // * mw-editfont-default
+ // * mw-editfont-monospace
+ // * mw-editfont-sans-serif
+ // * mw-editfont-serif
+ $class = 'mw-editfont-' . $wgUser->getOption( 'editfont' );
+
+ if ( isset( $attribs['class'] ) ) {
+ if ( is_string( $attribs['class'] ) ) {
+ $attribs['class'] .= ' ' . $class;
+ } elseif ( is_array( $attribs['class'] ) ) {
+ $attribs['class'][] = $class;
+ }
+ } else {
+ $attribs['class'] = $class;
+ }
+
$pageLang = $this->mTitle->getPageLanguage();
$attribs['lang'] = $pageLang->getHtmlCode();
$attribs['dir'] = $pageLang->getDir();
}
if ( $newContent ) {
- ContentHandler::runLegacyHooks( 'EditPageGetDiffText', [ $this, &$newContent ] );
+ ContentHandler::runLegacyHooks( 'EditPageGetDiffText', [ $this, &$newContent ], '1.21' );
Hooks::run( 'EditPageGetDiffContent', [ $this, &$newContent ] );
$popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
* @param string $format Output format, valid values are any function of a Message object
* @return string
*/
- public static function getCopyrightWarning( $title, $format = 'plain' ) {
+ public static function getCopyrightWarning( $title, $format = 'plain', $langcode = null ) {
global $wgRightsText;
if ( $wgRightsText ) {
$copywarnMsg = [ 'copyrightwarning',
// Allow for site and per-namespace customization of contribution/copyright notice.
Hooks::run( 'EditPageCopyrightWarning', [ $title, &$copywarnMsg ] );
+ $msg = call_user_func_array( 'wfMessage', $copywarnMsg )->title( $title );
+ if ( $langcode ) {
+ $msg->inLanguage( $langcode );
+ }
return "<div id=\"editpage-copywarn\">\n" .
- call_user_func_array( 'wfMessage', $copywarnMsg )->title( $title )->$format() . "\n</div>";
+ $msg->$format() . "\n</div>";
}
/**
return '';
}
- return ResourceLoader::makeInlineScript(
- ResourceLoader::makeConfigSetScript(
- [ 'wgPageParseReport' => $output->getLimitReportData() ],
- true
- )
+ $limitReport = Html::rawElement( 'div', [ 'class' => 'mw-limitReportExplanation' ],
+ wfMessage( 'limitreport-title' )->parseAsBlock()
);
+
+ // Show/hide animation doesn't work correctly on a table, so wrap it in a div.
+ $limitReport .= Html::openElement( 'div', [ 'class' => 'preview-limit-report-wrapper' ] );
+
+ $limitReport .= Html::openElement( 'table', [
+ 'class' => 'preview-limit-report wikitable'
+ ] ) .
+ Html::openElement( 'tbody' );
+
+ foreach ( $output->getLimitReportData() as $key => $value ) {
+ if ( Hooks::run( 'ParserLimitReportFormat',
+ [ $key, &$value, &$limitReport, true, true ]
+ ) ) {
+ $keyMsg = wfMessage( $key );
+ $valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] );
+ if ( !$valueMsg->exists() ) {
+ $valueMsg = new RawMessage( '$1' );
+ }
+ if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
+ $limitReport .= Html::openElement( 'tr' ) .
+ Html::rawElement( 'th', null, $keyMsg->parse() ) .
+ Html::rawElement( 'td', null, $valueMsg->params( $value )->parse() ) .
+ Html::closeElement( 'tr' );
+ }
+ }
+ }
+
+ $limitReport .= Html::closeElement( 'tbody' ) .
+ Html::closeElement( 'table' ) .
+ Html::closeElement( 'div' );
+
+ return $limitReport;
}
protected function showStandardInputs( &$tabindex = 2 ) {
}
$hook_args = [ $this, &$content ];
- ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args );
+ ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args, '1.25' );
Hooks::run( 'EditPageGetPreviewContent', $hook_args );
$parserResult = $this->doPreviewParse( $content );
'name' => 'wpSave',
'tabindex' => ++$tabindex,
] + Linker::tooltipAndAccesskeyAttribs( 'save' );
- $buttons['save'] = Html::submitButton( $buttonLabel, $attribs, [ 'mw-ui-constructive' ] );
+ $buttons['save'] = Html::submitButton( $buttonLabel, $attribs, [ 'mw-ui-progressive' ] );
++$tabindex; // use the same for preview and live preview
$attribs = [
protected function safeUnicodeOutput( $text ) {
return $this->checkUnicodeCompliantBrowser()
? $text
- : $this->makesafe( $text );
+ : $this->makeSafe( $text );
}
/**
// reverse the transform that we made for reversibility reasons.
return strtr( $result, [ "�" => "&#x" ] );
}
+
+ /**
+ * @since 1.29
+ */
+ protected function addEditNotices() {
+ global $wgOut;
+
+ $editNotices = $this->mTitle->getEditNotices( $this->oldid );
+ if ( count( $editNotices ) ) {
+ $wgOut->addHTML( implode( "\n", $editNotices ) );
+ } else {
+ $msg = $this->context->msg( 'editnotice-notext' );
+ if ( !$msg->isDisabled() ) {
+ $wgOut->addHTML(
+ '<div class="mw-editnotice-notext">'
+ . $msg->parseAsBlock()
+ . '</div>'
+ );
+ }
+ }
+ }
+
+ /**
+ * @since 1.29
+ */
+ protected function addTalkPageText() {
+ global $wgOut;
+
+ if ( $this->mTitle->isTalkPage() ) {
+ $wgOut->addWikiMsg( 'talkpagetext' );
+ }
+ }
}