*/
const AS_CONTENT_TOO_BIG = 216;
- /**
- * Status: User cannot edit? (not used)
- */
- const AS_USER_CANNOT_EDIT = 217;
-
/**
* Status: this anonymous user is not allowed to edit this page
*/
const AS_NO_CREATE_PERMISSION = 223;
/**
- * Status: user tried to create a blank page
+ * Status: user tried to create a blank page and wpIgnoreBlankArticle == false
*/
const AS_BLANK_ARTICLE = 224;
*/
const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229;
- /**
- * not used
- */
- const AS_OK = 230;
-
/**
* Status: WikiPage::doEdit() was unsuccessful
*/
/** @var bool */
protected $allowBlankSummary = false;
+ /** @var bool */
+ protected $blankArticle = false;
+
+ /** @var bool */
+ protected $allowBlankArticle = false;
+
/** @var string */
protected $autoSumm = '';
*
* @param string $modelId The ID of the content model to test. Use CONTENT_MODEL_XXX constants.
* @return bool
- * @throws MWException if $modelId has no known handler
+ * @throws MWException If $modelId has no known handler
*/
public function isSupportedContentModel( $modelId ) {
return $this->allowNonTextContent ||
* Subclasses may override this to replace the default behavior, which is
* to check ContentHandler::supportsSections.
*
- * @return bool true if this edit page supports sections, false otherwise.
+ * @return bool True if this edit page supports sections, false otherwise.
*/
protected function isSectionEditSupported() {
$contentHandler = ContentHandler::getForTitle( $this->mTitle );
}
$this->autoSumm = $request->getText( 'wpAutoSummary' );
+
+ $this->allowBlankArticle = $request->getBool( 'wpIgnoreBlankArticle' );
} else {
# Not a posted form? Start with nothing.
wfDebug( __METHOD__ . ": Not a posted form.\n" );
* Fetch initial editing page content.
*
* @param string|bool $def_text
- * @return string|bool string on success, $def_text for invalid sections
+ * @return string|bool String on success, $def_text for invalid sections
* @private
* @deprecated since 1.21, get WikiPage::getContent() instead.
*/
* Get the contents to be preloaded into the box, either set by
* an earlier setPreloadText() or by loading the given page.
*
- * @param string $preload representing the title to preload from.
+ * @param string $preload Representing the title to preload from.
*
* @return string
*
* If the variable were set on the server, it would be cached, which is unwanted
* since the post-edit state should only apply to the load right after the save.
*
- * @param $statusValue int The status value (to check for new article status)
+ * @param int $statusValue The status value (to check for new article status)
*/
protected function setPostEditCookie( $statusValue ) {
$revisionId = $this->mArticle->getLatest();
/**
* Attempt submission
* @throws UserBlockedError|ReadOnlyError|ThrottledError|PermissionsError
- * @return bool false if output is done, true if the rest of the form should be displayed
+ * @return bool False if output is done, true if the rest of the form should be displayed
*/
public function attemptSave() {
global $wgUser;
* @param array|bool $resultDetails
*
* @throws ErrorPageError
- * @return bool false, if output is done, true if rest of the form should be displayed
+ * @return bool False, if output is done, true if rest of the form should be displayed
*/
private function handleStatus( Status $status, $resultDetails ) {
global $wgUser, $wgOut;
case self::AS_TEXTBOX_EMPTY:
case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
case self::AS_END:
+ case self::AS_BLANK_ARTICLE:
return true;
case self::AS_HOOK_ERROR:
$wgOut->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
return false;
- case self::AS_BLANK_ARTICLE:
- $wgOut->redirect( $this->getContextTitle()->getFullURL() );
- return false;
-
case self::AS_SPAM_ERROR:
$this->spamPageWithContent( $resultDetails['spam'] );
return false;
return true;
}
+ /**
+ * Return the summary to be used for a new section.
+ *
+ * @param string $sectionanchor Set to the section anchor text
+ * @return string
+ */
+ private function newSectionSummary( &$sectionanchor = null ) {
+ global $wgParser;
+
+ if ( $this->sectiontitle !== '' ) {
+ $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle );
+ // If no edit summary was specified, create one automatically from the section
+ // title and have it link to the new section. Otherwise, respect the summary as
+ // passed.
+ if ( $this->summary === '' ) {
+ $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
+ return wfMessage( 'newsectionsummary' )
+ ->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
+ }
+ } elseif ( $this->summary !== '' ) {
+ $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
+ # 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' )
+ ->rawParams( $cleanSummary )->inContentLanguage()->text();
+ } else {
+ return $this->summary;
+ }
+ }
+
/**
* Attempt submission (no UI)
*
$defaultText = '';
}
- if ( $this->textbox1 === $defaultText ) {
+ if ( !$this->allowBlankArticle && $this->textbox1 === $defaultText ) {
+ $this->blankArticle = true;
+ $status->fatal( 'blankarticle' );
$status->setResult( false, self::AS_BLANK_ARTICLE );
wfProfileOut( __METHOD__ );
return $status;
if ( $this->sectiontitle !== '' ) {
// Insert the section title above the content.
$content = $content->addSectionHeader( $this->sectiontitle );
-
- // Jump to the new section
- $result['sectionanchor'] =
- $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle );
-
- // If no edit summary was specified, create one automatically from the section
- // title and have it link to the new section. Otherwise, respect the summary as
- // passed.
- if ( $this->summary === '' ) {
- $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
- $this->summary = wfMessage( 'newsectionsummary' )
- ->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
- }
} elseif ( $this->summary !== '' ) {
// Insert the section title above the content.
$content = $content->addSectionHeader( $this->summary );
-
- // Jump to the new section
- $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
-
- // Create a link to the new section from the edit summary.
- $cleanSummary = $wgParser->stripSectionName( $this->summary );
- $this->summary = wfMessage( 'newsectionsummary' )
- ->rawParams( $cleanSummary )->inContentLanguage()->text();
}
+ $this->summary = $this->newSectionSummary( $result['sectionanchor'] );
}
$status->value = self::AS_SUCCESS_NEW_ARTICLE;
$this->isConflict = true;
if ( $this->section == 'new' ) {
if ( $this->mArticle->getUserText() == $wgUser->getName() &&
- $this->mArticle->getComment() == $this->summary ) {
+ $this->mArticle->getComment() == $this->newSectionSummary()
+ ) {
// Probably a duplicate submission of a new comment.
// This can happen when squid resends a request after
// a timeout but the first one actually went through.
wfProfileIn( __METHOD__ . '-sectionanchor' );
$sectionanchor = '';
if ( $this->section == 'new' ) {
- if ( $this->sectiontitle !== '' ) {
- $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle );
- // If no edit summary was specified, create one automatically from the section
- // title and have it link to the new section. Otherwise, respect the summary as
- // passed.
- if ( $this->summary === '' ) {
- $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
- $this->summary = wfMessage( 'newsectionsummary' )
- ->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
- }
- } elseif ( $this->summary !== '' ) {
- $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
- # This is a new section, so create a link to the new section
- # in the revision summary.
- $cleanSummary = $wgParser->stripSectionName( $this->summary );
- $this->summary = wfMessage( 'newsectionsummary' )
- ->rawParams( $cleanSummary )->inContentLanguage()->text();
- }
+ $this->summary = $this->newSectionSummary( $sectionanchor );
} elseif ( $this->section != '' ) {
# Try to get a section anchor from the section source, redirect
# to edited section if header found.
// Do this in its own transaction to reduce contention...
$dbw = wfGetDB( DB_MASTER );
- $dbw->onTransactionIdle( function() use ( $dbw, $title, $watch, $wgUser, $fname ) {
+ $dbw->onTransactionIdle( function () use ( $dbw, $title, $watch, $wgUser, $fname ) {
$dbw->begin( $fname );
WatchAction::doWatchOrUnwatch( $watch, $title, $wgUser );
$dbw->commit( $fname );
$username = $parts[0];
$user = User::newFromName( $username, false /* allow IP users*/ );
$ip = User::isIP( $username );
+ $block = Block::newFromTarget( $user, $user );
if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
$wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
array( 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ) );
- } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
+ } elseif ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) { # Show log extract if the user is currently blocked
LogEventsList::showLogExtract(
$wgOut,
'block',
- $user->getUserPage(),
+ MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
'',
array(
'lim' => 1,
* @param Content|null|bool|string $content
* @return string The editable text form of the content.
*
- * @throws MWException if $content is not an instance of TextContent and
+ * @throws MWException If $content is not an instance of TextContent and
* $this->allowNonTextContent is not true.
*/
protected function toEditText( $content ) {
* @return Content The content object created from $text. If $text was false
* or null, false resp. null will be returned instead.
*
- * @throws MWException if unserializing the text results in a Content
+ * @throws MWException If unserializing the text results in a Content
* object that is not an instance of TextContent and
* $this->allowNonTextContent is not true.
*/
$wgOut->addHTML( EditPage::getEditToolbar() );
}
+ if ( $this->blankArticle ) {
+ $wgOut->addHTML( Html::hidden( 'wpIgnoreBlankArticle', true ) );
+ }
+
if ( $this->isConflict ) {
// In an edit conflict bypass the overridable content form method
// and fallback to the raw wpTextbox1 since editconflicts can't be
* Extract the section title from current section text, if any.
*
* @param string $text
- * @return string|bool string or false
+ * @return string|bool String or false
*/
public static function extractSectionTitle( $text ) {
preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches );
*/
protected function showHeader() {
global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
+ global $wgAllowUserCss, $wgAllowUserJs;
if ( $this->mTitle->isTalkPage() ) {
$wgOut->addWikiMsg( 'talkpagetext' );
$wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1\n</div>", 'missingcommentheader' );
}
+ if ( $this->blankArticle ) {
+ $wgOut->wrapWikiMsg( "<div id='mw-blankarticle'>\n$1\n</div>", 'blankarticle' );
+ }
+
if ( $this->hookError !== '' ) {
$wgOut->addWikiText( $this->hookError );
}
);
}
if ( $this->formtype !== 'preview' ) {
- if ( $this->isCssSubpage ) {
+ if ( $this->isCssSubpage && $wgAllowUserCss ) {
$wgOut->wrapWikiMsg(
"<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
array( 'usercssyoucanpreview' )
);
}
- if ( $this->isJsSubpage ) {
+ if ( $this->isJsSubpage && $wgAllowUserJs ) {
$wgOut->wrapWikiMsg(
"<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
array( 'userjsyoucanpreview' )
}
/**
- * @param bool $isSubjectPreview true if this is the section subject/title
+ * @param bool $isSubjectPreview True if this is the section subject/title
* up top, or false if this is the comment summary
* down below the textarea
* @param string $summary The text of the summary to display
}
/**
- * @param bool $isSubjectPreview true if this is the section subject/title
+ * @param bool $isSubjectPreview True if this is the section subject/title
* up top, or false if this is the comment summary
* down below the textarea
* @param string $summary The text of the summary to display
*/
function getPreviewText() {
global $wgOut, $wgUser, $wgRawHtml, $wgLang;
+ global $wgAllowUserCss, $wgAllowUserJs;
wfProfileIn( __METHOD__ );
if ( $content->getModel() == CONTENT_MODEL_CSS ) {
$format = 'css';
+ if ( $level === 'user' && !$wgAllowUserCss ) {
+ $format = false;
+ }
} elseif ( $content->getModel() == CONTENT_MODEL_JAVASCRIPT ) {
$format = 'js';
+ if ( $level === 'user' && !$wgAllowUserJs ) {
+ $format = false;
+ }
} else {
$format = false;
}
$previewHTML = $parserOutput->getText();
$this->mParserOutput = $parserOutput;
- $wgOut->addParserOutputNoText( $parserOutput );
+ $wgOut->addParserOutputMetadata( $parserOutput );
if ( count( $parserOutput->getWarnings() ) ) {
$note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
public function getEditButtons( &$tabindex ) {
$buttons = array();
- // @todo FIXME: Hardcoded square brackets.
- $temp = array(
+ $attribs = array(
'id' => 'wpSave',
'name' => 'wpSave',
'type' => 'submit',
'tabindex' => ++$tabindex,
'value' => wfMessage( 'savearticle' )->text(),
- 'accesskey' => wfMessage( 'accesskey-save' )->text(),
- 'title' => wfMessage( 'tooltip-save' )->text()
- . ' [' . wfMessage( 'accesskey-save' )->text() . ']',
- );
- $buttons['save'] = Xml::element( 'input', $temp, '' );
+ ) + Linker::tooltipAndAccesskeyAttribs( 'save' );
+ $buttons['save'] = Xml::element( 'input', $attribs, '' );
++$tabindex; // use the same for preview and live preview
- // @todo FIXME: Hardcoded square brackets.
- $temp = array(
+ $attribs = array(
'id' => 'wpPreview',
'name' => 'wpPreview',
'type' => 'submit',
'tabindex' => $tabindex,
'value' => wfMessage( 'showpreview' )->text(),
- 'accesskey' => wfMessage( 'accesskey-preview' )->text(),
- 'title' => wfMessage( 'tooltip-preview' )->text()
- . ' [' . wfMessage( 'accesskey-preview' )->text() . ']',
- );
- $buttons['preview'] = Xml::element( 'input', $temp, '' );
+ ) + Linker::tooltipAndAccesskeyAttribs( 'preview' );
+ $buttons['preview'] = Xml::element( 'input', $attribs, '' );
$buttons['live'] = '';
- // @todo FIXME: Hardcoded square brackets.
- $temp = array(
+ $attribs = array(
'id' => 'wpDiff',
'name' => 'wpDiff',
'type' => 'submit',
'tabindex' => ++$tabindex,
'value' => wfMessage( 'showdiff' )->text(),
- 'accesskey' => wfMessage( 'accesskey-diff' )->text(),
- 'title' => wfMessage( 'tooltip-diff' )->text()
- . ' [' . wfMessage( 'accesskey-diff' )->text() . ']',
- );
- $buttons['diff'] = Xml::element( 'input', $temp, '' );
+ ) + Linker::tooltipAndAccesskeyAttribs( 'diff' );
+ $buttons['diff'] = Xml::element( 'input', $attribs, '' );
wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
return $buttons;