*/
var $mTitle;
private $mContextTitle = null;
- var $action;
+ var $action = 'submit';
var $isConflict = false;
var $isCssJsSubpage = false;
var $isCssSubpage = false;
# Placeholders for text injection by hooks (must be HTML)
# extensions should take care to _append_ to the present value
- public $editFormPageTop; // Before even the preview
- public $editFormTextTop;
- public $editFormTextBeforeContent;
- public $editFormTextAfterWarn;
- public $editFormTextAfterTools;
- public $editFormTextBottom;
- public $editFormTextAfterContent;
- public $previewTextAfterContent;
- public $mPreloadText;
+ public $editFormPageTop = ''; // Before even the preview
+ public $editFormTextTop = '';
+ public $editFormTextBeforeContent = '';
+ public $editFormTextAfterWarn = '';
+ public $editFormTextAfterTools = '';
+ public $editFormTextBottom = '';
+ public $editFormTextAfterContent = '';
+ public $previewTextAfterContent = '';
+ public $mPreloadText = '';
/* $didSave should be set to true whenever an article was succesfully altered. */
public $didSave = false;
* @todo document
* @param $article Article
*/
- function __construct( $article ) {
- $this->mArticle =& $article;
+ public function __construct( $article ) {
+ $this->mArticle = $article;
$this->mTitle = $article->getTitle();
- $this->action = 'submit';
-
- # Placeholders for text injection by hooks (empty per default)
- $this->editFormPageTop =
- $this->editFormTextTop =
- $this->editFormTextBeforeContent =
- $this->editFormTextAfterWarn =
- $this->editFormTextAfterTools =
- $this->editFormTextBottom =
- $this->editFormTextAfterContent =
- $this->previewTextAfterContent =
- $this->mPreloadText = "";
}
/**
* @return Article
*/
- function getArticle() {
+ public function getArticle() {
return $this->mArticle;
}
+ /**
+ * @since 1.19
+ * @return Title
+ */
+ public function getTitle() {
+ return $this->mTitle;
+ }
+
/**
* Set the context Title object
*
}
}
- /**
- * Fetch initial editing page content.
- *
- * @param $def_text string
- * @returns mixed string on success, $def_text for invalid sections
- * @private
- */
- function getContent( $def_text = '' ) {
- global $wgOut, $wgRequest, $wgParser;
-
- wfProfileIn( __METHOD__ );
- # Get variables from query string :P
- $section = $wgRequest->getVal( 'section' );
-
- $preload = $wgRequest->getVal( 'preload',
- // Custom preload text for new sections
- $section === 'new' ? 'MediaWiki:addsection-preload' : '' );
- $undoafter = $wgRequest->getVal( 'undoafter' );
- $undo = $wgRequest->getVal( 'undo' );
-
- // For message page not locally set, use the i18n message.
- // For other non-existent articles, use preload text if any.
- if ( !$this->mTitle->exists() ) {
- if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- # If this is a system message, get the default text.
- $text = $this->mTitle->getDefaultMessageText();
- if( $text === false ) {
- $text = $this->getPreloadedText( $preload );
- }
- } else {
- # If requested, preload some text.
- $text = $this->getPreloadedText( $preload );
- }
- // For existing pages, get text based on "undo" or section parameters.
- } else {
- $text = $this->mArticle->getContent();
- if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
- # If they got undoafter and undo round the wrong way, switch them
- list( $undo, $undoafter ) = array( $undoafter, $undo );
- }
- if ( $undo > 0 && $undo > $undoafter ) {
- # Undoing a specific edit overrides section editing; section-editing
- # doesn't work with undoing.
- if ( $undoafter ) {
- $undorev = Revision::newFromId( $undo );
- $oldrev = Revision::newFromId( $undoafter );
- } else {
- $undorev = Revision::newFromId( $undo );
- $oldrev = $undorev ? $undorev->getPrevious() : null;
- }
-
- # Sanity check, make sure it's the right page,
- # the revisions exist and they were not deleted.
- # Otherwise, $text will be left as-is.
- if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
- $undorev->getPage() == $oldrev->getPage() &&
- $undorev->getPage() == $this->mArticle->getID() &&
- !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
- !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
-
- $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
- if ( $undotext === false ) {
- # Warn the user that something went wrong
- $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' .
- wfMsgNoTrans( 'undo-failure' ) . '</div>', true, /* interface */true );
- } else {
- $text = $undotext;
- # Inform the user of our success and set an automatic edit summary
- $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' .
- wfMsgNoTrans( 'undo-success' ) . '</div>', true, /* interface */true );
- $firstrev = $oldrev->getNext();
- # If we just undid one rev, use an autosummary
- if ( $firstrev->mId == $undo ) {
- $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
- $this->undidRev = $undo;
- }
- $this->formtype = 'diff';
- }
- } else {
- // Failed basic sanity checks.
- // Older revisions may have been removed since the link
- // was created, or we may simply have got bogus input.
- $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' .
- wfMsgNoTrans( 'undo-norev' ) . '</div>', true, /* interface */true );
- }
- } elseif ( $section != '' ) {
- if ( $section == 'new' ) {
- $text = $this->getPreloadedText( $preload );
- } else {
- // Get section edit text (returns $def_text for invalid sections)
- $text = $wgParser->getSection( $text, $section, $def_text );
- }
- }
- }
-
- wfProfileOut( __METHOD__ );
- return $text;
- }
-
- /**
- * Use this method before edit() to preload some text into the edit box
- *
- * @param $text string
- */
- public function setPreloadedText( $text ) {
- $this->mPreloadText = $text;
- }
-
- /**
- * Get the contents to be preloaded into the box, either set by
- * an earlier setPreloadText() or by loading the given page.
- *
- * @param $preload String: representing the title to preload from.
- * @return String
- */
- protected function getPreloadedText( $preload ) {
- global $wgUser, $wgParser;
- if ( !empty( $this->mPreloadText ) ) {
- return $this->mPreloadText;
- } elseif ( $preload !== '' ) {
- $title = Title::newFromText( $preload );
- # Check for existence to avoid getting MediaWiki:Noarticletext
- if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
- $article = new Article( $title );
-
- if ( $article->isRedirect() ) {
- $title = Title::newFromRedirectRecurse( $article->getContent() );
- # Redirects to missing titles are displayed, to hidden pages are followed
- # Copying observed behaviour from ?action=view
- if ( $title->exists() ) {
- if ($title->userCanRead() ) {
- $article = new Article( $title );
- } else {
- return "";
- }
- }
- }
- $parserOptions = ParserOptions::newFromUser( $wgUser );
- return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions );
- }
- }
- return '';
- }
-
- /**
- * Check if a page was deleted while the user was editing it, before submit.
- * Note that we rely on the logging table, which hasn't been always there,
- * but that doesn't matter, because this only applies to brand new
- * deletes.
- */
- protected function wasDeletedSinceLastEdit() {
- if ( $this->deletedSinceEdit !== null ) {
- return $this->deletedSinceEdit;
- }
-
- $this->deletedSinceEdit = false;
-
- if ( $this->mTitle->isDeletedQuick() ) {
- $this->lastDelete = $this->getLastDelete();
- if ( $this->lastDelete ) {
- $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
- if ( $deleteTime > $this->starttime ) {
- $this->deletedSinceEdit = true;
- }
- }
- }
-
- return $this->deletedSinceEdit;
- }
-
- /**
- * Checks whether the user entered a skin name in uppercase,
- * e.g. "User:Example/Monobook.css" instead of "monobook.css"
- *
- * @return bool
- */
- protected function isWrongCaseCssJsPage() {
- if( $this->mTitle->isCssJsSubpage() ) {
- $name = $this->mTitle->getSkinFromCssJsSubpage();
- $skins = array_merge(
- array_keys( Skin::getSkinNames() ),
- array( 'common' )
- );
- return !in_array( $name, $skins )
- && in_array( strtolower( $name ), $skins );
- } else {
- return false;
- }
- }
-
function submit() {
$this->edit();
}
wfProfileIn( __METHOD__ );
wfDebug( __METHOD__.": enter\n" );
+ // If they used redlink=1 and the page exists, redirect to the main article
+ if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) {
+ $wgOut->redirect( $this->mTitle->getFullURL() );
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
$this->importFormData( $wgRequest );
$this->firsttime = false;
$this->preview = true;
}
- $wgOut->addModules( array( 'mediawiki.action.edit' ) );
-
- if ( $wgUser->getOption( 'uselivepreview', false ) ) {
- $wgOut->addModules( 'mediawiki.legacy.preview' );
+ if ( $this->save ) {
+ $this->formtype = 'save';
+ } elseif ( $this->preview ) {
+ $this->formtype = 'preview';
+ } elseif ( $this->diff ) {
+ $this->formtype = 'diff';
+ } else { # First time through
+ $this->firsttime = true;
+ if ( $this->previewOnOpen() ) {
+ $this->formtype = 'preview';
+ } else {
+ $this->formtype = 'initial';
+ }
}
- // Bug #19334: textarea jumps when editing articles in IE8
- $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
$permErrors = $this->getEditPermissionErrors();
if ( $permErrors ) {
wfDebug( __METHOD__ . ": User can't edit\n" );
- $content = $this->getContent( null );
- $content = $content === '' ? null : $content;
- $this->readOnlyPage( $content, true, $permErrors, 'edit' );
+ // Auto-block user's IP if the account was "hard" blocked
+ $wgUser->spreadAnyEditBlock();
+
+ $this->displayPermissionsError( $permErrors );
+
wfProfileOut( __METHOD__ );
return;
- } else {
- if ( $this->save ) {
- $this->formtype = 'save';
- } elseif ( $this->preview ) {
- $this->formtype = 'preview';
- } elseif ( $this->diff ) {
- $this->formtype = 'diff';
- } else { # First time through
- $this->firsttime = true;
- if ( $this->previewOnOpen() ) {
- $this->formtype = 'preview';
- } else {
- $this->formtype = 'initial';
- }
- }
}
- // If they used redlink=1 and the page exists, redirect to the main article
- if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) {
- $wgOut->redirect( $this->mTitle->getFullURL() );
+ $wgOut->addModules( array( 'mediawiki.action.edit' ) );
+
+ if ( $wgUser->getOption( 'uselivepreview', false ) ) {
+ $wgOut->addModules( 'mediawiki.legacy.preview' );
}
+ // Bug #19334: textarea jumps when editing articles in IE8
+ $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
wfProfileIn( __METHOD__."-business-end" );
return $permErrors;
}
+ /**
+ * Display a permissions error page, like OutputPage::showPermissionsErrorPage(),
+ * but with the following differences:
+ * - If redlink=1, the user will be redirect to the page
+ * - If there is content to display or the error occurs while either saving,
+ * previewing or showing the difference, it will be a
+ * "View source for ..." page displaying the source code after the error message.
+ *
+ * @since 1.19
+ * @param $permErrors Array of permissions errors, as returned by
+ * Title::getUserPermissionsErrors().
+ */
+ protected function displayPermissionsError( array $permErrors ) {
+ global $wgRequest, $wgOut;
+
+ if ( $wgRequest->getBool( 'redlink' ) ) {
+ // The edit page was reached via a red link.
+ // Redirect to the article page and let them click the edit tab if
+ // they really want a permission error.
+ $wgOut->redirect( $this->mTitle->getFullUrl() );
+ return;
+ }
+
+ $content = $this->getContent();
+
+ # Use the normal message if there's nothing to display
+ if ( $this->firsttime && $content === '' ) {
+ $action = $this->mTitle->exists() ? 'edit' :
+ ( $permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage' );
+ throw new PermissionsError( $action, $permErrors );
+ }
+
+ $wgOut->setPageTitle( wfMessage( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) );
+ $wgOut->addBacklinkSubtitle( $this->getContextTitle() );
+ $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) );
+ $wgOut->addHTML( "<hr />\n" );
+
+ # If the user made changes, preserve them when showing the markup
+ # (This happens when a user is blocked during edit, for instance)
+ if ( !$this->firsttime ) {
+ $content = $this->textbox1;
+ $wgOut->addWikiMsg( 'viewyourtext' );
+ } else {
+ $wgOut->addWikiMsg( 'viewsourcetext' );
+ }
+
+ $this->showTextbox( $content, 'wpTextbox1', array( 'readonly' ) );
+
+ $wgOut->addHTML( Html::rawElement( 'div', array( 'class' => 'templatesUsed' ),
+ Linker::formatTemplates( $this->getTemplates() ) ) );
+
+ if ( $this->mTitle->exists() ) {
+ $wgOut->returnToMain( null, $this->mTitle );
+ }
+ }
+
/**
* Show a read-only error
* Parameters are the same as OutputPage:readOnlyPage()
* Redirect to the article page if redlink=1
+ * @deprecated in 1.19; use displayPermissionsError() instead
*/
function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
global $wgRequest, $wgOut;
}
}
+ /**
+ * Checks whether the user entered a skin name in uppercase,
+ * e.g. "User:Example/Monobook.css" instead of "monobook.css"
+ *
+ * @return bool
+ */
+ protected function isWrongCaseCssJsPage() {
+ if( $this->mTitle->isCssJsSubpage() ) {
+ $name = $this->mTitle->getSkinFromCssJsSubpage();
+ $skins = array_merge(
+ array_keys( Skin::getSkinNames() ),
+ array( 'common' )
+ );
+ return !in_array( $name, $skins )
+ && in_array( strtolower( $name ), $skins );
+ } else {
+ return false;
+ }
+ }
+
/**
* Does this EditPage class support section editing?
* This is used by EditPage subclasses to indicate their ui cannot handle section edits
return true;
}
- /**
- * Returns the URL to use in the form's action attribute.
- * This is used by EditPage subclasses when simply customizing the action
- * variable in the constructor is not enough. This can be used when the
- * EditPage lives inside of a Special page rather than a custom page action.
- *
- * @param $title Title object for which is being edited (where we go to for &action= links)
- * @return string
- */
- protected function getActionURL( Title $title ) {
- return $title->getLocalURL( array( 'action' => $this->action ) );
- }
-
/**
* @todo document
* @param $request WebRequest
}
/**
- * Make sure the form isn't faking a user's credentials.
- *
- * @param $request WebRequest
- * @return bool
- * @private
+ * Initialise form fields in the object
+ * Called on the first invocation, e.g. when a user clicks an edit link
+ * @return bool -- if the requested section is valid
*/
- function tokenOk( &$request ) {
+ function initialiseForm() {
global $wgUser;
- $token = $request->getVal( 'wpEditToken' );
- $this->mTokenOk = $wgUser->matchEditToken( $token );
- $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
- return $this->mTokenOk;
+ $this->edittime = $this->mArticle->getTimestamp();
+ $this->textbox1 = $this->getContent( false );
+ // activate checkboxes if user wants them to be always active
+ # Sort out the "watch" checkbox
+ if ( $wgUser->getOption( 'watchdefault' ) ) {
+ # Watch all edits
+ $this->watchthis = true;
+ } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
+ # Watch creations
+ $this->watchthis = true;
+ } elseif ( $this->mTitle->userIsWatching() ) {
+ # Already watched
+ $this->watchthis = true;
+ }
+ if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew ) {
+ $this->minoredit = true;
+ }
+ if ( $this->textbox1 === false ) {
+ return false;
+ }
+ wfProxyCheck();
+ return true;
}
/**
- * Show all applicable editing introductions
+ * Fetch initial editing page content.
+ *
+ * @param $def_text string
+ * @return mixed string on success, $def_text for invalid sections
+ * @private
*/
- protected function showIntro() {
- global $wgOut, $wgUser;
- if ( $this->suppressIntro ) {
- return;
- }
+ function getContent( $def_text = '' ) {
+ global $wgOut, $wgRequest, $wgParser;
- $namespace = $this->mTitle->getNamespace();
+ wfProfileIn( __METHOD__ );
+ # Get variables from query string :P
+ $section = $wgRequest->getVal( 'section' );
- if ( $namespace == NS_MEDIAWIKI ) {
- # Show a warning if editing an interface message
- $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
- }
+ $preload = $wgRequest->getVal( 'preload',
+ // Custom preload text for new sections
+ $section === 'new' ? 'MediaWiki:addsection-preload' : '' );
+ $undoafter = $wgRequest->getVal( 'undoafter' );
+ $undo = $wgRequest->getVal( 'undo' );
- # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
- # Show log extract when the user is currently blocked
- if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
- $parts = explode( '/', $this->mTitle->getText(), 2 );
- $username = $parts[0];
- $user = User::newFromName( $username, false /* allow IP users*/ );
- $ip = User::isIP( $username );
- if ( !$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
- LogEventsList::showLogExtract(
- $wgOut,
- 'block',
- $user->getUserPage(),
- '',
- array(
- 'lim' => 1,
- 'showIfEmpty' => false,
- 'msgKey' => array(
- 'blocked-notice-logextract',
- $user->getName() # Support GENDER in notice
- )
- )
- );
- }
- }
- # Try to add a custom edit intro, or use the standard one if this is not possible.
- if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
- if ( $wgUser->isLoggedIn() ) {
- $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1\n</div>", 'newarticletext' );
+ // For message page not locally set, use the i18n message.
+ // For other non-existent articles, use preload text if any.
+ if ( !$this->mTitle->exists() ) {
+ if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+ # If this is a system message, get the default text.
+ $text = $this->mTitle->getDefaultMessageText();
+ if( $text === false ) {
+ $text = $this->getPreloadedText( $preload );
+ }
} else {
- $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1\n</div>", 'newarticletextanon' );
+ # If requested, preload some text.
+ $text = $this->getPreloadedText( $preload );
+ }
+ // For existing pages, get text based on "undo" or section parameters.
+ } else {
+ $text = $this->mArticle->getContent();
+ if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
+ # If they got undoafter and undo round the wrong way, switch them
+ list( $undo, $undoafter ) = array( $undoafter, $undo );
+ }
+ if ( $undo > 0 && $undo > $undoafter ) {
+ # Undoing a specific edit overrides section editing; section-editing
+ # doesn't work with undoing.
+ if ( $undoafter ) {
+ $undorev = Revision::newFromId( $undo );
+ $oldrev = Revision::newFromId( $undoafter );
+ } else {
+ $undorev = Revision::newFromId( $undo );
+ $oldrev = $undorev ? $undorev->getPrevious() : null;
+ }
+
+ # Sanity check, make sure it's the right page,
+ # the revisions exist and they were not deleted.
+ # Otherwise, $text will be left as-is.
+ if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
+ $undorev->getPage() == $oldrev->getPage() &&
+ $undorev->getPage() == $this->mArticle->getID() &&
+ !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
+ !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
+
+ $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
+ if ( $undotext === false ) {
+ # Warn the user that something went wrong
+ $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' .
+ wfMsgNoTrans( 'undo-failure' ) . '</div>', true, /* interface */true );
+ } else {
+ $text = $undotext;
+ # Inform the user of our success and set an automatic edit summary
+ $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' .
+ wfMsgNoTrans( 'undo-success' ) . '</div>', true, /* interface */true );
+ $firstrev = $oldrev->getNext();
+ # If we just undid one rev, use an autosummary
+ if ( $firstrev->getId() == $undo ) {
+ $undoSummary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
+ if ( $this->summary === '' ) {
+ $this->summary = $undoSummary;
+ } else {
+ $this->summary = $undoSummary . wfMsgForContent( 'colon-separator' ) . $this->summary;
+ }
+ $this->undidRev = $undo;
+ }
+ $this->formtype = 'diff';
+ }
+ } else {
+ // Failed basic sanity checks.
+ // Older revisions may have been removed since the link
+ // was created, or we may simply have got bogus input.
+ $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' .
+ wfMsgNoTrans( 'undo-norev' ) . '</div>', true, /* interface */true );
+ }
+ } elseif ( $section != '' ) {
+ if ( $section == 'new' ) {
+ $text = $this->getPreloadedText( $preload );
+ } else {
+ // Get section edit text (returns $def_text for invalid sections)
+ $text = $wgParser->getSection( $text, $section, $def_text );
+ }
}
}
- # Give a notice if the user is editing a deleted/moved page...
- if ( !$this->mTitle->exists() ) {
- LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle,
- '', array( 'lim' => 10,
- 'conds' => array( "log_action != 'revision'" ),
- 'showIfEmpty' => false,
- 'msgKey' => array( 'recreate-moveddeleted-warn') )
- );
- }
+
+ wfProfileOut( __METHOD__ );
+ return $text;
}
/**
- * Attempt to show a custom editing introduction, if supplied
+ * Use this method before edit() to preload some text into the edit box
*
- * @return bool
+ * @param $text string
*/
- protected function showCustomIntro() {
- if ( $this->editintro ) {
- $title = Title::newFromText( $this->editintro );
- if ( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
- global $wgOut;
- // Added using template syntax, to take <noinclude>'s into account.
- $wgOut->addWikiTextTitleTidy( '{{:' . $title->getFullText() . '}}', $this->mTitle );
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
+ public function setPreloadedText( $text ) {
+ $this->mPreloadText = $text;
}
/**
- * Attempt submission (no UI)
- *
- * @param $result
- * @param $bot bool
- *
- * @return Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
+ * Get the contents to be preloaded into the box, either set by
+ * an earlier setPreloadText() or by loading the given page.
*
- * FIXME: This interface is TERRIBLE, but hard to get rid of due to various error display idiosyncrasies. There are
- * also lots of cases where error metadata is set in the object and retrieved later instead of being returned, e.g.
- * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
+ * @param $preload String: representing the title to preload from.
+ * @return String
*/
- function internalAttemptSave( &$result, $bot = false ) {
- global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
- global $wgMaxArticleSize;
-
- $status = Status::newGood();
-
- wfProfileIn( __METHOD__ );
- wfProfileIn( __METHOD__ . '-checks' );
+ protected function getPreloadedText( $preload ) {
+ global $wgUser, $wgParser;
- if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
- wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
- $status->fatal( 'hookaborted' );
- $status->value = self::AS_HOOK_ERROR;
- wfProfileOut( __METHOD__ . '-checks' );
- wfProfileOut( __METHOD__ );
- return $status;
+ if ( !empty( $this->mPreloadText ) ) {
+ return $this->mPreloadText;
+ }
+
+ if ( $preload === '' ) {
+ return '';
}
- # Check image redirect
- if ( $this->mTitle->getNamespace() == NS_FILE &&
- Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
- !$wgUser->isAllowed( 'upload' ) ) {
- $code = $wgUser->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED;
- $status->setResult( false, $code );
-
- wfProfileOut( __METHOD__ . '-checks' );
- wfProfileOut( __METHOD__ );
-
- return $status;
+ $title = Title::newFromText( $preload );
+ # Check for existence to avoid getting MediaWiki:Noarticletext
+ if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) {
+ return '';
}
- # Check for spam
- $match = self::matchSummarySpamRegex( $this->summary );
- if ( $match === false ) {
- $match = self::matchSpamRegex( $this->textbox1 );
+ $page = WikiPage::factory( $title );
+ if ( $page->isRedirect() ) {
+ $title = $page->getRedirectTarget();
+ # Same as before
+ if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) {
+ return '';
+ }
+ $page = WikiPage::factory( $title );
}
- if ( $match !== false ) {
- $result['spam'] = $match;
- $ip = $wgRequest->getIP();
- $pdbk = $this->mTitle->getPrefixedDBkey();
+
+ $parserOptions = ParserOptions::newFromUser( $wgUser );
+ return $wgParser->getPreloadText( $page->getRawText(), $title, $parserOptions );
+ }
+
+ /**
+ * Make sure the form isn't faking a user's credentials.
+ *
+ * @param $request WebRequest
+ * @return bool
+ * @private
+ */
+ function tokenOk( &$request ) {
+ global $wgUser;
+ $token = $request->getVal( 'wpEditToken' );
+ $this->mTokenOk = $wgUser->matchEditToken( $token );
+ $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
+ return $this->mTokenOk;
+ }
+
+ /**
+ * Attempt submission
+ * @return bool false if output is done, true if the rest of the form should be displayed
+ */
+ function attemptSave() {
+ global $wgUser, $wgOut;
+
+ $resultDetails = false;
+ # Allow bots to exempt some edits from bot flagging
+ $bot = $wgUser->isAllowed( 'bot' ) && $this->bot;
+ $status = $this->internalAttemptSave( $resultDetails, $bot );
+ // FIXME: once the interface for internalAttemptSave() is made nicer, this should use the message in $status
+
+ if ( $status->value == self::AS_SUCCESS_UPDATE || $status->value == self::AS_SUCCESS_NEW_ARTICLE ) {
+ $this->didSave = true;
+ }
+
+ switch ( $status->value ) {
+ case self::AS_HOOK_ERROR_EXPECTED:
+ case self::AS_CONTENT_TOO_BIG:
+ case self::AS_ARTICLE_WAS_DELETED:
+ case self::AS_CONFLICT_DETECTED:
+ case self::AS_SUMMARY_NEEDED:
+ case self::AS_TEXTBOX_EMPTY:
+ case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
+ case self::AS_END:
+ return true;
+
+ case self::AS_HOOK_ERROR:
+ case self::AS_FILTERING:
+ return false;
+
+ case self::AS_SUCCESS_NEW_ARTICLE:
+ $query = $resultDetails['redirect'] ? 'redirect=no' : '';
+ $wgOut->redirect( $this->mTitle->getFullURL( $query ) );
+ return false;
+
+ case self::AS_SUCCESS_UPDATE:
+ $extraQuery = '';
+ $sectionanchor = $resultDetails['sectionanchor'];
+
+ // Give extensions a chance to modify URL query on update
+ wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this->mArticle, &$sectionanchor, &$extraQuery ) );
+
+ if ( $resultDetails['redirect'] ) {
+ if ( $extraQuery == '' ) {
+ $extraQuery = 'redirect=no';
+ } else {
+ $extraQuery = 'redirect=no&' . $extraQuery;
+ }
+ }
+ $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;
+
+ case self::AS_BLOCKED_PAGE_FOR_USER:
+ throw new UserBlockedError( $wgUser->mBlock );
+
+ case self::AS_IMAGE_REDIRECT_ANON:
+ case self::AS_IMAGE_REDIRECT_LOGGED:
+ throw new PermissionsError( 'upload' );
+
+ case self::AS_READ_ONLY_PAGE_ANON:
+ case self::AS_READ_ONLY_PAGE_LOGGED:
+ throw new PermissionsError( 'edit' );
+
+ case self::AS_READ_ONLY_PAGE:
+ throw new ReadOnlyError;
+
+ case self::AS_RATE_LIMITED:
+ throw new ThrottledError();
+
+ case self::AS_NO_CREATE_PERMISSION:
+ $permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage';
+ throw new PermissionsError( $permission );
+
+ }
+ return false;
+ }
+
+ /**
+ * Attempt submission (no UI)
+ *
+ * @param $result
+ * @param $bot bool
+ *
+ * @return Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
+ *
+ * FIXME: This interface is TERRIBLE, but hard to get rid of due to various error display idiosyncrasies. There are
+ * also lots of cases where error metadata is set in the object and retrieved later instead of being returned, e.g.
+ * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
+ */
+ function internalAttemptSave( &$result, $bot = false ) {
+ global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
+ global $wgMaxArticleSize;
+
+ $status = Status::newGood();
+
+ wfProfileIn( __METHOD__ );
+ wfProfileIn( __METHOD__ . '-checks' );
+
+ if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
+ wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
+ $status->fatal( 'hookaborted' );
+ $status->value = self::AS_HOOK_ERROR;
+ wfProfileOut( __METHOD__ . '-checks' );
+ wfProfileOut( __METHOD__ );
+ return $status;
+ }
+
+ # Check image redirect
+ if ( $this->mTitle->getNamespace() == NS_FILE &&
+ Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
+ !$wgUser->isAllowed( 'upload' ) ) {
+ $code = $wgUser->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED;
+ $status->setResult( false, $code );
+
+ wfProfileOut( __METHOD__ . '-checks' );
+ wfProfileOut( __METHOD__ );
+
+ return $status;
+ }
+
+ # Check for spam
+ $match = self::matchSummarySpamRegex( $this->summary );
+ if ( $match === false ) {
+ $match = self::matchSpamRegex( $this->textbox1 );
+ }
+ if ( $match !== false ) {
+ $result['spam'] = $match;
+ $ip = $wgRequest->getIP();
+ $pdbk = $this->mTitle->getPrefixedDBkey();
$match = str_replace( "\n", '', $match );
wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
$status->fatal( 'spamprotectionmatch', $match );
wfProfileOut( __METHOD__ );
return $status;
}
- if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
+ if ( $wgFilterCallback && is_callable( $wgFilterCallback ) && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
# Error messages or other handling should be performed by the filter function
$status->setResult( false, self::AS_FILTERING );
wfProfileOut( __METHOD__ . '-checks' );
}
if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
+ // Auto-block user's IP if the account was "hard" blocked
+ $wgUser->spreadAnyEditBlock();
# Check block state against master, thus 'false'.
$status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
wfProfileOut( __METHOD__ . '-checks' );
return true;
}
+ /**
+ * @private
+ * @todo document
+ *
+ * @parma $editText string
+ *
+ * @return bool
+ */
+ function mergeChangesInto( &$editText ){
+ wfProfileIn( __METHOD__ );
+
+ $db = wfGetDB( DB_MASTER );
+
+ // This is the revision the editor started from
+ $baseRevision = $this->getBaseRevision();
+ if ( is_null( $baseRevision ) ) {
+ wfProfileOut( __METHOD__ );
+ return false;
+ }
+ $baseText = $baseRevision->getText();
+
+ // The current state, we want to merge updates into it
+ $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
+ if ( is_null( $currentRevision ) ) {
+ wfProfileOut( __METHOD__ );
+ return false;
+ }
+ $currentText = $currentRevision->getText();
+
+ $result = '';
+ if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
+ $editText = $result;
+ wfProfileOut( __METHOD__ );
+ return true;
+ } else {
+ wfProfileOut( __METHOD__ );
+ return false;
+ }
+ }
+
+ /**
+ * @return Revision
+ */
+ function getBaseRevision() {
+ if ( !$this->mBaseRevision ) {
+ $db = wfGetDB( DB_MASTER );
+ $baseRevision = Revision::loadFromTimestamp(
+ $db, $this->mTitle, $this->edittime );
+ return $this->mBaseRevision = $baseRevision;
+ } else {
+ return $this->mBaseRevision;
+ }
+ }
+
/**
* Check given input text against $wgSpamRegex, and return the text of the first match.
*
return false;
}
- /**
- * Initialise form fields in the object
- * Called on the first invocation, e.g. when a user clicks an edit link
- * @return bool -- if the requested section is valid
- */
- function initialiseForm() {
- global $wgUser;
- $this->edittime = $this->mArticle->getTimestamp();
- $this->textbox1 = $this->getContent( false );
- // activate checkboxes if user wants them to be always active
- # Sort out the "watch" checkbox
- if ( $wgUser->getOption( 'watchdefault' ) ) {
- # Watch all edits
- $this->watchthis = true;
- } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
- # Watch creations
- $this->watchthis = true;
- } elseif ( $this->mTitle->userIsWatching() ) {
- # Already watched
- $this->watchthis = true;
- }
- if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew ) {
- $this->minoredit = true;
- }
- if ( $this->textbox1 === false ) {
- return false;
- }
- wfProxyCheck();
- return true;
- }
-
function setHeaders() {
global $wgOut;
$wgOut->setRobotPolicy( 'noindex,nofollow' );
- if ( $this->formtype == 'preview' ) {
- $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
- }
if ( $this->isConflict ) {
- $wgOut->setPageTitle( wfMsg( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
+ $wgOut->setPageTitle( wfMessage( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
} elseif ( $this->section != '' ) {
$msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
- $wgOut->setPageTitle( wfMsg( $msg, $this->getContextTitle()->getPrefixedText() ) );
+ $wgOut->setPageTitle( wfMessage( $msg, $this->getContextTitle()->getPrefixedText() ) );
} else {
# Use the title defined by DISPLAYTITLE magic word when present
if ( isset( $this->mParserOutput )
} else {
$title = $this->getContextTitle()->getPrefixedText();
}
- $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
+ $wgOut->setPageTitle( wfMessage( 'editing', $title ) );
}
}
/**
- * Send the edit form and related headers to $wgOut
- * @param $formCallback Callback that takes an OutputPage parameter; will be called
- * during form output near the top, for captchas and the like.
+ * Show all applicable editing introductions
*/
- function showEditForm( $formCallback = null ) {
- global $wgOut, $wgUser, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
+ protected function showIntro() {
+ global $wgOut, $wgUser;
+ if ( $this->suppressIntro ) {
+ return;
+ }
- wfProfileIn( __METHOD__ );
+ $namespace = $this->mTitle->getNamespace();
- #need to parse the preview early so that we know which templates are used,
- #otherwise users with "show preview after edit box" will get a blank list
- #we parse this near the beginning so that setHeaders can do the title
- #setting work instead of leaving it in getPreviewText
- $previewOutput = '';
- if ( $this->formtype == 'preview' ) {
+ if ( $namespace == NS_MEDIAWIKI ) {
+ # Show a warning if editing an interface message
+ $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
+ }
+
+ # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
+ # Show log extract when the user is currently blocked
+ if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
+ $parts = explode( '/', $this->mTitle->getText(), 2 );
+ $username = $parts[0];
+ $user = User::newFromName( $username, false /* allow IP users*/ );
+ $ip = User::isIP( $username );
+ 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
+ LogEventsList::showLogExtract(
+ $wgOut,
+ 'block',
+ $user->getUserPage(),
+ '',
+ array(
+ 'lim' => 1,
+ 'showIfEmpty' => false,
+ 'msgKey' => array(
+ 'blocked-notice-logextract',
+ $user->getName() # Support GENDER in notice
+ )
+ )
+ );
+ }
+ }
+ # Try to add a custom edit intro, or use the standard one if this is not possible.
+ if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
+ if ( $wgUser->isLoggedIn() ) {
+ $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1\n</div>", 'newarticletext' );
+ } else {
+ $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1\n</div>", 'newarticletextanon' );
+ }
+ }
+ # Give a notice if the user is editing a deleted/moved page...
+ if ( !$this->mTitle->exists() ) {
+ LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle,
+ '', array( 'lim' => 10,
+ 'conds' => array( "log_action != 'revision'" ),
+ 'showIfEmpty' => false,
+ 'msgKey' => array( 'recreate-moveddeleted-warn') )
+ );
+ }
+ }
+
+ /**
+ * Attempt to show a custom editing introduction, if supplied
+ *
+ * @return bool
+ */
+ protected function showCustomIntro() {
+ if ( $this->editintro ) {
+ $title = Title::newFromText( $this->editintro );
+ if ( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
+ global $wgOut;
+ // Added using template syntax, to take <noinclude>'s into account.
+ $wgOut->addWikiTextTitleTidy( '{{:' . $title->getFullText() . '}}', $this->mTitle );
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Send the edit form and related headers to $wgOut
+ * @param $formCallback Callback that takes an OutputPage parameter; will be called
+ * during form output near the top, for captchas and the like.
+ */
+ function showEditForm( $formCallback = null ) {
+ global $wgOut, $wgUser;
+
+ wfProfileIn( __METHOD__ );
+
+ #need to parse the preview early so that we know which templates are used,
+ #otherwise users with "show preview after edit box" will get a blank list
+ #we parse this near the beginning so that setHeaders can do the title
+ #setting work instead of leaving it in getPreviewText
+ $previewOutput = '';
+ if ( $this->formtype == 'preview' ) {
$previewOutput = $this->getPreviewText();
}
$toolbar = '';
}
+
$wgOut->addHTML( $this->editFormPageTop );
if ( $wgUser->getOption( 'previewontop' ) ) {
$templates = $this->getTemplates();
$formattedtemplates = Linker::formatTemplates( $templates, $this->preview, $this->section != '');
- $distantTemplates = $this->getDistantTemplates();
- $formattedDistantTemplates = Linker::formatDistantTemplates( $distantTemplates, $this->preview, $this->section != '' );
-
$hiddencats = $this->mArticle->getHiddenCategories();
$formattedhiddencats = Linker::formatHiddenCategories( $hiddencats );
<div class='templatesUsed'>
{$formattedtemplates}
</div>
-HTML
-);
-
- if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
- $wgOut->addHTML( <<<HTML
-{$this->editFormTextAfterTools}
-<div class='distantTemplatesUsed'>
-{$formattedDistantTemplates}
-</div>
-HTML
-);
- }
-
- $wgOut->addHTML( <<<HTML
-{$this->editFormTextAfterTools}
<div class='hiddencats'>
{$formattedhiddencats}
</div>
if ( $this->isCssJsSubpage ) {
# Check the skin exists
if ( $this->isWrongCaseCssJsPage ) {
- $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->getContextTitle()->getSkinFromCssJsSubpage() ) );
+ $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ) );
}
if ( $this->formtype !== 'preview' ) {
if ( $this->isCssSubpage )
* include the constant suffix to prevent editing from
* broken text-mangling proxies.
*/
- $wgOut->addHTML( "\n" . Html::hidden( "wpEditToken", $wgUser->editToken() ) . "\n" );
+ $wgOut->addHTML( "\n" . Html::hidden( "wpEditToken", $wgUser->getEditToken() ) . "\n" );
}
/**
global $wgOut, $wgUser;
$wikitext = $this->safeUnicodeOutput( $content );
- if ( $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 ext is empty, or Firefox in XHTML
}
}
+ /**
+ * Get a diff between the current contents of the edit box and the
+ * version of the page we're editing from.
+ *
+ * If this is a section edit, we'll replace the section as for final
+ * save and then make a comparison.
+ */
+ function showDiff() {
+ global $wgUser, $wgContLang, $wgParser;
+
+ $oldtext = $this->mArticle->fetchContent();
+ $newtext = $this->mArticle->replaceSection(
+ $this->section, $this->textbox1, $this->summary, $this->edittime );
+
+ wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
+
+ $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+ $newtext = $wgParser->preSaveTransform( $newtext, $this->mTitle, $wgUser, $popts );
+ $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
+ $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
+ if ( $oldtext !== false || $newtext != '' ) {
+ $de = new DifferenceEngine( $this->mArticle->getContext() );
+ $de->setText( $oldtext, $newtext );
+ $difftext = $de->getDiff( $oldtitle, $newtitle );
+ $de->showDiffStyle();
+ } else {
+ $difftext = '';
+ }
+
+ global $wgOut;
+ $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
+ }
+
/**
* Give a chance for site and per-namespace customizations of
* terms of service summary link that might exist separately
if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
$wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
- $de = new DifferenceEngine( $this->mTitle );
+ $de = new DifferenceEngine( $this->mArticle->getContext() );
$de->setText( $this->textbox2, $this->textbox1 );
- $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
+ $de->showDiff( wfMsgExt( 'yourtext', 'parseinline' ), wfMsg( 'storedversion' ) );
$wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
$this->showTextbox2();
}
}
+ /**
+ * @return string
+ */
+ public function getCancelLink() {
+ $cancelParams = array();
+ if ( !$this->isConflict && $this->mArticle->getOldID() > 0 ) {
+ $cancelParams['oldid'] = $this->mArticle->getOldID();
+ }
+
+ return Linker::linkKnown(
+ $this->getContextTitle(),
+ wfMsgExt( 'cancel', array( 'parseinline' ) ),
+ array( 'id' => 'mw-editform-cancel' ),
+ $cancelParams
+ );
+ }
+
+ /**
+ * Returns the URL to use in the form's action attribute.
+ * This is used by EditPage subclasses when simply customizing the action
+ * variable in the constructor is not enough. This can be used when the
+ * EditPage lives inside of a Special page rather than a custom page action.
+ *
+ * @param $title Title object for which is being edited (where we go to for &action= links)
+ * @return string
+ */
+ protected function getActionURL( Title $title ) {
+ return $title->getLocalURL( array( 'action' => $this->action ) );
+ }
+
+ /**
+ * Check if a page was deleted while the user was editing it, before submit.
+ * Note that we rely on the logging table, which hasn't been always there,
+ * but that doesn't matter, because this only applies to brand new
+ * deletes.
+ */
+ protected function wasDeletedSinceLastEdit() {
+ if ( $this->deletedSinceEdit !== null ) {
+ return $this->deletedSinceEdit;
+ }
+
+ $this->deletedSinceEdit = false;
+
+ if ( $this->mTitle->isDeletedQuick() ) {
+ $this->lastDelete = $this->getLastDelete();
+ if ( $this->lastDelete ) {
+ $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
+ if ( $deleteTime > $this->starttime ) {
+ $this->deletedSinceEdit = true;
+ }
+ }
+ }
+
+ return $this->deletedSinceEdit;
+ }
+
protected function getLastDelete() {
$dbr = wfGetDB( DB_SLAVE );
$data = $dbr->selectRow(
* @return string
*/
function getPreviewText() {
- global $wgOut, $wgUser, $wgParser;
+ global $wgOut, $wgUser, $wgParser, $wgRawHtml;
wfProfileIn( __METHOD__ );
+ if ( $wgRawHtml && !$this->mTokenOk ) {
+ // Could be an offsite preview attempt. This is very unsafe if
+ // HTML is enabled, as it could be an attack.
+ $parsedNote = '';
+ if ( $this->textbox1 !== '' ) {
+ // Do not put big scary notice, if previewing the empty
+ // string, which happens when you initially edit
+ // a category page, due to automatic preview-on-open.
+ $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
+ wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
+ }
+ wfProfileOut( __METHOD__ );
+ return $parsedNote;
+ }
+
if ( $this->mTriedSave && !$this->mTokenOk ) {
if ( $this->mTokenOkExceptSuffix ) {
$note = wfMsg( 'token_suffix_mismatch' );
$parserOptions = ParserOptions::newFromUser( $wgUser );
$parserOptions->setEditSection( false );
+ $parserOptions->setTidy( true );
$parserOptions->setIsPreview( true );
$parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
- global $wgRawHtml;
- if ( $wgRawHtml && !$this->mTokenOk ) {
- // Could be an offsite preview attempt. This is very unsafe if
- // HTML is enabled, as it could be an attack.
- $parsedNote = '';
- if ( $this->textbox1 !== '' ) {
- // Do not put big scary notice, if previewing the empty
- // string, which happens when you initially edit
- // a category page, due to automatic preview-on-open.
- $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
- wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
- }
- wfProfileOut( __METHOD__ );
- return $parsedNote;
- }
-
# don't parse non-wikitext pages, show message about preview
# XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
}
}
- $parserOptions->setTidy( true );
$parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
$previewHTML = $parserOutput->mText;
$previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n";
wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
- $parserOptions->setTidy( true );
$parserOptions->enableLimitReport();
- $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
- $this->mTitle, $parserOptions );
+
+ $toparse = $wgParser->preSaveTransform( $toparse, $this->mTitle, $wgUser, $parserOptions );
+ $parserOutput = $wgParser->parse( $toparse, $this->mTitle, $parserOptions );
$previewHTML = $parserOutput->getText();
$this->mParserOutput = $parserOutput;
if ( $this->preview || $this->section != '' ) {
$templates = array();
if ( !isset( $this->mParserOutput ) ) {
- return $templates;
- }
- foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
- foreach( array_keys( $template ) as $dbk ) {
- $templates[] = Title::makeTitle($ns, $dbk);
- }
- }
- return $templates;
- } else {
- return $this->mArticle->getUsedTemplates();
- }
- }
-
- function getDistantTemplates() {
- global $wgEnableInterwikiTemplatesTracking;
- if ( !$wgEnableInterwikiTemplatesTracking ) {
- return array( );
- }
- if ( $this->preview || $this->section != '' ) {
- $templates = array();
- if ( !isset( $this->mParserOutput ) ) return $templates;
- $templatesList = $this->mParserOutput->getDistantTemplates();
- foreach( $templatesList as $prefix => $templatesbyns ) {
- foreach( $templatesbyns as $ns => $template ) {
- foreach( array_keys( $template ) as $dbk ) {
- $templates[] = Title::makeTitle( $ns, $dbk, null, $prefix );
- }
- }
- }
- return $templates;
- } else {
- return $this->mArticle->getUsedDistantTemplates();
- }
- }
-
- /**
- * Call the stock "user is blocked" page
- */
- function blockedPage() {
- global $wgOut;
- $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
-
- # If the user made changes, preserve them when showing the markup
- # (This happens when a user is blocked during edit, for instance)
- $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' );
- if ( $first ) {
- $source = $this->mTitle->exists() ? $this->getContent() : false;
- } else {
- $source = $this->textbox1;
- }
-
- # Spit out the source or the user's modified version
- if ( $source !== false ) {
- $wgOut->addHTML( '<hr />' );
- $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );
- $this->showTextbox1( array( 'readonly' ), $source );
- }
- }
-
- /**
- * Produce the stock "please login to edit pages" page
- */
- function userNotLoggedInPage() {
- global $wgOut;
-
- $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
- $loginLink = Linker::linkKnown(
- $loginTitle,
- wfMsgHtml( 'loginreqlink' ),
- array(),
- array( 'returnto' => $this->getContextTitle()->getPrefixedText() )
- );
-
- $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->setArticleRelated( false );
-
- $wgOut->addHTML( wfMessage( 'whitelistedittext' )->rawParams( $loginLink )->parse() );
- $wgOut->returnToMain( false, $this->getContextTitle() );
- }
-
- /**
- * Creates a basic error page which informs the user that
- * they have attempted to edit a nonexistent section.
- */
- function noSuchSectionPage() {
- global $wgOut;
-
- $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->setArticleRelated( false );
-
- $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section );
- wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
- $wgOut->addHTML( $res );
-
- $wgOut->returnToMain( false, $this->mTitle );
- }
-
- /**
- * Produce the stock "your edit contains spam" page
- *
- * @param $match Text which triggered one or more filters
- * @deprecated since 1.17 Use method spamPageWithContent() instead
- */
- static function spamPage( $match = false ) {
- global $wgOut, $wgTitle;
-
- $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->setArticleRelated( false );
-
- $wgOut->addHTML( '<div id="spamprotected">' );
- $wgOut->addWikiMsg( 'spamprotectiontext' );
- if ( $match ) {
- $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
- }
- $wgOut->addHTML( '</div>' );
-
- $wgOut->returnToMain( false, $wgTitle );
- }
-
- /**
- * Show "your edit contains spam" page with your diff and text
- *
- * @param $match Text which triggered one or more filters
- */
- public function spamPageWithContent( $match = false ) {
- global $wgOut;
- $this->textbox2 = $this->textbox1;
-
- $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->setArticleRelated( false );
-
- $wgOut->addHTML( '<div id="spamprotected">' );
- $wgOut->addWikiMsg( 'spamprotectiontext' );
- if ( $match ) {
- $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
- }
- $wgOut->addHTML( '</div>' );
-
- $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
- $de = new DifferenceEngine( $this->mTitle );
- $de->setText( $this->getContent(), $this->textbox2 );
- $de->showDiff( wfMsg( "storedversion" ), wfMsg( "yourtext" ) );
-
- $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
- $this->showTextbox2();
-
- $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
- }
-
-
- /**
- * @private
- * @todo document
- *
- * @parma $editText string
- *
- * @return bool
- */
- function mergeChangesInto( &$editText ){
- wfProfileIn( __METHOD__ );
-
- $db = wfGetDB( DB_MASTER );
-
- // This is the revision the editor started from
- $baseRevision = $this->getBaseRevision();
- if ( is_null( $baseRevision ) ) {
- wfProfileOut( __METHOD__ );
- return false;
- }
- $baseText = $baseRevision->getText();
-
- // The current state, we want to merge updates into it
- $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
- if ( is_null( $currentRevision ) ) {
- wfProfileOut( __METHOD__ );
- return false;
- }
- $currentText = $currentRevision->getText();
-
- $result = '';
- if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
- $editText = $result;
- wfProfileOut( __METHOD__ );
- return true;
- } else {
- wfProfileOut( __METHOD__ );
- return false;
- }
- }
-
- /**
- * Check if the browser is on a blacklist of user-agents known to
- * mangle UTF-8 data on form submission. Returns true if Unicode
- * should make it through, false if it's known to be a problem.
- * @return bool
- * @private
- */
- function checkUnicodeCompliantBrowser() {
- global $wgBrowserBlackList;
- if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
- // No User-Agent header sent? Trust it by default...
- return true;
- }
- $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
- foreach ( $wgBrowserBlackList as $browser ) {
- if ( preg_match($browser, $currentbrowser) ) {
- return false;
+ return $templates;
+ }
+ foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
+ foreach( array_keys( $template ) as $dbk ) {
+ $templates[] = Title::makeTitle($ns, $dbk);
+ }
}
+ return $templates;
+ } else {
+ return $this->mArticle->getUsedTemplates();
}
- return true;
- }
-
- /**
- * Format an anchor fragment as it would appear for a given section name
- * @param $text String
- * @return String
- * @private
- */
- function sectionAnchor( $text ) {
- global $wgParser;
- return $wgParser->guessSectionNameFromWikiText( $text );
}
/**
'key' => 'R'
)
);
- $toolbar = "<div id='toolbar'>\n";
$script = '';
foreach ( $toolarray as $tool ) {
$cssId = $tool['id'],
);
- $paramList = implode( ',',
- array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
- $script .= "mw.toolbar.addButton($paramList);\n";
+ $script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params );
}
- $wgOut->addScript( Html::inlineScript(
- "if ( window.mediaWiki ) {{$script}}"
- ) );
+ $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
- $toolbar .= "\n</div>";
+ $toolbar = '<div id="toolbar"></div>';
wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
}
/**
- * @return string
+ * Call the stock "user is blocked" page
+ *
+ * @deprecated in 1.19; throw an exception directly instead
*/
- public function getCancelLink() {
- $cancelParams = array();
- if ( !$this->isConflict && $this->mArticle->getOldID() > 0 ) {
- $cancelParams['oldid'] = $this->mArticle->getOldID();
- }
+ function blockedPage() {
+ global $wgUser;
- return Linker::linkKnown(
- $this->getContextTitle(),
- wfMsgExt( 'cancel', array( 'parseinline' ) ),
- array( 'id' => 'mw-editform-cancel' ),
- $cancelParams
- );
+ throw new UserBlockedError( $wgUser->mBlock );
}
/**
- * Get a diff between the current contents of the edit box and the
- * version of the page we're editing from.
+ * Produce the stock "please login to edit pages" page
*
- * If this is a section edit, we'll replace the section as for final
- * save and then make a comparison.
+ * @deprecated in 1.19; throw an exception directly instead
*/
- function showDiff() {
- $oldtext = $this->mArticle->fetchContent();
- $newtext = $this->mArticle->replaceSection(
- $this->section, $this->textbox1, $this->summary, $this->edittime );
+ function userNotLoggedInPage() {
+ throw new PermissionsError( 'edit' );
+ }
- wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
+ /**
+ * Show an error page saying to the user that he has insufficient permissions
+ * to create a new page
+ *
+ * @deprecated in 1.19; throw an exception directly instead
+ */
+ function noCreatePermission() {
+ $permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage';
+ throw new PermissionsError( $permission );
+ }
- $newtext = $this->mArticle->preSaveTransform( $newtext );
- $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
- $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
- if ( $oldtext !== false || $newtext != '' ) {
- $de = new DifferenceEngine( $this->mTitle );
- $de->setText( $oldtext, $newtext );
- $difftext = $de->getDiff( $oldtitle, $newtitle );
- $de->showDiffStyle();
- } else {
- $difftext = '';
+ /**
+ * Creates a basic error page which informs the user that
+ * they have attempted to edit a nonexistent section.
+ */
+ function noSuchSectionPage() {
+ global $wgOut;
+
+ $wgOut->prepareErrorPage( wfMessage( 'nosuchsectiontitle' ) );
+
+ $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section );
+ wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
+ $wgOut->addHTML( $res );
+
+ $wgOut->returnToMain( false, $this->mTitle );
+ }
+
+ /**
+ * Produce the stock "your edit contains spam" page
+ *
+ * @param $match Text which triggered one or more filters
+ * @deprecated since 1.17 Use method spamPageWithContent() instead
+ */
+ static function spamPage( $match = false ) {
+ global $wgOut, $wgTitle;
+
+ $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );
+
+ $wgOut->addHTML( '<div id="spamprotected">' );
+ $wgOut->addWikiMsg( 'spamprotectiontext' );
+ if ( $match ) {
+ $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
}
+ $wgOut->addHTML( '</div>' );
+ $wgOut->returnToMain( false, $wgTitle );
+ }
+
+ /**
+ * Show "your edit contains spam" page with your diff and text
+ *
+ * @param $match Text which triggered one or more filters
+ */
+ public function spamPageWithContent( $match = false ) {
global $wgOut;
- $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
+ $this->textbox2 = $this->textbox1;
+
+ $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );
+
+ $wgOut->addHTML( '<div id="spamprotected">' );
+ $wgOut->addWikiMsg( 'spamprotectiontext' );
+ if ( $match ) {
+ $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
+ }
+ $wgOut->addHTML( '</div>' );
+
+ $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
+ $de = new DifferenceEngine( $this->mArticle->getContext() );
+ $de->setText( $this->getContent(), $this->textbox2 );
+ $de->showDiff( wfMsg( "storedversion" ), wfMsgExt( 'yourtext', 'parseinline' ) );
+
+ $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
+ $this->showTextbox2();
+
+ $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
+ }
+
+ /**
+ * Format an anchor fragment as it would appear for a given section name
+ * @param $text String
+ * @return String
+ * @private
+ */
+ function sectionAnchor( $text ) {
+ global $wgParser;
+ return $wgParser->guessSectionNameFromWikiText( $text );
+ }
+
+ /**
+ * Check if the browser is on a blacklist of user-agents known to
+ * mangle UTF-8 data on form submission. Returns true if Unicode
+ * should make it through, false if it's known to be a problem.
+ * @return bool
+ * @private
+ */
+ function checkUnicodeCompliantBrowser() {
+ global $wgBrowserBlackList;
+ if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
+ // No User-Agent header sent? Trust it by default...
+ return true;
+ }
+ $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
+ foreach ( $wgBrowserBlackList as $browser ) {
+ if ( preg_match($browser, $currentbrowser) ) {
+ return false;
+ }
+ }
+ return true;
}
/**
// reverse the transform that we made for reversability reasons.
return strtr( $result, array( "�" => "&#x" ) );
}
-
- function noCreatePermission() {
- global $wgOut;
- $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
- $wgOut->addWikiMsg( 'nocreatetext' );
- }
-
- /**
- * Attempt submission
- * @return bool false if output is done, true if the rest of the form should be displayed
- */
- function attemptSave() {
- global $wgUser, $wgOut;
-
- $resultDetails = false;
- # Allow bots to exempt some edits from bot flagging
- $bot = $wgUser->isAllowed( 'bot' ) && $this->bot;
- $status = $this->internalAttemptSave( $resultDetails, $bot );
- // FIXME: once the interface for internalAttemptSave() is made nicer, this should use the message in $status
-
- if ( $status->value == self::AS_SUCCESS_UPDATE || $status->value == self::AS_SUCCESS_NEW_ARTICLE ) {
- $this->didSave = true;
- }
-
- switch ( $status->value ) {
- case self::AS_HOOK_ERROR_EXPECTED:
- case self::AS_CONTENT_TOO_BIG:
- case self::AS_ARTICLE_WAS_DELETED:
- case self::AS_CONFLICT_DETECTED:
- case self::AS_SUMMARY_NEEDED:
- case self::AS_TEXTBOX_EMPTY:
- case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
- case self::AS_END:
- return true;
-
- case self::AS_HOOK_ERROR:
- case self::AS_FILTERING:
- return false;
-
- case self::AS_SUCCESS_NEW_ARTICLE:
- $query = $resultDetails['redirect'] ? 'redirect=no' : '';
- $wgOut->redirect( $this->mTitle->getFullURL( $query ) );
- return false;
-
- case self::AS_SUCCESS_UPDATE:
- $extraQuery = '';
- $sectionanchor = $resultDetails['sectionanchor'];
-
- // Give extensions a chance to modify URL query on update
- wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this->mArticle, &$sectionanchor, &$extraQuery ) );
-
- if ( $resultDetails['redirect'] ) {
- if ( $extraQuery == '' ) {
- $extraQuery = 'redirect=no';
- } else {
- $extraQuery = 'redirect=no&' . $extraQuery;
- }
- }
- $wgOut->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
- return false;
-
- case self::AS_SPAM_ERROR:
- $this->spamPageWithContent( $resultDetails['spam'] );
- return false;
-
- case self::AS_BLOCKED_PAGE_FOR_USER:
- $this->blockedPage();
- return false;
-
- case self::AS_IMAGE_REDIRECT_ANON:
- $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
- return false;
-
- case self::AS_READ_ONLY_PAGE_ANON:
- $this->userNotLoggedInPage();
- return false;
-
- case self::AS_READ_ONLY_PAGE_LOGGED:
- case self::AS_READ_ONLY_PAGE:
- $wgOut->readOnlyPage();
- return false;
-
- case self::AS_RATE_LIMITED:
- $wgOut->rateLimited();
- return false;
-
- case self::AS_NO_CREATE_PERMISSION:
- $this->noCreatePermission();
- return false;
-
- case self::AS_BLANK_ARTICLE:
- $wgOut->redirect( $this->getContextTitle()->getFullURL() );
- return false;
-
- case self::AS_IMAGE_REDIRECT_LOGGED:
- $wgOut->permissionRequired( 'upload' );
- return false;
- }
- }
-
- /**
- * @return Revision
- */
- function getBaseRevision() {
- if ( !$this->mBaseRevision ) {
- $db = wfGetDB( DB_MASTER );
- $baseRevision = Revision::loadFromTimestamp(
- $db, $this->mTitle, $this->edittime );
- return $this->mBaseRevision = $baseRevision;
- } else {
- return $this->mBaseRevision;
- }
- }
}