/** @var bool */
public $bot = true;
- /** @var null|string */
- public $contentModel = null;
+ /** @var string */
+ public $contentModel;
/** @var null|string */
public $contentFormat = null;
$this->enableApiEditOverride = $enableOverride;
}
- function submit() {
+ /**
+ * @deprecated since 1.29, call edit directly
+ */
+ public function submit() {
$this->edit();
}
* is made and all is well do we actually save and redirect to
* the newly-edited page.
*/
- function edit() {
+ public function edit() {
global $wgOut, $wgRequest, $wgUser;
// Allow extensions to modify/prevent this form or submission
if ( !Hooks::run( 'AlternateEdit', [ $this ] ) ) {
* @param WebRequest $request
* @throws ErrorPageError
*/
- function importFormData( &$request ) {
+ public function importFormData( &$request ) {
global $wgContLang, $wgUser;
# Section edit can come from either the form or a link
$this->recreate = false;
// When creating a new section, we can preload a section title by passing it as the
- // preloadtitle parameter in the URL (Bug 13100)
+ // preloadtitle parameter in the URL (T15100)
if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
$this->sectiontitle = $request->getVal( 'preloadtitle' );
// Once wpSummary isn't being use for setting section titles, we should delete this.
* Called on the first invocation, e.g. when a user clicks an edit link
* @return bool If the requested section is valid
*/
- function initialiseForm() {
+ public function initialiseForm() {
global $wgUser;
$this->edittime = $this->page->getTimestamp();
$this->editRevId = $this->page->getLatest();
}
$revision = $this->mArticle->getRevisionFetched();
if ( $revision === null ) {
- if ( !$this->contentModel ) {
- $this->contentModel = $this->getTitle()->getContentModel();
- }
$handler = ContentHandler::getForModelID( $this->contentModel );
-
return $handler->makeEmptyContent();
}
$content = $revision->getContent( Revision::FOR_THIS_USER, $user );
$content = $rev ? $rev->getContent( Revision::RAW ) : null;
if ( $content === false || $content === null ) {
- if ( !$this->contentModel ) {
- $this->contentModel = $this->getTitle()->getContentModel();
- }
$handler = ContentHandler::getForModelID( $this->contentModel );
-
return $handler->makeEmptyContent();
} elseif ( !$this->undidRev ) {
// Content models should always be the same since we error
* @return bool
* @private
*/
- function tokenOk( &$request ) {
+ public function tokenOk( &$request ) {
global $wgUser;
$token = $request->getVal( 'wpEditToken' );
$this->mTokenOk = $wgUser->matchEditToken( $token );
* AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some
* time.
*/
- function internalAttemptSave( &$result, $bot = false ) {
+ public function internalAttemptSave( &$result, $bot = false ) {
global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize;
global $wgContentHandlerUseDB;
// Don't save a new page if it's blank or if it's a MediaWiki:
// message with content equivalent to default (allow empty pages
- // in this case to disable messages, see bug 50124)
+ // in this case to disable messages, see T52124)
$defaultMessageText = $this->mTitle->getDefaultMessageText();
if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) {
$defaultText = $defaultMessageText;
* one might think of X as the "base revision", which is NOT what this returns.
* @return Revision Current version when the edit was started
*/
- function getBaseRevision() {
+ public function getBaseRevision() {
if ( !$this->mBaseRevision ) {
$db = wfGetDB( DB_MASTER );
$this->mBaseRevision = $this->editRevId
return false;
}
- function setHeaders() {
- global $wgOut, $wgUser, $wgAjaxEditStash, $wgCookieSetOnAutoblock;
+ public function setHeaders() {
+ global $wgOut, $wgUser, $wgAjaxEditStash;
$wgOut->addModules( 'mediawiki.action.edit' );
- if ( $wgCookieSetOnAutoblock === true ) {
- $wgOut->addModules( 'mediawiki.user.blockcookie' );
- }
$wgOut->addModuleStyles( 'mediawiki.action.edit.styles' );
if ( $wgUser->getOption( 'showtoolbar' ) ) {
}
# Give a notice if the user is editing a deleted/moved page...
if ( !$this->mTitle->exists() ) {
+ $dbr = wfGetDB( DB_REPLICA );
+
LogEventsList::showLogExtract( $wgOut, [ 'delete', 'move' ], $this->mTitle,
'',
[
'lim' => 10,
- 'conds' => [ "log_action != 'revision'" ],
+ 'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
'showIfEmpty' => false,
'msgKey' => [ 'recreate-moveddeleted-warn' ]
]
* The $formCallback parameter is deprecated since MediaWiki 1.25. Please
* use the EditPage::showEditForm:fields hook instead.
*/
- function showEditForm( $formCallback = null ) {
+ public function showEditForm( $formCallback = null ) {
global $wgOut, $wgUser;
# need to parse the preview early so that we know which templates are used,
return;
}
- $this->showHeader();
+ $this->showHeader();
$wgOut->addHTML( $this->editFormPageTop );
if ( $this->hasPresetSummary ) {
// If a summary has been preset using &summary= we don't want to prompt for
// a different summary. Only prompt for a summary if the summary is blanked.
- // (Bug 17416)
+ // (T19416)
$this->autoSumm = md5( '' );
}
*
* @return array An array in the format [ $label, $input ]
*/
- function getSummaryInput( $summary = "", $labelText = null,
+ public function getSummaryInput( $summary = "", $labelText = null,
$inputAttrs = null, $spanLabelAttrs = null
) {
// Note: the maxlength is overridden in JS to 255 and to make it use UTF-8 bytes, not characters.
*/
protected function showPreview( $text ) {
global $wgOut;
- if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
+ if ( $this->mArticle instanceof CategoryPage ) {
$this->mArticle->openShowCategory();
}
# This hook seems slightly odd here, but makes things more
# consistent for extensions.
Hooks::run( 'OutputPageBeforeHTML', [ &$wgOut, &$text ] );
$wgOut->addHTML( $text );
- if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
+ if ( $this->mArticle instanceof CategoryPage ) {
$this->mArticle->closeShowCategory();
}
}
* If this is a section edit, we'll replace the section as for final
* save and then make a comparison.
*/
- function showDiff() {
+ public function showDiff() {
global $wgUser, $wgContLang, $wgOut;
$oldtitlemsg = 'currentrev';
// Avoid PHP 7.1 warning of passing $this by reference
$editPage = $this;
if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$wgOut ] ) ) {
- $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
- $stats->increment( 'edit.failures.conflict' );
- // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
- if (
- $this->mTitle->getNamespace() >= NS_MAIN &&
- $this->mTitle->getNamespace() <= NS_CATEGORY_TALK
- ) {
- $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() );
- }
+ $this->incrementConflictStats();
$wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
}
}
+ protected function incrementConflictStats() {
+ $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+ $stats->increment( 'edit.failures.conflict' );
+ // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
+ if (
+ $this->mTitle->getNamespace() >= NS_MAIN &&
+ $this->mTitle->getNamespace() <= NS_CATEGORY_TALK
+ ) {
+ $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() );
+ }
+ }
+
/**
* @return string
*/
* @throws MWException
* @return string
*/
- function getPreviewText() {
+ public function getPreviewText() {
global $wgOut, $wgRawHtml, $wgLang;
global $wgAllowUserCss, $wgAllowUserJs;
- $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
-
if ( $wgRawHtml && !$this->mTokenOk ) {
// Could be an offsite preview attempt. This is very unsafe if
// HTML is enabled, as it could be an attack.
$this->context->msg( 'session_fail_preview_html' )->text() . "</div>",
true, /* interface */true );
}
- $stats->increment( 'edit.failures.session_loss' );
+ $this->incrementEditFailureStats( 'session_loss' );
return $parsedNote;
}
if ( $this->mTriedSave && !$this->mTokenOk ) {
if ( $this->mTokenOkExceptSuffix ) {
$note = $this->context->msg( 'token_suffix_mismatch' )->plain();
- $stats->increment( 'edit.failures.bad_token' );
+ $this->incrementEditFailureStats( 'bad_token' );
} else {
$note = $this->context->msg( 'session_fail_preview' )->plain();
- $stats->increment( 'edit.failures.session_loss' );
+ $this->incrementEditFailureStats( 'session_loss' );
}
} elseif ( $this->incompleteForm ) {
$note = $this->context->msg( 'edit_form_incomplete' )->plain();
if ( $this->mTriedSave ) {
- $stats->increment( 'edit.failures.incomplete_form' );
+ $this->incrementEditFailureStats( 'incomplete_form' );
}
} else {
$note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
return $previewhead . $previewHTML . $this->previewTextAfterContent;
}
+ private function incrementEditFailureStats( $failureType ) {
+ $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+ $stats->increment( 'edit.failures.' . $failureType );
+ }
+
/**
* Get parser options for a preview
* @return ParserOptions
/**
* @return array
*/
- function getTemplates() {
+ public function getTemplates() {
if ( $this->preview || $this->section != '' ) {
$templates = [];
if ( !isset( $this->mParserOutput ) ) {
* @param Title $title Title object for the page being edited (optional)
* @return string
*/
- static function getEditToolbar( $title = null ) {
+ public static function getEditToolbar( $title = null ) {
global $wgContLang, $wgOut;
global $wgEnableUploads, $wgForeignFileRepos;
* Creates a basic error page which informs the user that
* they have attempted to edit a nonexistent section.
*/
- function noSuchSectionPage() {
+ public function noSuchSectionPage() {
global $wgOut;
$wgOut->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) );