Cleaning up some old PHP 4 object-reference usage in some edit filtering hooks.
[lhc/web/wiklou.git] / includes / EditPage.php
index 2300ffd..456152f 100644 (file)
  * usually the same, but they are now allowed to be different.
  */
 class EditPage {
-       const AS_SUCCESS_UPDATE             = 200;
-       const AS_SUCCESS_NEW_ARTICLE        = 201;
-       const AS_HOOK_ERROR                 = 210;
-       const AS_FILTERING                  = 211;
-       const AS_HOOK_ERROR_EXPECTED        = 212;
-       const AS_BLOCKED_PAGE_FOR_USER      = 215;
-       const AS_CONTENT_TOO_BIG            = 216;
-       const AS_USER_CANNOT_EDIT           = 217;
-       const AS_READ_ONLY_PAGE_ANON        = 218;
-       const AS_READ_ONLY_PAGE_LOGGED      = 219;
-       const AS_READ_ONLY_PAGE             = 220;
-       const AS_RATE_LIMITED               = 221;
-       const AS_ARTICLE_WAS_DELETED        = 222;
-       const AS_NO_CREATE_PERMISSION       = 223;
-       const AS_BLANK_ARTICLE              = 224;
-       const AS_CONFLICT_DETECTED          = 225;
-       const AS_SUMMARY_NEEDED             = 226;
-       const AS_TEXTBOX_EMPTY              = 228;
-       const AS_MAX_ARTICLE_SIZE_EXCEEDED  = 229;
-       const AS_OK                         = 230;
-       const AS_END                        = 231;
-       const AS_SPAM_ERROR                 = 232;
-       const AS_IMAGE_REDIRECT_ANON        = 233;
-       const AS_IMAGE_REDIRECT_LOGGED      = 234;
+       const AS_SUCCESS_UPDATE                 = 200;
+       const AS_SUCCESS_NEW_ARTICLE            = 201;
+       const AS_HOOK_ERROR                     = 210;
+       const AS_FILTERING                      = 211;
+       const AS_HOOK_ERROR_EXPECTED            = 212;
+       const AS_BLOCKED_PAGE_FOR_USER          = 215;
+       const AS_CONTENT_TOO_BIG                = 216;
+       const AS_USER_CANNOT_EDIT               = 217;
+       const AS_READ_ONLY_PAGE_ANON            = 218;
+       const AS_READ_ONLY_PAGE_LOGGED          = 219;
+       const AS_READ_ONLY_PAGE                 = 220;
+       const AS_RATE_LIMITED                   = 221;
+       const AS_ARTICLE_WAS_DELETED            = 222;
+       const AS_NO_CREATE_PERMISSION           = 223;
+       const AS_BLANK_ARTICLE                  = 224;
+       const AS_CONFLICT_DETECTED              = 225;
+       const AS_SUMMARY_NEEDED                 = 226;
+       const AS_TEXTBOX_EMPTY                  = 228;
+       const AS_MAX_ARTICLE_SIZE_EXCEEDED      = 229;
+       const AS_OK                             = 230;
+       const AS_END                            = 231;
+       const AS_SPAM_ERROR                     = 232;
+       const AS_IMAGE_REDIRECT_ANON            = 233;
+       const AS_IMAGE_REDIRECT_LOGGED          = 234;
 
        var $mArticle;
        var $mTitle;
@@ -48,6 +48,8 @@ class EditPage {
        var $mMetaData = '';
        var $isConflict = false;
        var $isCssJsSubpage = false;
+       var $isCssSubpage = false;
+       var $isJsSubpage = false;
        var $deletedSinceEdit = false;
        var $formtype;
        var $firsttime;
@@ -84,6 +86,7 @@ class EditPage {
 
        /* $didSave should be set to true whenever an article was succesfully altered. */
        public $didSave = false;
+       public $undidRev = 0;
 
        public $suppressIntro = false;
 
@@ -102,13 +105,15 @@ class EditPage {
                $this->editFormTextBeforeContent =
                $this->editFormTextAfterWarn =
                $this->editFormTextAfterTools =
-               $this->editFormTextBottom = "";
+               $this->editFormTextBottom =
+               $this->mPreloadText = "";
        }
        
        function getArticle() {
                return $this->mArticle;
        }
 
+
        /**
         * Fetch initial editing page content.
         * @private
@@ -164,35 +169,28 @@ class EditPage {
                                        $undorev->getPage() == $this->mArticle->getID() &&
                                        !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
                                        !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
-                                       $undorev_text = $undorev->getText();
-                                       $oldrev_text = $oldrev->getText();
-                                       $currev_text = $text;
-
-                                       if ( $currev_text != $undorev_text ) {
-                                               $result = wfMerge( $undorev_text, $oldrev_text, $currev_text, $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>' );
                                        } else {
-                                               # No use doing a merge if it's just a straight revert.
-                                               $text = $oldrev_text;
-                                               $result = true;
-                                       }
-                                       if ( $result ) {
+                                               $text = $undotext;
                                                # Inform the user of our success and set an automatic edit summary
-                                               $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
+                                               $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
                                                $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->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
+                                                       $this->undidRev = $undo;
                                                }
                                                $this->formtype = 'diff';
-                                       } else {
-                                               # Warn the user that something went wrong
-                                               $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
                                        }
                                } 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( wfMsgNoTrans( 'undo-norev' ) );
+                                       $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
                                }
                        } else if ( $section != '' ) {
                                if ( $section == 'new' ) {
@@ -206,6 +204,11 @@ class EditPage {
                wfProfileOut( __METHOD__ );
                return $text;
        }
+       
+       /** Use this method before edit() to preload some text into the edit box */
+       public function setPreloadedText( $text ) {
+               $this->mPreloadText = $text;
+       }
 
        /**
         * Get the contents of a page from its title and remove includeonly tags
@@ -214,7 +217,9 @@ class EditPage {
         * @return string The contents of the page.
         */
        protected function getPreloadedText( $preload ) {
-               if ( $preload === '' ) {
+               if ( !empty($this->mPreloadText) ) {
+                       return $this->mPreloadText;
+               } elseif ( $preload === '' ) {
                        return '';
                } else {
                        $preloadTitle = Title::newFromText( $preload );
@@ -237,7 +242,7 @@ class EditPage {
         * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
         *  and set $wgMetadataWhitelist to the *full* title of the template whitelist
         */
-       function extractMetaDataFromArticle() {
+       function extractMetaDataFromArticle () {
                global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
                $this->mMetaData = '';
                if ( !$wgUseMetadataEdit ) return;
@@ -330,7 +335,7 @@ class EditPage {
        protected function wasDeletedSinceLastEdit() {
                if ( $this->deletedSinceEdit )
                        return true;
-               if ( $this->mTitle->isDeleted() ) {
+               if ( $this->mTitle->isDeletedQuick() ) {
                        $this->lastDelete = $this->getLastDelete();
                        if ( $this->lastDelete ) {
                                $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
@@ -358,9 +363,9 @@ class EditPage {
         * the newly-edited page.
         */
        function edit() {
-               global $wgOut, $wgUser, $wgRequest;
+               global $wgOut, $wgRequest, $wgEnableJS2system;
                // Allow extensions to modify/prevent this form or submission
-               if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) ) {
+               if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
                        return;
                }
 
@@ -386,6 +391,10 @@ class EditPage {
                }
 
                $wgOut->addScriptFile( 'edit.js' );
+
+               if($wgEnableJS2system)
+                   $wgOut->addScriptClass( 'editPage' );
+
                $permErrors = $this->getEditPermissionErrors();
                if ( $permErrors ) {
                        wfDebug( __METHOD__.": User can't edit\n" );
@@ -409,12 +418,19 @@ class EditPage {
                                }
                        }
                }
+               
+               // 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() );
+               }
 
                wfProfileIn( __METHOD__."-business-end" );
 
                $this->isConflict = false;
                // css / js subpages of user pages get a special treatment
                $this->isCssJsSubpage      = $this->mTitle->isCssJsSubpage();
+               $this->isCssSubpage        = $this->mTitle->isCssSubpage();
+               $this->isJsSubpage         = $this->mTitle->isJsSubpage();
                $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage();
 
                # Show applicable editing introductions
@@ -427,7 +443,6 @@ class EditPage {
 
                # Optional notices on a per-namespace and per-page basis
                $editnotice_ns   = 'editnotice-'.$this->mTitle->getNamespace();
-               $editnotice_page = $editnotice_ns.'-'.$this->mTitle->getDBkey();
                if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
                        $wgOut->addWikiText( wfMsgForContent( $editnotice_ns )  );
                }
@@ -440,8 +455,6 @@ class EditPage {
                                        $wgOut->addWikiText( wfMsgForContent( $editnotice_base )  );
                                }
                        }
-               } else if ( !wfEmptyMsg( $editnotice_page, wfMsgForContent( $editnotice_page ) ) ) {
-                       $wgOut->addWikiText( wfMsgForContent( $editnotice_page ) );
                }
 
                # Attempt submission here.  This will check for edit conflicts,
@@ -529,7 +542,7 @@ class EditPage {
                } elseif ( $this->section == 'new' ) {
                        // Nothing *to* preview for new sections
                        return false;
-               } elseif ( ( $wgRequest->getVal( 'preload' ) !== '' || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
+               } elseif ( ( $wgRequest->getVal( 'preload' ) !== null || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
                        // Standard preference behaviour
                        return true;
                } elseif ( !$this->mTitle->exists() && $this->mTitle->getNamespace() == NS_CATEGORY ) {
@@ -546,8 +559,8 @@ class EditPage {
         */
        function importFormData( &$request ) {
                global $wgLang, $wgUser;
-
-               wfProfileIn( __METHOD__ );
+               $fname = 'EditPage::importFormData';
+               wfProfileIn( $fname );
 
                # Section edit can come from either the form or a link
                $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
@@ -560,7 +573,7 @@ class EditPage {
                        $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
                        $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
                        # Truncate for whole multibyte characters. +5 bytes for ellipsis
-                       $this->summary = $wgLang->truncate( $request->getText( 'wpSummary'  ), 250 );
+                       $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
 
                        # Remove extra headings from summaries and new sections.
                        $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary);
@@ -572,9 +585,9 @@ class EditPage {
 
                        if ( is_null( $this->edittime ) ) {
                                # If the form is incomplete, force to preview.
-                               wfDebug( __METHOD__ . ": Form data appears to be incomplete\n" );
+                               wfDebug( "$fname: Form data appears to be incomplete\n" );
                                wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
-                               $this->preview  = true;
+                               $this->preview = true;
                        } else {
                                /* Fallback for live preview */
                                $this->preview = $request->getCheck( 'wpPreview' ) || $request->getCheck( 'wpLivePreview' );
@@ -589,14 +602,14 @@ class EditPage {
                                        # if the user hits enter in the comment box.
                                        # The unmarked state will be assumed to be a save,
                                        # if the form seems otherwise complete.
-                                       wfDebug( __METHOD__ . ": Passed token check.\n" );
+                                       wfDebug( "$fname: Passed token check.\n" );
                                } else if ( $this->diff ) {
                                        # Failed token check, but only requested "Show Changes".
-                                       wfDebug( __METHOD__ . ": Failed token check; Show Changes requested.\n" );
+                                       wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
                                } else {
                                        # Page might be a hack attempt posted from
                                        # an external site. Preview instead of saving.
-                                       wfDebug( __METHOD__ . ": Failed token check; forcing preview\n" );
+                                       wfDebug( "$fname: Failed token check; forcing preview\n" );
                                        $this->preview = true;
                                }
                        }
@@ -626,7 +639,7 @@ class EditPage {
                        $this->autoSumm = $request->getText( 'wpAutoSummary' );
                } else {
                        # Not a posted form? Start with nothing.
-                       wfDebug( __METHOD__ . ": Not a posted form.\n" );
+                       wfDebug( "$fname: Not a posted form.\n" );
                        $this->textbox1  = '';
                        $this->textbox2  = '';
                        $this->mMetaData = '';
@@ -644,14 +657,25 @@ class EditPage {
                        if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
                                $this->summary = $request->getVal( 'preloadtitle' );
                        }
+                       elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) {
+                               $this->summary = $request->getText( 'summary' );
+                       }
+                       
+                       if ( $request->getVal( 'minor' ) ) {
+                               $this->minoredit = true;
+                       }
                }
 
+               // FIXME: unused variable?
                $this->oldid = $request->getInt( 'oldid' );
 
                $this->live = $request->getCheck( 'live' );
                $this->editintro = $request->getText( 'editintro' );
 
-               wfProfileOut( __METHOD__ );
+               wfProfileOut( $fname );
+
+               // Allow extensions to modify form data
+               wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
        }
 
        /**
@@ -677,8 +701,16 @@ class EditPage {
                if ( $this->suppressIntro ) {
                        return;
                }
+
+               $namespace = $this->mTitle->getNamespace();
+
+               if ( $namespace == NS_MEDIAWIKI ) {
+                       # Show a warning if editing an interface message
+                       $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
+               }
+
                # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
-               if ( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
+               if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
                        $parts = explode( '/', $this->mTitle->getText(), 2 );
                        $username = $parts[0];
                        $id = User::idFromName( $username );
@@ -696,9 +728,9 @@ class EditPage {
                                $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
                        }
                }
-               # Give a notice if the user is editing a deleted page...
+               # Give a notice if the user is editing a deleted/moved page...
                if ( !$this->mTitle->exists() ) {
-                       $this->showDeletionLog( $wgOut );
+                       $this->showLogs( $wgOut );
                }
        }
 
@@ -731,12 +763,13 @@ class EditPage {
                global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
                global $wgMaxArticleSize;
 
-               wfProfileIn( __METHOD__ );
-               wfProfileIn( __METHOD__ . '-checks' );
+               $fname = 'EditPage::attemptSave';
+               wfProfileIn( $fname );
+               wfProfileIn( "$fname-checks" );
 
-               if ( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
+               if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) )
                {
-                       wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
+                       wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
                        return self::AS_HOOK_ERROR;
                }
 
@@ -756,7 +789,7 @@ class EditPage {
                $this->mMetaData = '' ;
 
                # Check for spam
-               $match = self::matchSpamRegex( $this->summary );
+               $match = self::matchSummarySpamRegex( $this->summary );
                if ( $match === false ) {
                        $match = self::matchSpamRegex( $this->textbox1 );
                }
@@ -766,105 +799,114 @@ class EditPage {
                        $pdbk = $this->mTitle->getPrefixedDBkey();
                        $match = str_replace( "\n", '', $match );
                        wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_SPAM_ERROR;
                }
                if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
                        # Error messages or other handling should be performed by the filter function
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_FILTERING;
                }
                if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
                        # Error messages etc. could be handled within the hook...
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_HOOK_ERROR;
                } elseif ( $this->hookError != '' ) {
                        # ...or the hook could be expecting us to produce an error
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_HOOK_ERROR_EXPECTED;
                }
                if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
                        # Check block state against master, thus 'false'.
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_BLOCKED_PAGE_FOR_USER;
                }
                $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
                if ( $this->kblength > $wgMaxArticleSize ) {
                        // Error will be displayed by showEditForm()
                        $this->tooBig = true;
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_CONTENT_TOO_BIG;
                }
 
                if ( !$wgUser->isAllowed('edit') ) {
                        if ( $wgUser->isAnon() ) {
-                               wfProfileOut( __METHOD__ . '-checks' );
-                               wfProfileOut( __METHOD__ );
+                               wfProfileOut( "$fname-checks" );
+                               wfProfileOut( $fname );
                                return self::AS_READ_ONLY_PAGE_ANON;
                        }
                        else {
-                               wfProfileOut( __METHOD__ . '-checks' );
-                               wfProfileOut( __METHOD__ );
+                               wfProfileOut( "$fname-checks" );
+                               wfProfileOut( $fname );
                                return self::AS_READ_ONLY_PAGE_LOGGED;
                        }
                }
 
                if ( wfReadOnly() ) {
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_READ_ONLY_PAGE;
                }
                if ( $wgUser->pingLimiter() ) {
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_RATE_LIMITED;
                }
 
                # If the article has been deleted while editing, don't save it without
                # confirmation
                if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( "$fname-checks" );
+                       wfProfileOut( $fname );
                        return self::AS_ARTICLE_WAS_DELETED;
                }
 
-               wfProfileOut( __METHOD__ . '-checks' );
+               wfProfileOut( "$fname-checks" );
 
                # 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->userCan( 'create' ) ) {
-                               wfDebug( __METHOD__ . ": no create permission\n" );
-                               wfProfileOut( __METHOD__ );
+                               wfDebug( "$fname: no create permission\n" );
+                               wfProfileOut( $fname );
                                return self::AS_NO_CREATE_PERMISSION;
                        }
 
                        # Don't save a new article if it's blank.
                        if ( '' == $this->textbox1 ) {
-                               wfProfileOut( __METHOD__ );
+                               wfProfileOut( $fname );
                                return self::AS_BLANK_ARTICLE;
                        }
 
                        // Run post-section-merge edit filter
                        if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
                                # Error messages etc. could be handled within the hook...
-                               wfProfileOut( __METHOD__ );
+                               wfProfileOut( $fname );
                                return self::AS_HOOK_ERROR;
                        }
+                       
+                       # Handle the user preference to force summaries here. Check if it's not a redirect.
+                       if ( !$this->allowBlankSummary && !Title::newFromRedirect( $this->textbox1 ) ) {
+                               if ( md5( $this->summary ) == $this->autoSumm ) {
+                                       $this->missingSummary = true;
+                                       wfProfileOut( $fname );
+                                       return self::AS_SUMMARY_NEEDED;
+                               }
+                       }
 
                        $isComment = ( $this->section == 'new' );
 
                        $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
-                               $this->minoredit, $this->watchthis, false, $isComment, $bot);
+                               $this->minoredit, $this->watchthis, false, $isComment, $bot );
 
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return self::AS_SUCCESS_NEW_ARTICLE;
                }
 
@@ -892,44 +934,40 @@ class EditPage {
                        }
                }
                $userid = $wgUser->getId();
+               
+               # Suppress edit conflict with self, except for section edits where merging is required.
+               if ( $this->isConflict && $this->section == '' && $this->userWasLastToEdit($userid,$this->edittime) ) {
+                       wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
+                       $this->isConflict = false;
+               }
 
                if ( $this->isConflict ) {
                        wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
                                $this->mArticle->getTimestamp() . "')\n" );
-                       $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime);
-               }
-               else {
+                       $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime );
+               } else {
                        wfDebug( "EditPage::editForm getting section '$this->section'\n" );
-                       $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary);
+                       $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary );
                }
                if ( is_null( $text ) ) {
                        wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
                        $this->isConflict = true;
-                       $text = $this->textbox1;
-               }
-
-               # Suppress edit conflict with self, except for section edits where merging is required.
-               if ( $this->section == '' && $userid && $this->userWasLastToEdit($userid,$this->edittime) ) {
-                       wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
-                       $this->isConflict = false;
-               } else {
-                       # switch from section editing to normal editing in edit conflict
-                       if ( $this->isConflict ) {
-                               # Attempt merge
-                               if ( $this->mergeChangesInto( $text ) ) {
-                                       // Successful merge! Maybe we should tell the user the good news?
-                                       $this->isConflict = false;
-                                       wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
-                               } else {
-                                       $this->section = '';
-                                       $this->textbox1 = $text;
-                                       wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
-                               }
+                       $text = $this->textbox1; // do not try to merge here!
+               } else if ( $this->isConflict ) {
+                       # Attempt merge
+                       if ( $this->mergeChangesInto( $text ) ) {
+                               // Successful merge! Maybe we should tell the user the good news?
+                               $this->isConflict = false;
+                               wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
+                       } else {
+                               $this->section = '';
+                               $this->textbox1 = $text;
+                               wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
                        }
                }
 
                if ( $this->isConflict ) {
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return self::AS_CONFLICT_DETECTED;
                }
 
@@ -938,17 +976,17 @@ class EditPage {
                // Run post-section-merge edit filter
                if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
                        # Error messages etc. could be handled within the hook...
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return self::AS_HOOK_ERROR;
                }
 
                # Handle the user preference to force summaries here, but not for null edits
-               if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext, $text) &&
-                       !is_object( Title::newFromRedirect( $text ) ) # check if it's not a redirect
-               {
+               if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext,$text) 
+                       && !Title::newFromRedirect( $text ) ) # check if it's not a redirect
+               {
                        if ( md5( $this->summary ) == $this->autoSumm ) {
                                $this->missingSummary = true;
-                               wfProfileOut( __METHOD__ );
+                               wfProfileOut( $fname );
                                return self::AS_SUMMARY_NEEDED;
                        }
                }
@@ -957,13 +995,13 @@ class EditPage {
                if ( $this->section == 'new' && !$this->allowBlankSummary ) {
                        if (trim($this->summary) == '') {
                                $this->missingSummary = true;
-                               wfProfileOut( __METHOD__ );
+                               wfProfileOut( $fname );
                                return self::AS_SUMMARY_NEEDED;
                        }
                }
 
                # All's well
-               wfProfileIn( __METHOD__ . '-sectionanchor' );
+               wfProfileIn( "$fname-sectionanchor" );
                $sectionanchor = '';
                if ( $this->section == 'new' ) {
                        if ( $this->textbox1 == '' ) {
@@ -988,7 +1026,7 @@ class EditPage {
                                $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
                        }
                }
-               wfProfileOut( __METHOD__ . '-sectionanchor' );
+               wfProfileOut( "$fname-sectionanchor" );
 
                // Save errors may fall down to the edit form, but we've now
                // merged the section into full text. Clear the section field
@@ -1001,19 +1039,20 @@ class EditPage {
                $this->kblength = (int)(strlen( $text ) / 1024);
                if ( $this->kblength > $wgMaxArticleSize ) {
                        $this->tooBig = true;
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
                }
 
                # update the article here
                if ( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
-                       $this->watchthis, $bot, $sectionanchor ) ) {
-                       wfProfileOut( __METHOD__ );
+                       $this->watchthis, $bot, $sectionanchor ) ) 
+               {
+                       wfProfileOut( $fname );
                        return self::AS_SUCCESS_UPDATE;
                } else {
                        $this->isConflict = true;
                }
-               wfProfileOut( __METHOD__ );
+               wfProfileOut( $fname );
                return self::AS_END;
        }
        
@@ -1023,6 +1062,7 @@ class EditPage {
         * 50 revisions for the sake of performance.
         */
        protected function userWasLastToEdit( $id, $edittime ) {
+               if( !$id ) return false;
                $dbw = wfGetDB( DB_MASTER );
                $res = $dbw->select( 'revision',
                        'rev_user',
@@ -1039,21 +1079,33 @@ class EditPage {
                }
                return true;
        }
-       
+
        /**
         * Check given input text against $wgSpamRegex, and return the text of the first match.
         * @return mixed -- matching string or false
         */
        public static function matchSpamRegex( $text ) {
                global $wgSpamRegex;
-               if ( $wgSpamRegex ) {
-                       // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
-                       $regexes = (array)$wgSpamRegex;
-                       foreach( $regexes as $regex ) {
-                               $matches = array();
-                               if ( preg_match( $regex, $text, $matches ) ) {
-                                       return $matches[0];
-                               }
+               // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
+               $regexes = (array)$wgSpamRegex;
+               return self::matchSpamRegexInternal( $text, $regexes );
+       }
+       
+       /**
+        * Check given input text against $wgSpamRegex, and return the text of the first match.
+        * @return mixed -- matching string or false
+        */
+       public static function matchSummarySpamRegex( $text ) {
+               global $wgSummarySpamRegex;
+               $regexes = (array)$wgSummarySpamRegex;
+               return self::matchSpamRegexInternal( $text, $regexes );
+       }
+       
+       protected static function matchSpamRegexInternal( $text, $regexes ) {
+               foreach( $regexes as $regex ) {
+                       $matches = array();
+                       if( preg_match( $regex, $text, $matches ) ) {
+                               return $matches[0];
                        }
                }
                return false;
@@ -1084,7 +1136,7 @@ class EditPage {
                        $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
                } else {
                        # Use the title defined by DISPLAYTITLE magic word when present
-                       if ( isset( $this->mParserOutput )
+                       if ( isset($this->mParserOutput)
                         && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
                                $title = $dt;
                        } else {
@@ -1107,15 +1159,14 @@ class EditPage {
                # Some hook probably called this function  without checking
                # for is_null($wgTitle) first. Bail out right here so we don't
                # do lots of work just to discard it right after.
-               if ( is_null( $wgTitle ) )
+               if (is_null($wgTitle))
                        return;
 
-               wfProfileIn( __METHOD__ );
+               $fname = 'EditPage::showEditForm';
+               wfProfileIn( $fname );
 
                $sk = $wgUser->getSkin();
 
-               wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
-
                #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
@@ -1124,6 +1175,8 @@ class EditPage {
                if ( $this->formtype == 'preview' ) {
                        $previewOutput = $this->getPreviewText();
                }
+               
+               wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
 
                $this->setHeaders();
 
@@ -1131,7 +1184,7 @@ class EditPage {
                $wgOut->setArticleRelated( true );
 
                if ( $this->isConflict ) {
-                       $wgOut->addWikiMsg( 'explainconflict' );
+                       $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1</div>", 'explainconflict' );
 
                        $this->textbox2 = $this->textbox1;
                        $this->textbox1 = $this->getContent();
@@ -1140,9 +1193,7 @@ class EditPage {
                        if ( $this->section != '' && $this->section != 'new' ) {
                                $matches = array();
                                if ( !$this->summary && !$this->preview && !$this->diff ) {
-                                       preg_match( "/^(=+)(.+)\\1/mi",
-                                               $this->textbox1,
-                                               $matches );
+                                       preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1, $matches );
                                        if ( !empty( $matches[2] ) ) {
                                                global $wgParser;
                                                $this->summary = "/* " .
@@ -1153,7 +1204,7 @@ class EditPage {
                        }
 
                        if ( $this->missingComment ) {
-                               $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>',  'missingcommenttext' );
+                               $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
                        }
 
                        if ( $this->missingSummary && $this->section != 'new' ) {
@@ -1175,9 +1226,9 @@ class EditPage {
                        // Let sysop know that this will make private content public if saved
 
                                if ( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) {
-                                       $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
+                                       $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
                                } else if ( $this->mArticle->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
-                                       $wgOut->addWikiMsg( 'rev-deleted-text-view' );
+                                       $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
                                }
 
                                if ( !$this->mArticle->mRevision->isCurrent() ) {
@@ -1194,20 +1245,20 @@ class EditPage {
                } else {
                        if ( $this->isCssJsSubpage ) {
                                # Check the skin exists
-                               if ( $this->isValidCssJsSubpage ) {
-                                       if ( $this->formtype !== 'preview' ) {
-                                               $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
-                                       }
-                               } else {
+                               if ( !$this->isValidCssJsSubpage ) {
                                        $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
                                }
+                               if ( $this->formtype !== 'preview' ) {
+                                       if ( $this->isCssSubpage )
+                                               $wgOut->addWikiMsg( 'usercssyoucanpreview' );
+                                       if ( $this->isJsSubpage )
+                                               $wgOut->addWikiMsg( 'userjsyoucanpreview' );
+                               }
                        }
                }
 
                $classes = array(); // Textarea CSS
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
-                       # Show a warning if editing an interface message
-                       $wgOut->addWikiMsg( 'editinginterface' );
                } elseif ( $this->mTitle->isProtected( 'edit' ) ) {
                        # Is the title semi-protected?
                        if ( $this->mTitle->isSemiProtected() ) {
@@ -1226,17 +1277,19 @@ class EditPage {
                if ( $this->mTitle->isCascadeProtected() ) {
                        # Is this page under cascading protection from some source pages?
                        list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources();
-                       $notice = "$1\n";
-                       if ( count($cascadeSources) > 0 ) {
+                       $notice = "<div class='mw-cascadeprotectedwarning'>$1\n";
+                       $cascadeSourcesCount = count( $cascadeSources );
+                       if ( $cascadeSourcesCount > 0 ) {
                                # Explain, and list the titles responsible
                                foreach( $cascadeSources as $page ) {
                                        $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
                                }
                        }
-                       $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', count($cascadeSources) ) );
+                       $notice .= '</div>';
+                       $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
                }
                if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
-                       $wgOut->addWikiMsg( 'titleprotectedwarning' );
+                       $wgOut->wrapWikiMsg( '<div class="mw-titleprotectedwarning">$1</div>', 'titleprotectedwarning' );
                }
 
                if ( $this->kblength === false ) {
@@ -1252,17 +1305,23 @@ class EditPage {
                        $wgOut->addHTML( "</div>\n" );
                }
 
-               $q = 'action='.$this->action;
-               #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
-               $action = $wgTitle->escapeLocalURL( $q );
+               $action = $wgTitle->escapeLocalURL( array( 'action' => $this->action ) );
 
-               $summary = wfMsgExt( 'summary', array( 'parseinline' ) );
-               $subject = wfMsgExt( 'subject', array( 'parseinline' ) );
+               $summary = wfMsgExt( 'summary', 'parseinline' );
+               $subject = wfMsgExt( 'subject', 'parseinline' );
 
-               $cancel = $sk->makeKnownLinkObj( $wgTitle, wfMsgHtml( 'cancel' ) );
-               $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
-               $edithelp = Xml::element( 'a', array( 'target' => 'helpwindow', 'href' => $edithelpurl ), wfMsg( 'edithelp' ) ) .
-                       ' ' . wfMsgExt( 'newwindow', array( 'parseinline' ) );
+               $cancel = $sk->link(
+                       $wgTitle,
+                       wfMsgExt( 'cancel', array( 'parseinline' ) ),
+                       array( 'id' => 'mw-editform-cancel' ),
+                       array(),
+                       array( 'known', 'noclasses' )
+               );
+               $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
+               $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
+               $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
+                       htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
+                       htmlspecialchars( wfMsg( 'newwindow' ) );
 
                global $wgRightsText;
                if ( $wgRightsText ) {
@@ -1273,6 +1332,8 @@ class EditPage {
                        $copywarnMsg = array( 'copyrightwarning2',
                                '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
                }
+               // Allow for site and per-namespace customization of contribution/copyright notice.
+               wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle, &$copywarnMsg ) );
 
                if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
                        # prepare toolbar for edit buttons
@@ -1281,6 +1342,7 @@ class EditPage {
                        $toolbar = '';
                }
 
+
                // activate checkboxes if user wants them to be always active
                if ( !$this->preview && !$this->diff ) {
                        # Sort out the "watch" checkbox
@@ -1294,7 +1356,7 @@ class EditPage {
                                # Already watched
                                $this->watchthis = true;
                        }
-                       
+
                        # May be overriden by request parameters
                        if( $wgRequest->getBool( 'watchthis' ) ) {
                                $this->watchthis = true;
@@ -1314,7 +1376,7 @@ class EditPage {
 
                # if this is a comment, show a subject line at the top, which is also the edit summary.
                # Otherwise, show a summary field at the bottom
-               $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME
+               $summarytext = $wgContLang->recodeForEdit( $this->summary );
 
                # If a blank edit summary was previously provided, and the appropriate
                # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
@@ -1328,26 +1390,69 @@ class EditPage {
                $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
                $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
                if ( $this->section == 'new' ) {
-                       $commentsubject = "<span id='wpSummaryLabel'><label for='wpSummary'>{$subject}</label></span>\n" .
-                               "<input tabindex='1' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' />" .
-                               "{$summaryhiddens}<br />";
+                       $commentsubject = '';
+                       if ( !$wgRequest->getBool( 'nosummary' ) ) {
+                               # Add a class if 'missingsummary' is triggered to allow styling of the summary line
+                               $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
+
+                               $commentsubject =
+                                       Xml::tags( 'label', array( 'for' => 'wpSummary' ), $subject );
+                               $commentsubject =
+                                       Xml::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
+                                               $commentsubject );
+                               $commentsubject .= '&nbsp;';
+                               $commentsubject .= Xml::input( 'wpSummary',
+                                                                       60,
+                                                                       $summarytext,
+                                                                       array(
+                                                                               'id' => 'wpSummary',
+                                                                               'maxlength' => '200',
+                                                                               'tabindex' => '1'
+                                                                       ) );
+                       } else {
+                               $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true ); # bug 18699
+                       }
                        $editsummary = "<div class='editOptions'>\n";
                        global $wgParser;
                        $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
-                       $subjectpreview = $summarytext && $this->preview ?
-                               "<div class=\"mw-summary-preview\">" . wfMsgExt( 'subject-preview', array( 'escapenoentities' ) ) .
-                               $sk->commentBlock( $formattedSummary, $this->mTitle, true ) . "</div>\n" : '';
+                       $subjectpreview = $summarytext && ( $this->preview || $this->diff ) ?
+                               "<div class=\"mw-summary-preview\">". wfMsgExt('subject-preview', 'parseinline') . $sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
                        $summarypreview = '';
                } else {
                        $commentsubject = '';
-                       $editsummary = "<div class='editOptions'>\n<span id='wpSummaryLabel'><label for='wpSummary'>{$summary}</label></span>\n" .
-                               "<input tabindex='2' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' />" .
-                               "{$summaryhiddens}<br />";
+
+                       # Add a class if 'missingsummary' is triggered to allow styling of the summary line
+                       $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
+
+                       $editsummary = Xml::tags( 'label', array( 'for' => 'wpSummary' ), $summary );
+                       $editsummary = Xml::tags( 'span',  array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
+                                       $editsummary ) . ' ';
+
+                       $editsummary .= Xml::input( 'wpSummary',
+                               60,
+                               $summarytext,
+                               array(
+                                       'id' => 'wpSummary',
+                                       'maxlength' => '200',
+                                       'tabindex' => '1'
+                               ) );
+
+                       // No idea where this is closed.
+                       $editsummary = Xml::openElement( 'div', array( 'class' => 'editOptions' ) )
+                                                       . $editsummary . '<br/>';
+
+                       $summarypreview = '';
+                       if ( $summarytext && ( $this->preview || $this->diff ) ) {
+                               $summarypreview =
+                                       Xml::tags( 'div',
+                                               array( 'class' => 'mw-summary-preview' ),
+                                               wfMsgExt( 'summary-preview', 'parseinline' ) .
+                                                       $sk->commentBlock( $this->summary, $this->mTitle )
+                                       );
+                       }
                        $subjectpreview = '';
-                       $summarypreview = $summarytext && $this->preview ?
-                               "<div class=\"mw-summary-preview\">" . wfMsgExt( 'summary-preview', array( 'escapenoentities' ) ) .
-                               $sk->commentBlock( $this->summary, $this->mTitle ) . "</div>\n" : '';
                }
+               $commentsubject .= $summaryhiddens;
 
                # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
                if ( !$this->preview && !$this->diff ) {
@@ -1361,7 +1466,7 @@ class EditPage {
 
                global $wgUseMetadataEdit ;
                if ( $wgUseMetadataEdit ) {
-                       $metadata = $this->mMetaData;
+                       $metadata = $this->mMetaData ;
                        $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
                        $top = wfMsgWikiHtml( 'metadata_help' );
                        /* ToDo: Replace with clean code */
@@ -1377,15 +1482,18 @@ class EditPage {
                $recreate = '';
                if ( $this->wasDeletedSinceLastEdit() ) {
                        if ( 'save' != $this->formtype ) {
-                               $wgOut->addWikiMsg( 'deletedwhileediting' );
+                               $wgOut->wrapWikiMsg(
+                                       "<div class='error mw-deleted-while-editing'>\n$1</div>",
+                                       'deletedwhileediting' );
                        } else {
-                               // Hide the toolbar and edit area, use can click preview to get it back
+                               // Hide the toolbar and edit area, user can click preview to get it back
                                // Add an confirmation checkbox and explanation.
                                $toolbar = '';
-                               $recreate = wfMsgExt( 'confirmrecreate',  array( 'parse' ), $this->lastDelete->user_name , $this->lastDelete->log_comment ) .
-                                       "<br />" .
-                                       Xml::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
-                                               array( 'tabindex' => '1' ), array( 'title' => wfMsg( 'tooltip-recreate' ) ) );
+                               $recreate = '<div class="mw-confirm-recreate">' .
+                                               $wgOut->parse( wfMsg( 'confirmrecreate',  $this->lastDelete->user_name , $this->lastDelete->log_comment ) ) .
+                                               Xml::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
+                                                       array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
+                                               ) . '</div>';
                        }
                }
 
@@ -1440,7 +1548,7 @@ END
                $wgOut->addHTML(
 "<div class='editButtons'>
 {$buttonshtml}
-       <span class='editHelp'>{$cancel} | {$edithelp}</span>
+       <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>
 </div><!-- editButtons -->
 </div><!-- editOptions -->");
 
@@ -1459,6 +1567,7 @@ END
                $token = htmlspecialchars( $wgUser->editToken() );
                $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
 
+               $this->showTosSummary();
                $this->showEditTools();
 
                $wgOut->addHTML( <<<END
@@ -1473,13 +1582,13 @@ END
 );
 
                if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
-                       $wgOut->wrapWikiMsg( '==$1==', 'yourdiff' );
+                       $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
 
                        $de = new DifferenceEngine( $this->mTitle );
                        $de->setText( $this->textbox2, $this->textbox1 );
-                       $de->showDiff( wfMsgExt( 'yourtext', array( 'parseinline' ) ), wfMsgExt( 'storedversion', array( 'parseinline' ) ) );
+                       $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
 
-                       $wgOut->wrapWikiMsg( '==$1==', 'yourtext' );
+                       $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
                        $this->showTextbox2();
                }
                $wgOut->addHTML( $this->editFormTextBottom );
@@ -1488,7 +1597,7 @@ END
                        $this->displayPreviewArea( $previewOutput, false );
                }
 
-               wfProfileOut( __METHOD__ );
+               wfProfileOut( $fname );
        }
 
        protected function showFormBeforeText() {
@@ -1597,10 +1706,25 @@ END
        function doLivePreviewScript() {
                global $wgOut, $wgTitle;
                $wgOut->addScriptFile( 'preview.js' );
-               $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
-               return "return !lpDoPreview(" .
-                       "editform.wpTextbox1.value," .
-                       '"' . $liveAction . '"' . ")";
+               return "";
+       }
+
+       protected function showTosSummary() {
+               $msg = 'editpage-tos-summary';
+               // Give a chance for site and per-namespace customizations of
+               // terms of service summary link that might exist separately
+               // from the copyright notice.
+               //
+               // This will display between the save button and the edit tools,
+               // so should remain short!
+               wfRunHooks( 'EditPageTosSummary', array( $this->mTitle, &$msg ) );
+               $text = wfMsg( $msg );
+               if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) {
+                       global $wgOut;
+                       $wgOut->addHTML( '<div class="mw-tos-summary">' );
+                       $wgOut->addWikiMsgArray( $msg, array() );
+                       $wgOut->addHTML( '</div>' );
+               }
        }
 
        protected function showEditTools() {
@@ -1610,7 +1734,7 @@ END
                $wgOut->addHTML( '</div>' );
        }
 
-       function getLastDelete() {
+       protected function getLastDelete() {
                $dbr = wfGetDB( DB_SLAVE );
                $data = $dbr->selectRow(
                        array( 'logging', 'user' ),
@@ -1622,15 +1746,23 @@ END
                               'log_title',
                               'log_comment',
                               'log_params',
-                              'user_name', ),
+                                  'log_deleted',
+                              'user_name' ),
                        array( 'log_namespace' => $this->mTitle->getNamespace(),
                               'log_title' => $this->mTitle->getDBkey(),
                               'log_type' => 'delete',
                               'log_action' => 'delete',
                               'user_id=log_user' ),
                        __METHOD__,
-                       array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
-
+                       array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
+               );
+               // Quick paranoid permission checks...
+               if( is_object($data) ) {
+                       if( $data->log_deleted & LogPage::DELETED_USER )
+                               $data->user_name = wfMsgHtml('rev-deleted-user');
+                       if( $data->log_deleted & LogPage::DELETED_COMMENT )
+                               $data->log_comment = wfMsgHtml('rev-deleted-comment');
+               }
                return $data;
        }
 
@@ -1655,6 +1787,8 @@ END
 
                $parserOptions = ParserOptions::newFromUser( $wgUser );
                $parserOptions->setEditSection( false );
+               $parserOptions->setIsPreview( true );
+               $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
 
                global $wgRawHtml;
                if ( $wgRawHtml && !$this->mTokenOk ) {
@@ -1676,7 +1810,7 @@ END
                        $parserOptions->setTidy(true);
                        $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
                        $previewHTML = $parserOutput->mText;
-               } elseif ( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
+               } elseif ( $rt = Title::newFromRedirectArray( $this->textbox1 ) ) {
                        $previewHTML = $this->mArticle->viewRedirect( $rt, false );
                } else {
                        $toparse = $this->textbox1;
@@ -1711,12 +1845,16 @@ END
                        }
                }
 
-               $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
-                       "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
-               if ( $this->isConflict ) {
-                       $previewhead .='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
+               if( $this->isConflict ) {
+                       $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
+               } else {
+                       $conflict = '<hr />';
                }
 
+               $previewhead = "<div class='previewnote'>\n" .
+                       '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
+                       $wgOut->parse( $note ) . $conflict . "</div>\n";
+
                wfProfileOut( __METHOD__ );
                return $previewhead . $previewHTML;
        }
@@ -1773,7 +1911,13 @@ END
                $skin = $wgUser->getSkin();
 
                $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
-               $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
+               $loginLink = $skin->link(
+                       $loginTitle,
+                       wfMsgHtml( 'loginreqlink' ),
+                       array(),
+                       array( 'returnto' => $wgTitle->getPrefixedText() ),
+                       array( 'known', 'noclasses' )
+               );
 
                $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
@@ -1785,7 +1929,7 @@ END
 
        /**
         * Creates a basic error page which informs the user that
-        * they have attempted to edit a nonexistant section.
+        * they have attempted to edit a nonexistent section.
         */
        function noSuchSectionPage() {
                global $wgOut, $wgTitle;
@@ -1824,23 +1968,23 @@ END
         * @todo document
         */
        function mergeChangesInto( &$editText ){
-               wfProfileIn( __METHOD__ );
+               $fname = 'EditPage::mergeChangesInto';
+               wfProfileIn( $fname );
 
                $db = wfGetDB( DB_MASTER );
 
                // This is the revision the editor started from
                $baseRevision = $this->getBaseRevision();
                if ( is_null( $baseRevision ) ) {
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return false;
                }
                $baseText = $baseRevision->getText();
 
                // The current state, we want to merge updates into it
-               $currentRevision =  Revision::loadFromTitle(
-                       $db, $this->mTitle );
+               $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
                if ( is_null( $currentRevision ) ) {
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return false;
                }
                $currentText = $currentRevision->getText();
@@ -1848,10 +1992,10 @@ END
                $result = '';
                if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
                        $editText = $result;
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return true;
                } else {
-                       wfProfileOut( __METHOD__ );
+                       wfProfileOut( $fname );
                        return false;
                }
        }
@@ -1905,7 +2049,7 @@ END
         * @return string
         */
        static function getEditToolbar() {
-               global $wgStylePath, $wgContLang, $wgLang, $wgJsMimeType;
+               global $wgStylePath, $wgContLang, $wgLang;
 
                /**
                 * toolarray an array of arrays which each include the filename of
@@ -1920,109 +2064,109 @@ END
                 */
                $toolarray = array(
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-bold' ),
+                               'image'  => $wgLang->getImageFile('button-bold'),
                                'id'     => 'mw-editbutton-bold',
                                'open'   => '\'\'\'',
                                'close'  => '\'\'\'',
-                               'sample' => wfMsg( 'bold_sample' ),
-                               'tip'    => wfMsg( 'bold_tip' ),
+                               'sample' => wfMsg('bold_sample'),
+                               'tip'    => wfMsg('bold_tip'),
                                'key'    => 'B'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-italic' ),
+                               'image'  => $wgLang->getImageFile('button-italic'),
                                'id'     => 'mw-editbutton-italic',
                                'open'   => '\'\'',
                                'close'  => '\'\'',
-                               'sample' => wfMsg( 'italic_sample' ),
-                               'tip'    => wfMsg( 'italic_tip' ),
+                               'sample' => wfMsg('italic_sample'),
+                               'tip'    => wfMsg('italic_tip'),
                                'key'    => 'I'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-link' ),
+                               'image'  => $wgLang->getImageFile('button-link'),
                                'id'     => 'mw-editbutton-link',
                                'open'   => '[[',
                                'close'  => ']]',
-                               'sample' => wfMsg( 'link_sample' ),
-                               'tip'    => wfMsg( 'link_tip' ),
+                               'sample' => wfMsg('link_sample'),
+                               'tip'    => wfMsg('link_tip'),
                                'key'    => 'L'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-extlink' ),
+                               'image'  => $wgLang->getImageFile('button-extlink'),
                                'id'     => 'mw-editbutton-extlink',
                                'open'   => '[',
                                'close'  => ']',
-                               'sample' => wfMsg( 'extlink_sample' ),
-                               'tip'    => wfMsg( 'extlink_tip' ),
+                               'sample' => wfMsg('extlink_sample'),
+                               'tip'    => wfMsg('extlink_tip'),
                                'key'    => 'X'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-headline' ),
+                               'image'  => $wgLang->getImageFile('button-headline'),
                                'id'     => 'mw-editbutton-headline',
                                'open'   => "\n== ",
                                'close'  => " ==\n",
-                               'sample' => wfMsg( 'headline_sample' ),
-                               'tip'    => wfMsg( 'headline_tip' ),
+                               'sample' => wfMsg('headline_sample'),
+                               'tip'    => wfMsg('headline_tip'),
                                'key'    => 'H'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-image' ),
+                               'image'  => $wgLang->getImageFile('button-image'),
                                'id'     => 'mw-editbutton-image',
-                               'open'   => '[['.$wgContLang->getNsText( NS_FILE ).':',
+                               'open'   => '[['.$wgContLang->getNsText(NS_FILE).':',
                                'close'  => ']]',
-                               'sample' => wfMsg( 'image_sample' ),
-                               'tip'    => wfMsg( 'image_tip' ),
+                               'sample' => wfMsg('image_sample'),
+                               'tip'    => wfMsg('image_tip'),
                                'key'    => 'D'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-media' ),
+                               'image'  => $wgLang->getImageFile('button-media'),
                                'id'     => 'mw-editbutton-media',
-                               'open'   => '[['.$wgContLang->getNsText( NS_MEDIA ).':',
+                               'open'   => '[['.$wgContLang->getNsText(NS_MEDIA).':',
                                'close'  => ']]',
-                               'sample' => wfMsg( 'media_sample' ),
-                               'tip'    => wfMsg( 'media_tip' ),
+                               'sample' => wfMsg('media_sample'),
+                               'tip'    => wfMsg('media_tip'),
                                'key'    => 'M'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-math' ),
+                               'image'  => $wgLang->getImageFile('button-math'),
                                'id'     => 'mw-editbutton-math',
                                'open'   => "<math>",
                                'close'  => "</math>",
-                               'sample' => wfMsg( 'math_sample' ),
-                               'tip'    => wfMsg( 'math_tip' ),
+                               'sample' => wfMsg('math_sample'),
+                               'tip'    => wfMsg('math_tip'),
                                'key'    => 'C'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-nowiki' ),
+                               'image'  => $wgLang->getImageFile('button-nowiki'),
                                'id'     => 'mw-editbutton-nowiki',
                                'open'   => "<nowiki>",
                                'close'  => "</nowiki>",
-                               'sample' => wfMsg( 'nowiki_sample' ),
-                               'tip'    => wfMsg( 'nowiki_tip' ),
+                               'sample' => wfMsg('nowiki_sample'),
+                               'tip'    => wfMsg('nowiki_tip'),
                                'key'    => 'N'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-sig' ),
+                               'image'  => $wgLang->getImageFile('button-sig'),
                                'id'     => 'mw-editbutton-signature',
                                'open'   => '--~~~~',
                                'close'  => '',
                                'sample' => '',
-                               'tip'    => wfMsg( 'sig_tip' ),
+                               'tip'    => wfMsg('sig_tip'),
                                'key'    => 'Y'
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-hr' ),
+                               'image'  => $wgLang->getImageFile('button-hr'),
                                'id'     => 'mw-editbutton-hr',
                                'open'   => "\n----\n",
                                'close'  => '',
                                'sample' => '',
-                               'tip'    => wfMsg( 'hr_tip' ),
+                               'tip'    => wfMsg('hr_tip'),
                                'key'    => 'R'
                        )
                );
                $toolbar = "<div id='toolbar'>\n";
-               $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
 
-               foreach( $toolarray as $tool ) {
+               $script = '';
+               foreach ( $toolarray as $tool ) {
                        $params = array(
                                $image = $wgStylePath.'/common/images/'.$tool['image'],
                                // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
@@ -2038,11 +2182,14 @@ END
 
                        $paramList = implode( ',',
                                array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
-                       $toolbar.="addButton($paramList);\n";
+                       $script .= "addButton($paramList);\n";
                }
+               $toolbar .= Html::inlineScript( "\n$script\n" );
+
+               $toolbar .= "\n</div>";
+
+               wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
 
-               $toolbar.="/*]]>*/\n</script>";
-               $toolbar.="\n</div>";
                return $toolbar;
        }
 
@@ -2063,8 +2210,8 @@ END
                $checkboxes = array();
 
                $checkboxes['minor'] = '';
-               $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
-               if ( $wgUser->isAllowed( 'minoredit' ) ) {
+               $minorLabel = wfMsgExt('minoredit', array('parseinline'));
+               if ( $wgUser->isAllowed('minoredit') ) {
                        $attribs = array(
                                'tabindex'  => ++$tabindex,
                                'accesskey' => wfMsg( 'accesskey-minoredit' ),
@@ -2072,10 +2219,10 @@ END
                        );
                        $checkboxes['minor'] =
                                Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
-                               "&nbsp;<label for='wpMinoredit'" . $skin->tooltip( 'minoredit', 'withaccess' ) . ">{$minorLabel}</label>";
+                               "&nbsp;<label for='wpMinoredit'".$skin->tooltip('minoredit', 'withaccess').">{$minorLabel}</label>";
                }
 
-               $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
+               $watchLabel = wfMsgExt('watchthis', array('parseinline'));
                $checkboxes['watch'] = '';
                if ( $wgUser->isLoggedIn() ) {
                        $attribs = array(
@@ -2085,7 +2232,7 @@ END
                        );
                        $checkboxes['watch'] =
                                Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
-                               "&nbsp;<label for='wpWatchthis'" . $skin->tooltip('watch', 'withaccess') . ">{$watchLabel}</label>";
+                               "&nbsp;<label for='wpWatchthis'".$skin->tooltip('watch', 'withaccess').">{$watchLabel}</label>";
                }
                wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
                return $checkboxes;
@@ -2099,7 +2246,7 @@ END
         *
         * @return array
         */
-       public function getEditButtons( &$tabindex ) {
+       public function getEditButtons(&$tabindex) {
                global $wgLivePreview, $wgUser;
 
                $buttons = array();
@@ -2109,25 +2256,27 @@ END
                        'name'      => 'wpSave',
                        'type'      => 'submit',
                        'tabindex'  => ++$tabindex,
-                       'value'     => wfMsg( 'savearticle' ),
-                       'accesskey' => wfMsg( 'accesskey-save' ),
+                       'value'     => wfMsg('savearticle'),
+                       'accesskey' => wfMsg('accesskey-save'),
                        'title'     => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
                );
-               $buttons['save'] = Xml::element( 'input', $temp, '' );
+               $buttons['save'] = Xml::element('input', $temp, '');
 
                ++$tabindex; // use the same for preview and live preview
                if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
+                       $this->doLivePreviewScript(); // Add to output
+                       
                        $temp = array(
                                'id'        => 'wpPreview',
                                'name'      => 'wpPreview',
                                'type'      => 'submit',
                                'tabindex'  => $tabindex,
-                               'value'     => wfMsg( 'showpreview' ),
+                               'value'     => wfMsg('showpreview'),
                                'accesskey' => '',
                                'title'     => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
                                'style'     => 'display: none;',
                        );
-                       $buttons['preview'] = Xml::element( 'input', $temp, '' );
+                       $buttons['preview'] = Xml::element('input', $temp, '');
 
                        $temp = array(
                                'id'        => 'wpLivePreview',
@@ -2137,20 +2286,20 @@ END
                                'value'     => wfMsg('showlivepreview'),
                                'accesskey' => wfMsg('accesskey-preview'),
                                'title'     => '',
-                               'onclick'   => $this->doLivePreviewScript(),
                        );
-                       $buttons['live'] = Xml::element( 'input', $temp, '' );
+                       
+                       $buttons['live'] = Xml::element('input', $temp, '');
                } else {
                        $temp = array(
                                'id'        => 'wpPreview',
                                'name'      => 'wpPreview',
                                'type'      => 'submit',
                                'tabindex'  => $tabindex,
-                               'value'     => wfMsg( 'showpreview' ),
-                               'accesskey' => wfMsg( 'accesskey-preview' ),
+                               'value'     => wfMsg('showpreview'),
+                               'accesskey' => wfMsg('accesskey-preview'),
                                'title'     => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
                        );
-                       $buttons['preview'] = Xml::element( 'input', $temp, '' );
+                       $buttons['preview'] = Xml::element('input', $temp, '');
                        $buttons['live'] = '';
                }
 
@@ -2159,11 +2308,11 @@ END
                        'name'      => 'wpDiff',
                        'type'      => 'submit',
                        'tabindex'  => ++$tabindex,
-                       'value'     => wfMsg( 'showdiff' ),
-                       'accesskey' => wfMsg( 'accesskey-diff' ),
+                       'value'     => wfMsg('showdiff'),
+                       'accesskey' => wfMsg('accesskey-diff'),
                        'title'     => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
                );
-               $buttons['diff'] = Xml::element( 'input', $temp, '' );
+               $buttons['diff'] = Xml::element('input', $temp, '');
 
                wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
                return $buttons;
@@ -2212,8 +2361,8 @@ END
                $newtext = $this->mArticle->replaceSection(
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
                $newtext = $this->mArticle->preSaveTransform( $newtext );
-               $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
-               $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
+               $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
+               $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
                if ( $oldtext !== false  || $newtext != '' ) {
                        $de = new DifferenceEngine( $this->mTitle );
                        $de->setText( $oldtext, $newtext );
@@ -2349,20 +2498,22 @@ END
        }
 
        /**
-        * If there are rows in the deletion log for this page, show them,
+        * If there are rows in the deletion/move log for this page, show them,
         * along with a nice little note for the user
         *
         * @param OutputPage $out
         */
-       protected function showDeletionLog( $out ) {
+       protected function showLogs( $out ) {
                global $wgUser;
                $loglist = new LogEventsList( $wgUser->getSkin(), $out );
-               $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
+               $pager = new LogPager( $loglist, array('move', 'delete'), false,
+                       $this->mTitle->getPrefixedText(), '', array( "log_action != 'revision'" ) );
+
                $count = $pager->getNumRows();
                if ( $count > 0 ) {
                        $pager->mLimit = 10;
                        $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
-                       $out->addWikiMsg( 'recreate-deleted-warn' );
+                       $out->addWikiMsg( 'recreate-moveddeleted-warn' );
                        $out->addHTML(
                                $loglist->beginLogEventsList() .
                                $pager->getBody() .
@@ -2371,11 +2522,9 @@ END
                        if($count > 10){
                                $out->addHTML( $wgUser->getSkin()->link(
                                        SpecialPage::getTitleFor( 'Log' ),
-                                       wfMsgHtml( 'deletelog-fulllog' ),
+                                       wfMsgHtml( 'log-fulllog' ),
                                        array(),
-                                       array(
-                                               'type' => 'delete',
-                                               'page' => $this->mTitle->getPrefixedText() ) ) );
+                                       array( 'page' => $this->mTitle->getPrefixedText() ) ) );
                        }
                        $out->addHTML( '</div>' );
                        return true;
@@ -2392,7 +2541,9 @@ END
                global $wgUser, $wgOut, $wgTitle, $wgRequest;
 
                $resultDetails = false;
-               $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) );
+               # Allow bots to exempt some edits from bot flagging
+               $bot = $wgUser->isAllowed('bot') && $wgRequest->getBool('bot',true);
+               $value = $this->internalAttemptSave( $resultDetails, $bot );
 
                if ( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
                        $this->didSave = true;