X-Git-Url: http://git.cyclocoop.org/%28?a=blobdiff_plain;f=includes%2FEditPage.php;h=c0c0048db8ae6114c9d170d40aa11e0f8cde091a;hb=d115a799235833e59f75958b9fdf011a19f0061b;hp=c5330eeea33beb4d015b04854e8b48027e468224;hpb=fc7d715b4b5adedd0ae3e9e6f969c89e19d460eb;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/EditPage.php b/includes/EditPage.php
index c5330eeea3..c0c0048db8 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -21,6 +21,7 @@
*/
use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
/**
* The edit page/HTML interface (split from Article)
@@ -577,7 +578,7 @@ class EditPage {
) {
$this->displayViewSourcePage(
$this->getContentObject(),
- wfMessage(
+ $this->context->msg(
'contentmodelediterror',
$revision->getContentModel(),
$this->contentModel
@@ -714,7 +715,7 @@ class EditPage {
Hooks::run( 'EditPage::showReadOnlyForm:initial', [ $this, &$wgOut ] );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->setPageTitle( wfMessage(
+ $wgOut->setPageTitle( $this->context->msg(
'viewsource-title',
$this->getContextTitle()->getPrefixedText()
) );
@@ -747,8 +748,7 @@ class EditPage {
$this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] );
$wgOut->addHTML( $this->editFormTextAfterContent );
- $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
- Linker::formatTemplates( $this->getTemplates() ) ) );
+ $wgOut->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
$wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
@@ -1008,9 +1008,17 @@ class EditPage {
// May be overridden by revision.
$this->contentFormat = $request->getText( 'format', $this->contentFormat );
- if ( !ContentHandler::getForModelID( $this->contentModel )
- ->isSupportedFormat( $this->contentFormat )
- ) {
+ try {
+ $handler = ContentHandler::getForModelID( $this->contentModel );
+ } catch ( MWUnknownContentModelException $e ) {
+ throw new ErrorPageError(
+ 'editpage-invalidcontentmodel-title',
+ 'editpage-invalidcontentmodel-text',
+ [ $this->contentModel ]
+ );
+ }
+
+ if ( !$handler->isSupportedFormat( $this->contentFormat ) ) {
throw new ErrorPageError(
'editpage-notsupportedcontentformat-title',
'editpage-notsupportedcontentformat-text',
@@ -1170,12 +1178,12 @@ class EditPage {
if ( $firstrev && $firstrev->getId() == $undo ) {
$userText = $undorev->getUserText();
if ( $userText === '' ) {
- $undoSummary = wfMessage(
+ $undoSummary = $this->context->msg(
'undo-summary-username-hidden',
$undo
)->inContentLanguage()->text();
} else {
- $undoSummary = wfMessage(
+ $undoSummary = $this->context->msg(
'undo-summary',
$undo,
$userText
@@ -1184,7 +1192,7 @@ class EditPage {
if ( $this->summary === '' ) {
$this->summary = $undoSummary;
} else {
- $this->summary = $undoSummary . wfMessage( 'colon-separator' )
+ $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
->inContentLanguage()->text() . $this->summary;
}
$this->undidRev = $undo;
@@ -1202,7 +1210,7 @@ class EditPage {
// Messages: undo-success, undo-failure, undo-norev, undo-nochange
$class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
$this->editFormPageTop .= $wgOut->parse( "
" .
- wfMessage( 'undo-' . $undoMsg )->plain() . '
', true, /* interface */true );
+ $this->context->msg( 'undo-' . $undoMsg )->plain() . '', true, /* interface */true );
}
if ( $content === false ) {
@@ -1666,7 +1674,7 @@ class EditPage {
// passed.
if ( $this->summary === '' ) {
$cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
- return wfMessage( 'newsectionsummary' )
+ return $this->context->msg( 'newsectionsummary' )
->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
}
} elseif ( $this->summary !== '' ) {
@@ -1674,7 +1682,7 @@ class EditPage {
# This is a new section, so create a link to the new section
# in the revision summary.
$cleanSummary = $wgParser->stripSectionName( $this->summary );
- return wfMessage( 'newsectionsummary' )
+ return $this->context->msg( 'newsectionsummary' )
->rawParams( $cleanSummary )->inContentLanguage()->text();
}
return $this->summary;
@@ -1838,8 +1846,17 @@ class EditPage {
} 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();
}
@@ -2349,7 +2366,7 @@ class EditPage {
if ( $displayTitle === false ) {
$displayTitle = $contextTitle->getPrefixedText();
}
- $wgOut->setPageTitle( wfMessage( $msg, $displayTitle ) );
+ $wgOut->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
# Transmit the name of the message to JavaScript for live preview
# Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys
$wgOut->addJsConfigVars( [
@@ -2434,7 +2451,7 @@ class EditPage {
# Try to add a custom edit intro, or use the standard one if this is not possible.
if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
$helpLink = wfExpandUrl( Skin::makeInternalOrExternalUrl(
- wfMessage( 'helppage' )->inContentLanguage()->text()
+ $this->context->msg( 'helppage' )->inContentLanguage()->text()
) );
if ( $wgUser->isLoggedIn() ) {
$wgOut->wrapWikiMsg(
@@ -2624,7 +2641,7 @@ class EditPage {
. Html::rawElement(
'label',
[ 'for' => 'wpAntispam' ],
- wfMessage( 'simpleantispam-label' )->parse()
+ $this->context->msg( 'simpleantispam-label' )->parse()
)
. Xml::element(
'input',
@@ -2654,8 +2671,8 @@ class EditPage {
: 'confirmrecreate';
$wgOut->addHTML(
''
@@ -3021,7 +3063,7 @@ class EditPage {
]
);
} else {
- if ( !wfMessage( 'longpage-hint' )->isDisabled() ) {
+ if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
$wgOut->wrapWikiMsg( "
\n$1\n
",
[
'longpage-hint',
@@ -3102,7 +3144,7 @@ class EditPage {
return;
}
}
- $labelText = wfMessage( $isSubjectPreview ? 'subject' : 'summary' )->parse();
+ $labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse();
list( $label, $input ) = $this->getSummaryInput(
$summary,
$labelText,
@@ -3129,13 +3171,14 @@ class EditPage {
global $wgParser;
if ( $isSubjectPreview ) {
- $summary = wfMessage( 'newsectionsummary' )->rawParams( $wgParser->stripSectionName( $summary ) )
+ $summary = $this->context->msg( 'newsectionsummary' )
+ ->rawParams( $wgParser->stripSectionName( $summary ) )
->inContentLanguage()->text();
}
$message = $isSubjectPreview ? 'subject-preview' : 'summary-preview';
- $summary = wfMessage( $message )->parse()
+ $summary = $this->context->msg( $message )->parse()
. Linker::commentBlock( $summary, $this->mTitle, $isSubjectPreview );
return Xml::tags( 'div', [ 'class' => 'mw-summary-preview' ], $summary );
}
@@ -3257,6 +3300,12 @@ HTML
'id' => $name,
'cols' => $wgUser->getIntOption( 'cols' ),
'rows' => $wgUser->getIntOption( 'rows' ),
+ // 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' ),
// Avoid PHP notices when appending preferences
// (appending allows customAttribs['style'] to still work).
'style' => ''
@@ -3300,7 +3349,7 @@ HTML
try {
$this->showDiff();
} catch ( MWContentSerializationException $ex ) {
- $msg = wfMessage(
+ $msg = $this->context->msg(
'content-failed-to-parse',
$this->contentModel,
$this->contentFormat,
@@ -3375,8 +3424,8 @@ HTML
}
if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) {
- $oldtitle = wfMessage( $oldtitlemsg )->parse();
- $newtitle = wfMessage( 'yourtext' )->parse();
+ $oldtitle = $this->context->msg( $oldtitlemsg )->parse();
+ $newtitle = $this->context->msg( 'yourtext' )->parse();
if ( !$oldContent ) {
$oldContent = $newContent->getContentHandler()->makeEmptyContent();
@@ -3403,7 +3452,7 @@ HTML
*/
protected function showHeaderCopyrightWarning() {
$msg = 'editpage-head-copy-warn';
- if ( !wfMessage( $msg )->isDisabled() ) {
+ if ( !$this->context->msg( $msg )->isDisabled() ) {
global $wgOut;
$wgOut->wrapWikiMsg( "
\n$1\n
",
'editpage-head-copy-warn' );
@@ -3421,7 +3470,7 @@ HTML
protected function showTosSummary() {
$msg = 'editpage-tos-summary';
Hooks::run( 'EditPageTosSummary', [ $this->mTitle, &$msg ] );
- if ( !wfMessage( $msg )->isDisabled() ) {
+ if ( !$this->context->msg( $msg )->isDisabled() ) {
global $wgOut;
$wgOut->addHTML( '
' );
$wgOut->addWikiMsg( $msg );
@@ -3432,7 +3481,7 @@ HTML
protected function showEditTools() {
global $wgOut;
$wgOut->addHTML( '
' .
- wfMessage( 'edittools' )->inContentLanguage()->parse() .
+ $this->context->msg( 'edittools' )->inContentLanguage()->parse() .
'
' );
}
@@ -3453,7 +3502,7 @@ HTML
* @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',
@@ -3466,8 +3515,12 @@ HTML
// 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 "
\n" .
- call_user_func_array( 'wfMessage', $copywarnMsg )->$format() . "\n
";
+ $msg->$format() . "\n
";
}
/**
@@ -3514,19 +3567,19 @@ HTML
if ( $cancel !== '' ) {
$cancel .= Html::element( 'span',
[ 'class' => 'mw-editButtons-pipe-separator' ],
- wfMessage( 'pipe-separator' )->text() );
+ $this->context->msg( 'pipe-separator' )->text() );
}
- $message = wfMessage( 'edithelppage' )->inContentLanguage()->text();
+ $message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text();
$edithelpurl = Skin::makeInternalOrExternalUrl( $message );
$attrs = [
'target' => 'helpwindow',
'href' => $edithelpurl,
];
- $edithelp = Html::linkButton( wfMessage( 'edithelp' )->text(),
+ $edithelp = Html::linkButton( $this->context->msg( 'edithelp' )->text(),
$attrs, [ 'mw-ui-quiet' ] ) .
- wfMessage( 'word-separator' )->escaped() .
- wfMessage( 'newwindow' )->parse();
+ $this->context->msg( 'word-separator' )->escaped() .
+ $this->context->msg( 'newwindow' )->parse();
$wgOut->addHTML( "
{$cancel}\n" );
$wgOut->addHTML( "
{$edithelp}\n" );
@@ -3564,8 +3617,8 @@ HTML
$de = $handler->createDifferenceEngine( $this->mArticle->getContext() );
$de->setContent( $content2, $content1 );
$de->showDiff(
- wfMessage( 'yourtext' )->parse(),
- wfMessage( 'storedversion' )->text()
+ $this->context->msg( 'yourtext' )->parse(),
+ $this->context->msg( 'storedversion' )->text()
);
$wgOut->wrapWikiMsg( '
$1
', "yourtext" );
@@ -3587,7 +3640,7 @@ HTML
return Linker::linkKnown(
$this->getContextTitle(),
- wfMessage( 'cancel' )->parse(),
+ $this->context->msg( 'cancel' )->parse(),
Html::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ),
$cancelParams
);
@@ -3664,11 +3717,11 @@ HTML
// Quick paranoid permission checks...
if ( is_object( $data ) ) {
if ( $data->log_deleted & LogPage::DELETED_USER ) {
- $data->user_name = wfMessage( 'rev-deleted-user' )->escaped();
+ $data->user_name = $this->context->msg( 'rev-deleted-user' )->escaped();
}
if ( $data->log_deleted & LogPage::DELETED_COMMENT ) {
- $data->log_comment = wfMessage( 'rev-deleted-comment' )->escaped();
+ $data->log_comment = $this->context->msg( 'rev-deleted-comment' )->escaped();
}
}
@@ -3695,7 +3748,8 @@ HTML
// string, which happens when you initially edit
// a category page, due to automatic preview-on-open.
$parsedNote = $wgOut->parse( "
" .
- wfMessage( 'session_fail_preview_html' )->text() . "
", true, /* interface */true );
+ $this->context->msg( 'session_fail_preview_html' )->text() . "
",
+ true, /* interface */true );
}
$stats->increment( 'edit.failures.session_loss' );
return $parsedNote;
@@ -3717,22 +3771,22 @@ HTML
# provide a anchor link to the editform
$continueEditing = '" .
- wfMessage( "{$level}{$format}preview" )->text() .
+ $this->context->msg( "{$level}{$format}preview" )->text() .
' ' . $continueEditing . "
";
}
}
@@ -3789,7 +3843,7 @@ HTML
}
} catch ( MWContentSerializationException $ex ) {
- $m = wfMessage(
+ $m = $this->context->msg(
'content-failed-to-parse',
$this->contentModel,
$this->contentFormat,
@@ -3801,13 +3855,13 @@ HTML
if ( $this->isConflict ) {
$conflict = '\n" .
- '" .
+ '" .
$wgOut->parse( $note, true, /* interface */true ) . $conflict . "
\n";
$pageViewLang = $this->mTitle->getPageViewLanguage();
@@ -4027,11 +4081,11 @@ HTML
// don't show the minor edit checkbox if it's a new page or section
if ( !$this->isNew ) {
$checkboxes['minor'] = '';
- $minorLabel = wfMessage( 'minoredit' )->parse();
+ $minorLabel = $this->context->msg( 'minoredit' )->parse();
if ( $wgUser->isAllowed( 'minoredit' ) ) {
$attribs = [
'tabindex' => ++$tabindex,
- 'accesskey' => wfMessage( 'accesskey-minoredit' )->text(),
+ 'accesskey' => $this->context->msg( 'accesskey-minoredit' )->text(),
'id' => 'wpMinoredit',
];
$minorEditHtml =
@@ -4050,12 +4104,12 @@ HTML
}
}
- $watchLabel = wfMessage( 'watchthis' )->parse();
+ $watchLabel = $this->context->msg( 'watchthis' )->parse();
$checkboxes['watch'] = '';
if ( $wgUser->isLoggedIn() ) {
$attribs = [
'tabindex' => ++$tabindex,
- 'accesskey' => wfMessage( 'accesskey-watch' )->text(),
+ 'accesskey' => $this->context->msg( 'accesskey-watch' )->text(),
'id' => 'wpWatchthis',
];
$watchThisHtml =
@@ -4095,13 +4149,13 @@ HTML
} else {
$buttonLabelKey = !$this->mTitle->exists() ? 'savearticle' : 'savechanges';
}
- $buttonLabel = wfMessage( $buttonLabelKey )->text();
+ $buttonLabel = $this->context->msg( $buttonLabelKey )->text();
$attribs = [
'id' => 'wpSave',
'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 = [
@@ -4109,7 +4163,7 @@ HTML
'name' => 'wpPreview',
'tabindex' => $tabindex,
] + Linker::tooltipAndAccesskeyAttribs( 'preview' );
- $buttons['preview'] = Html::submitButton( wfMessage( 'showpreview' )->text(),
+ $buttons['preview'] = Html::submitButton( $this->context->msg( 'showpreview' )->text(),
$attribs );
$buttons['live'] = '';
@@ -4118,7 +4172,7 @@ HTML
'name' => 'wpDiff',
'tabindex' => ++$tabindex,
] + Linker::tooltipAndAccesskeyAttribs( 'diff' );
- $buttons['diff'] = Html::submitButton( wfMessage( 'showdiff' )->text(),
+ $buttons['diff'] = Html::submitButton( $this->context->msg( 'showdiff' )->text(),
$attribs );
Hooks::run( 'EditPageBeforeEditButtons', [ &$this, &$buttons, &$tabindex ] );
@@ -4132,9 +4186,9 @@ HTML
function noSuchSectionPage() {
global $wgOut;
- $wgOut->prepareErrorPage( wfMessage( 'nosuchsectiontitle' ) );
+ $wgOut->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) );
- $res = wfMessage( 'nosuchsectiontext', $this->section )->parseAsBlock();
+ $res = $this->context->msg( 'nosuchsectiontext', $this->section )->parseAsBlock();
Hooks::run( 'EditPageNoSuchSection', [ &$this, &$res ] );
$wgOut->addHTML( $res );
@@ -4153,7 +4207,7 @@ HTML
if ( is_array( $match ) ) {
$match = $wgLang->listToText( $match );
}
- $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );
+ $wgOut->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) );
$wgOut->addHTML( '' );
$wgOut->addWikiMsg( 'spamprotectiontext' );
@@ -4219,7 +4273,7 @@ HTML
protected function safeUnicodeOutput( $text ) {
return $this->checkUnicodeCompliantBrowser()
? $text
- : $this->makesafe( $text );
+ : $this->makeSafe( $text );
}
/**