# Placeholders for text injection by hooks (must be HTML)
# extensions should take care to _append_ to the present value
- var $editFormTextTop;
- var $editFormTextAfterWarn;
- var $editFormTextAfterTools;
- var $editFormTextBottom;
+ public $editFormPageTop; // Before even the preview
+ public $editFormTextTop;
+ public $editFormTextAfterWarn;
+ public $editFormTextAfterTools;
+ public $editFormTextBottom;
/**
* @todo document
$this->mTitle =& $wgTitle;
# Placeholders for text injection by hooks (empty per default)
- $this->editFormTextTop = "";
- $this->editFormTextAfterWarn = "";
- $this->editFormTextAfterTools = "";
+ $this->editFormPageTop =
+ $this->editFormTextTop =
+ $this->editFormTextAfterWarn =
+ $this->editFormTextAfterTools =
$this->editFormTextBottom = "";
}
* Fetch initial editing page content.
*/
private function getContent() {
- global $wgRequest, $wgParser;
+ global $wgOut, $wgRequest, $wgParser;
# Get variables from query string :P
$section = $wgRequest->getVal( 'section' );
$text = '';
if( !$this->mTitle->exists() ) {
-
- # If requested, preload some text.
- $text = $this->getPreloadedText( $preload );
-
+ if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+ # If this is a system message, get the default text.
+ $text = wfMsgWeirdKey ( $this->mTitle->getText() ) ;
+ } else {
+ # If requested, preload some text.
+ $text = $this->getPreloadedText( $preload );
+ }
# We used to put MediaWiki:Newarticletext here if
# $text was empty at this point.
# This is now shown above the edit box instead.
// fetch the page record from the high-priority server,
// which is needed to guarantee we don't pick up lagged
// information.
-
+
$text = $this->mArticle->getContent();
if ( $undo > 0 ) {
#Undoing a specific edit overrides section editing; section-editing
# doesn't work with undoing.
$undorev = Revision::newFromId($undo);
- $oldrev = $undorev->getPrevious();
#Sanity check, make sure it's the right page.
# Otherwise, $text will be left as-is.
- if ($undorev->getPage() == $this->mArticle->getID()) {
+ if (!is_null($undorev) && $undorev->getPage() == $this->mArticle->getID()) {
+ $oldrev = $undorev->getPrevious();
$undorev_text = $undorev->getText();
$oldrev_text = $oldrev->getText();
$currev_text = $text;
-
- $result = wfMerge($undorev_text, $oldrev_text, $currev_text, &$text);
-
- if (!$result) {
- #Undoing failed. Bailing out with regular revision text.
- $text = $currev_text;
+
+ #No use doing a merge if it's just a straight revert.
+ if ($currev_text != $undorev_text) {
+ $result = wfMerge($undorev_text, $oldrev_text, $currev_text, $text);
+ } else {
+ $text = $oldrev_text;
+ $result = true;
+ }
+
+ if( $result ) {
+ # Inform the user of our success and set an automatic edit summary
+ $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
+ $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
+ $this->formtype = 'diff';
+ } else {
+ # Warn the user that something went wrong
+ $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
}
+
}
}
else if( $section != '' ) {
}
}
}
-
+
wfProfileOut( __METHOD__ );
return $text;
}
// Remember whether a save was requested, so we can indicate
// if we forced preview due to session failure.
$this->mTriedSave = !$this->preview;
-
+
if ( $this->tokenOk( $request ) ) {
# Some browsers will not report any submit button
# if the user hits enter in the comment box.
} else {
$this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' );
}
-
- $this->autoSumm = $request->getText( 'wpAutoSummary' );
+
+ $this->autoSumm = $request->getText( 'wpAutoSummary' );
} else {
# Not a posted form? Start with nothing.
wfDebug( "$fname: Not a posted form.\n" );
global $wgUser;
if( $wgUser->isAnon() ) {
# Anonymous users may not have a session
- # open. Don't tokenize.
- $this->mTokenOk = true;
+ # open. Check for suffix anyway.
+ $this->mTokenOk = ( EDIT_TOKEN_SUFFIX == $request->getVal( 'wpEditToken' ) );
} else {
$this->mTokenOk = $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
}
wfProfileIn( $fname );
wfProfileIn( "$fname-checks" );
+ if( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
+ {
+ wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
+ return false;
+ }
+
# Reintegrate metadata
if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
$this->mMetaData = '' ;
wfProfileOut( $fname );
return true;
}
-
+
if ( !$wgUser->isAllowed('edit') ) {
if ( $wgUser->isAnon() ) {
$this->userNotLoggedInPage();
# If article is new, insert it.
$aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
if ( 0 == $aid ) {
+
// Late check for create permission, just in case *PARANOIA*
if ( !$this->mTitle->userCanCreate() ) {
wfDebug( "$fname: no create permission\n" );
*/
function initialiseForm() {
$this->edittime = $this->mArticle->getTimestamp();
- $this->textbox1 = $this->getContent();
$this->summary = '';
+ $this->textbox1 = $this->getContent();
if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI )
- $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() ) ;
+ $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() );
wfProxyCheck();
}
if ( $this->missingComment ) {
$wgOut->addWikiText( wfMsg( 'missingcommenttext' ) );
}
-
+
if( $this->missingSummary && $this->section != 'new' ) {
$wgOut->addWikiText( wfMsg( 'missingsummary' ) );
}
if( $this->missingSummary && $this->section == 'new' ) {
$wgOut->addWikiText( wfMsg( 'missingcommentheader' ) );
}
-
+
if( !$this->hookError == '' ) {
$wgOut->addWikiText( $this->hookError );
}
}
}
}
-
+
if( $this->mTitle->isProtected( 'edit' ) ) {
+
+ $cascadeSources = $this->mTitle->getCascadeProtectionSources( );
+
# Is the protection due to the namespace, e.g. interface text?
if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
# Yes; remind the user
if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) || $notice == '-' ) {
$notice = '';
}
+ } elseif ($cascadeSources && count($cascadeSources) > 0) {
+ # Cascaded protection: warn the user.
+ $titles = '';
+
+ foreach ( $cascadeSources as $title ) {
+ $titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
+ }
+
+ $notice = wfMsg( 'cascadeprotectedwarning' ) . "\r\n$titles";
} else {
# No; regular protection
$notice = wfMsg( 'protectedpagewarning' );
#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
- $previewOutput = $this->getPreviewText();
+ if ( $this->formtype == 'preview' ) {
+ $previewOutput = $this->getPreviewText();
+ }
$rows = $wgUser->getIntOption( 'rows' );
$cols = $wgUser->getIntOption( 'cols' );
# Already watched
$this->watchthis = true;
}
-
+
if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
}
$minoredithtml =
"<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?" checked='checked'":"").
" accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />\n".
- "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>\n";
+ "<label for='wpMinoredit'".$sk->tooltipAndAccesskey('minoredit').">{$minor}</label>\n";
}
$watchhtml = '';
$watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
($this->watchthis?" checked='checked'":"").
" accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />\n".
- "<label for='wpWatchthis' title=\"" .
- htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>\n";
+ "<label for='wpWatchthis'".$sk->tooltipAndAccesskey('watch').">{$watchthis}</label>\n";
}
$checkboxhtml = $minoredithtml . $watchhtml;
+ $wgOut->addHTML( $this->editFormPageTop );
+
if ( $wgUser->getOption( 'previewontop' ) ) {
if ( 'preview' == $this->formtype ) {
'tabindex' => '5',
'value' => wfMsg('savearticle'),
'accesskey' => wfMsg('accesskey-save'),
- 'title' => wfMsg('tooltip-save'),
+ 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
);
$buttons['save'] = wfElement('input', $temp, '');
$temp = array(
'tabindex' => '7',
'value' => wfMsg('showdiff'),
'accesskey' => wfMsg('accesskey-diff'),
- 'title' => wfMsg('tooltip-diff'),
+ 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
);
$buttons['diff'] = wfElement('input', $temp, '');
'tabindex' => '6',
'value' => wfMsg('showpreview'),
'accesskey' => '',
- 'title' => wfMsg('tooltip-preview'),
+ 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
'style' => 'display: none;',
);
$buttons['preview'] = wfElement('input', $temp, '');
'tabindex' => '6',
'value' => wfMsg('showpreview'),
'accesskey' => wfMsg('accesskey-preview'),
- 'title' => wfMsg('tooltip-preview'),
+ 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
);
$buttons['preview'] = wfElement('input', $temp, '');
$buttons['live'] = '';
</div><!-- editButtons -->
</div><!-- editOptions -->");
+ $wgOut->addHtml( '<div class="mw-editTools">' );
$wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
+ $wgOut->addHtml( '</div>' );
+
$wgOut->addHTML( $this->editFormTextAfterTools );
$wgOut->addHTML( "
</div>
" );
- if ( $wgUser->isLoggedIn() ) {
- /**
- * To make it harder for someone to slip a user a page
- * which submits an edit form to the wiki without their
- * knowledge, a random token is associated with the login
- * session. If it's not passed back with the submission,
- * we won't save the page, or render user JavaScript and
- * CSS previews.
- */
+ /**
+ * To make it harder for someone to slip a user a page
+ * which submits an edit form to the wiki without their
+ * knowledge, a random token is associated with the login
+ * session. If it's not passed back with the submission,
+ * we won't save the page, or render user JavaScript and
+ * CSS previews.
+ *
+ * For anon editors, who may not have a session, we just
+ * include the constant suffix to prevent editing from
+ * broken text-mangling proxies.
+ */
+ if ( $wgUser->isLoggedIn() )
$token = htmlspecialchars( $wgUser->editToken() );
- $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
- }
+ else
+ $token = EDIT_TOKEN_SUFFIX;
+ $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
+
# If a blank edit summary was previously provided, and the appropriate
# user preference is active, pass a hidden tag here. This will stop the
if( $this->missingSummary ) {
$wgOut->addHTML( "<input type=\"hidden\" name=\"wpIgnoreBlankSummary\" value=\"1\" />\n" );
}
-
+
# For a bit more sophisticated detection of blank summaries, hash the
# automatic one and pass that in a hidden field.
$autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
} else {
$wgOut->addHTML( '<div id="wikiPreview"></div>' );
}
-
+
if ( $this->formtype == 'diff') {
$wgOut->addHTML( $this->getDiff() );
}
# don't parse user css/js, show message about preview
# XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
-
+
if ( $this->isCssJsSubpage ) {
if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
$previewtext = wfMsg('usercsspreview');
function blockedPage() {
global $wgOut, $wgUser;
$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)
+ # (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 ) {
$rows = $wgUser->getOption( 'rows' );
function userNotLoggedInPage() {
global $wgUser, $wgOut;
$skin = $wgUser->getSkin();
-
+
$loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
$loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $this->mTitle->getPrefixedUrl() );
-
+
$wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
-
+
$wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
$wgOut->returnToMain( false, $this->mTitle->getPrefixedUrl() );
}
$wgOut->setPageTitle( wfMsg( 'confirmedittitle' ) );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
-
+
$wgOut->addWikiText( wfMsg( 'confirmedittext' ) );
$wgOut->returnToMain( false );
}
$wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
if ( $match )
$wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
-
+
$wgOut->returnToMain( false );
}
*/
$toolarray=array(
array( 'image'=>'button_bold.png',
- 'open' => "\'\'\'",
- 'close' => "\'\'\'",
+ 'open' => '\\\'\\\'\\\'',
+ 'close' => '\\\'\\\'\\\'',
'sample'=> wfMsg('bold_sample'),
'tip' => wfMsg('bold_tip'),
'key' => 'B'
),
array( 'image'=>'button_italic.png',
- 'open' => "\'\'",
- 'close' => "\'\'",
+ 'open' => '\\\'\\\'',
+ 'close' => '\\\'\\\'',
'sample'=> wfMsg('italic_sample'),
'tip' => wfMsg('italic_tip'),
'key' => 'I'