// Allow extensions to modify form data
Hooks::run( 'EditPage::importFormData', [ $this, $request ] );
-
}
/**
// being set. This is used by ConfirmEdit to display a captcha
// without any error message cruft.
} else {
- $this->hookError = $this->formatStatusErrors( $status );
+ $this->hookError = $status->getWikiText();
}
// Use the existing $status->value if the hook set it
if ( !$status->value ) {
} 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
- $this->hookError = $this->formatStatusErrors( $status );
+ $this->hookError = $status->getWikiText();
$status->fatal( 'hookaborted' );
$status->value = self::AS_HOOK_ERROR_EXPECTED;
return false;
return true;
}
- /**
- * Wrap status errors in an errorbox for increased visiblity
- *
- * @param Status $status
- * @return string
- */
- private function formatStatusErrors( Status $status ) {
- $errmsg = $status->getHTML(
- 'edit-error-short',
- 'edit-error-long',
- $this->context->getLanguage()
- );
- return <<<ERROR
-<div class="errorbox">
-{$errmsg}
-</div>
-<br clear="all" />
-ERROR;
- }
-
/**
* Return the summary to be used for a new section.
*
* @return bool
*/
private function mergeChangesIntoContent( &$editContent ) {
-
$db = wfGetDB( DB_MASTER );
// This is the revision the editor started from
$this->setHeaders();
- if ( $this->showHeader() === false ) {
+ $this->addTalkPageText();
+ $this->addEditNotices();
+
+ if ( !$this->isConflict &&
+ $this->section != '' &&
+ !$this->isSectionEditSupported() ) {
+ // We use $this->section to much before this and getVal('wgSection') directly in other places
+ // at this point we can't reset $this->section to '' to fallback to non-section editing.
+ // Someone is welcome to try refactoring though
+ $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
return;
}
+ $this->showHeader();
+
$wgOut->addHTML( $this->editFormPageTop );
if ( $wgUser->getOption( 'previewontop' ) ) {
if ( !$wgUser->getOption( 'previewontop' ) ) {
$this->displayPreviewArea( $previewOutput, false );
}
-
}
/**
return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
$templateListFormatter->format( $templates, $type )
);
-
}
/**
}
}
- /**
- * @return bool
- */
protected function showHeader() {
- global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
+ global $wgOut, $wgUser;
global $wgAllowUserCss, $wgAllowUserJs;
- if ( $this->mTitle->isTalkPage() ) {
- $wgOut->addWikiMsg( 'talkpagetext' );
- }
-
- // 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>'
- );
- }
- }
-
if ( $this->isConflict ) {
- $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
+ $this->addExplainConflictHeader( $wgOut );
$this->editRevId = $this->page->getLatest();
} else {
- if ( $this->section != '' && !$this->isSectionEditSupported() ) {
- // We use $this->section to much before this and getVal('wgSection') directly in other places
- // at this point we can't reset $this->section to '' to fallback to non-section editing.
- // Someone is welcome to try refactoring though
- $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
- return false;
- }
-
if ( $this->section != '' && $this->section != 'new' ) {
if ( !$this->summary && !$this->preview && !$this->diff ) {
$sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object
}
}
- if ( $this->mTitle->isProtected( 'edit' ) &&
- MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
- ) {
- # Is the title semi-protected?
- if ( $this->mTitle->isSemiProtected() ) {
- $noticeMsg = 'semiprotectedpagewarning';
- } else {
- # Then it must be protected based on static groups (regular)
- $noticeMsg = 'protectedpagewarning';
- }
- LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
- [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] );
- }
- if ( $this->mTitle->isCascadeProtected() ) {
- # Is this page under cascading protection from some source pages?
- /** @var Title[] $cascadeSources */
- list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
- $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
- $cascadeSourcesCount = count( $cascadeSources );
- if ( $cascadeSourcesCount > 0 ) {
- # Explain, and list the titles responsible
- foreach ( $cascadeSources as $page ) {
- $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
- }
- }
- $notice .= '</div>';
- $wgOut->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] );
- }
- if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
- LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
- [ 'lim' => 1,
- 'showIfEmpty' => false,
- 'msgKey' => [ 'titleprotectedwarning' ],
- 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
- }
+ $this->addPageProtectionWarningHeaders();
- if ( $this->contentLength === false ) {
- $this->contentLength = strlen( $this->textbox1 );
- }
+ $this->addLongPageWarningHeader();
- if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) {
- $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
- [
- 'longpageerror',
- $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ),
- $wgLang->formatNum( $wgMaxArticleSize )
- ]
- );
- } else {
- if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
- $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
- [
- 'longpage-hint',
- $wgLang->formatSize( strlen( $this->textbox1 ) ),
- strlen( $this->textbox1 )
- ]
- );
- }
- }
# Add header copyright warning
$this->showHeaderCopyrightWarning();
-
- return true;
}
/**
global $wgOut, $wgUser;
$wikitext = $this->safeUnicodeOutput( $text );
- if ( strval( $wikitext ) !== '' ) {
- // Ensure there's a newline at the end, otherwise adding lines
- // is awkward.
- // But don't add a newline if the ext is empty, or Firefox in XHTML
- // mode will show an extra newline. A bit annoying.
- $wikitext .= "\n";
- }
+ $wikitext = $this->addNewLineAtEnd( $wikitext );
- $attribs = $customAttribs + [
- 'accesskey' => ',',
- 'id' => $name,
- 'cols' => $wgUser->getIntOption( 'cols' ),
- 'rows' => $wgUser->getIntOption( 'rows' ),
- // Avoid PHP notices when appending preferences
- // (appending allows customAttribs['style'] to still work).
- '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();
+ $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $wgUser );
$wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) );
}
] ) .
Html::openElement( 'tbody' );
- foreach ( $output->getLimitReportData()['limitreport'] as $key => $value ) {
+ foreach ( $output->getLimitReportData() as $key => $value ) {
if ( Hooks::run( 'ParserLimitReportFormat',
[ $key, &$value, &$limitReport, true, true ]
) ) {
- $keyMsg = wfMessage( "limitreport-$key" );
- $valueMsg = wfMessage(
- [ "limitreport-$key-value-html", "limitreport-$key-value" ]
- );
+ $keyMsg = wfMessage( $key );
+ $valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] );
if ( !$valueMsg->exists() ) {
$valueMsg = new RawMessage( '$1' );
}
if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
- // If it's a value/limit array, convert it for $1/$2
- if ( is_array( $value ) && isset( $value['value'] ) ) {
- $value = [ $value['value'], $value['limit'] ];
- }
$limitReport .= Html::openElement( 'tr' ) .
Html::rawElement( 'th', null, $keyMsg->parse() ) .
Html::rawElement( 'td', null, $valueMsg->params( $value )->parse() ) .
// 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' );
+ }
+ }
+
+ /**
+ * @since 1.29
+ */
+ protected function addLongPageWarningHeader() {
+ global $wgMaxArticleSize, $wgOut, $wgLang;
+
+ if ( $this->contentLength === false ) {
+ $this->contentLength = strlen( $this->textbox1 );
+ }
+
+ if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) {
+ $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
+ [
+ 'longpageerror',
+ $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ),
+ $wgLang->formatNum( $wgMaxArticleSize )
+ ]
+ );
+ } else {
+ if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
+ $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
+ [
+ 'longpage-hint',
+ $wgLang->formatSize( strlen( $this->textbox1 ) ),
+ strlen( $this->textbox1 )
+ ]
+ );
+ }
+ }
+ }
+
+ /**
+ * @since 1.29
+ */
+ protected function addPageProtectionWarningHeaders() {
+ global $wgOut;
+
+ if ( $this->mTitle->isProtected( 'edit' ) &&
+ MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
+ ) {
+ # Is the title semi-protected?
+ if ( $this->mTitle->isSemiProtected() ) {
+ $noticeMsg = 'semiprotectedpagewarning';
+ } else {
+ # Then it must be protected based on static groups (regular)
+ $noticeMsg = 'protectedpagewarning';
+ }
+ LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
+ [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] );
+ }
+ if ( $this->mTitle->isCascadeProtected() ) {
+ # Is this page under cascading protection from some source pages?
+ /** @var Title[] $cascadeSources */
+ list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
+ $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
+ $cascadeSourcesCount = count( $cascadeSources );
+ if ( $cascadeSourcesCount > 0 ) {
+ # Explain, and list the titles responsible
+ foreach ( $cascadeSources as $page ) {
+ $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
+ }
+ }
+ $notice .= '</div>';
+ $wgOut->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] );
+ }
+ if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
+ LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
+ [ 'lim' => 1,
+ 'showIfEmpty' => false,
+ 'msgKey' => [ 'titleprotectedwarning' ],
+ 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
+ }
+ }
+
+ /**
+ * @param OutputPage &$out
+ * @since 1.29
+ */
+ protected function addExplainConflictHeader( OutputPage &$out ) {
+ $out->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
+ }
+
+ /**
+ * @param string $name
+ * @param mixed[] $customAttribs
+ * @param User $wgUser
+ * @return mixed[]
+ * @since 1.29
+ */
+ protected function buildTextboxAttribs( $name, array $customAttribs, User $wgUser ) {
+ $attribs = $customAttribs + [
+ 'accesskey' => ',',
+ 'id' => $name,
+ 'cols' => $wgUser->getIntOption( 'cols' ),
+ 'rows' => $wgUser->getIntOption( 'rows' ),
+ // Avoid PHP notices when appending preferences
+ // (appending allows customAttribs['style'] to still work).
+ '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();
+
+ return $attribs;
+ }
+
+ /**
+ * @param string $wikitext
+ * @return string
+ * @since 1.29
+ */
+ protected function addNewLineAtEnd( $wikitext ) {
+ if ( strval( $wikitext ) !== '' ) {
+ // Ensure there's a newline at the end, otherwise adding lines
+ // is awkward.
+ // But don't add a newline if the text is empty, or Firefox in XHTML
+ // mode will show an extra newline. A bit annoying.
+ $wikitext .= "\n";
+ return $wikitext;
+ }
+ return $wikitext;
+ }
}