fix code style violations in RecentChange.php
[lhc/web/wiklou.git] / includes / EditPage.php
index d7b658f..00eb76f 100644 (file)
@@ -409,10 +409,13 @@ class EditPage {
                                wfProfileOut( __METHOD__ );
                                return;
                        }
-                       if ( !$this->mTitle->getArticleID() )
+
+                       if ( !$this->mTitle->getArticleID() ) {
                                wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) );
-                       else
+                       } else {
                                wfRunHooks( 'EditFormInitialText', array( $this ) );
+                       }
+
                }
 
                $this->showEditForm();
@@ -606,8 +609,10 @@ class EditPage {
                                // modified by subclasses
                                wfProfileIn( get_class( $this ) . "::importContentFormData" );
                                $textbox1 = $this->importContentFormData( $request );
-                               if ( isset( $textbox1 ) )
+                               if ( isset( $textbox1 ) ) {
                                        $this->textbox1 = $textbox1;
+                               }
+
                                wfProfileOut( get_class( $this ) . "::importContentFormData" );
                        }
 
@@ -1057,7 +1062,7 @@ class EditPage {
 
                $title = Title::newFromText( $preload );
                # Check for existence to avoid getting MediaWiki:Noarticletext
-               if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) {
+               if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
                        return $handler->makeEmptyContent();
                }
 
@@ -1065,7 +1070,7 @@ class EditPage {
                if ( $page->isRedirect() ) {
                        $title = $page->getRedirectTarget();
                        # Same as before
-                       if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) {
+                       if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
                                return $handler->makeEmptyContent();
                        }
                        $page = WikiPage::factory( $title );
@@ -1347,7 +1352,7 @@ class EditPage {
 
                if ( $new ) {
                        // Late check for create permission, just in case *PARANOIA*
-                       if ( !$this->mTitle->userCan( 'create' ) ) {
+                       if ( !$this->mTitle->userCan( 'create', $wgUser ) ) {
                                $status->fatal( 'nocreatetext' );
                                $status->value = self::AS_NO_CREATE_PERMISSION;
                                wfDebug( __METHOD__ . ": no create permission\n" );
@@ -1468,15 +1473,16 @@ class EditPage {
                                $this->isConflict = true;
                                $content = $textbox_content; // do not try to merge here!
                        } elseif ( $this->isConflict ) {
+                               $contentObj = $content;
                                # Attempt merge
-                               if ( $this->mergeChangesIntoContent( $textbox_content ) ) {
+                               if ( $this->mergeChangesInto( $content ) ) {
                                        // Successful merge! Maybe we should tell the user the good news?
                                        $this->isConflict = false;
-                                       $content = $textbox_content;
+                                       $content = $this->toEditContent( $content );
                                        wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
                                } else {
                                        $this->section = '';
-                                       $this->textbox1 = ContentHandler::getContentText( $content );
+                                       $this->textbox1 = ContentHandler::getContentText( $contentObj );
                                        wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
                                }
                        }
@@ -1603,7 +1609,7 @@ class EditPage {
 
                if ( $doEditStatus->isOK() ) {
                                $result['redirect'] = $content->isRedirect();
-                       $this->commitWatch();
+                       $this->updateWatchlist();
                        wfProfileOut( __METHOD__ );
                        return $status;
                } else {
@@ -1624,19 +1630,27 @@ class EditPage {
        }
 
        /**
-        * Commit the change of watch status
+        * Register the change of watch status
         */
-       protected function commitWatch() {
+       protected function updateWatchlist() {
                global $wgUser;
+
                if ( $wgUser->isLoggedIn() && $this->watchthis != $wgUser->isWatched( $this->mTitle ) ) {
+                       $fname = __METHOD__;
+                       $title = $this->mTitle;
+                       $watch = $this->watchthis;
+
+                       // Do this in its own transaction to reduce contention...
                        $dbw = wfGetDB( DB_MASTER );
-                       $dbw->begin( __METHOD__ );
-                       if ( $this->watchthis ) {
-                               WatchAction::doWatch( $this->mTitle, $wgUser );
-                       } else {
-                               WatchAction::doUnwatch( $this->mTitle, $wgUser );
-                       }
-                       $dbw->commit( __METHOD__ );
+                       $dbw->onTransactionIdle( function() use ( $dbw, $title, $watch, $wgUser, $fname ) {
+                               $dbw->begin( $fname );
+                               if ( $watch ) {
+                                       WatchAction::doWatch( $title, $wgUser );
+                               } else {
+                                       WatchAction::doUnwatch( $title, $wgUser );
+                               }
+                               $dbw->commit( $fname );
+                       } );
                }
        }
 
@@ -1652,15 +1666,37 @@ class EditPage {
        function mergeChangesInto( &$editText ){
                ContentHandler::deprecated( __METHOD__, "1.21" );
 
-               $editContent = $this->toEditContent( $editText );
+               wfProfileIn( __METHOD__ );
 
-               $ok = $this->mergeChangesIntoContent( $editContent );
+               $db = wfGetDB( DB_MASTER );
 
-               if ( $ok ) {
-                       $editText = $this->toEditText( $editContent );
+               // This is the revision the editor started from
+               $baseRevision = $this->getBaseRevision();
+               if ( is_null( $baseRevision ) ) {
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+               $baseText = $baseRevision->getText();
+
+               // The current state, we want to merge updates into it
+               $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
+               if ( is_null( $currentRevision ) ) {
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+               $currentText = $currentRevision->getText();
+
+               $result = '';
+               $editText = $this->toEditText( $editText );
+
+               if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
+                       $editText = $result;
+                       wfProfileOut( __METHOD__ );
                        return true;
+               } else {
+                       wfProfileOut( __METHOD__ );
+                       return false;
                }
-               return false;
        }
 
        /**
@@ -2235,7 +2271,7 @@ class EditPage {
                                if ( $revision ) {
                                        // Let sysop know that this will make private content public if saved
 
-                                       if ( !$revision->userCan( Revision::DELETED_TEXT ) ) {
+                                       if ( !$revision->userCan( Revision::DELETED_TEXT, $wgUser ) ) {
                                                $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
                                        } elseif ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
                                                $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
@@ -2269,10 +2305,13 @@ class EditPage {
                                        $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ) );
                                }
                                if ( $this->formtype !== 'preview' ) {
-                                       if ( $this->isCssSubpage )
+                                       if ( $this->isCssSubpage ) {
                                                $wgOut->wrapWikiMsg( "<div id='mw-usercssyoucanpreview'>\n$1\n</div>", array( 'usercssyoucanpreview' ) );
-                                       if ( $this->isJsSubpage )
+                                       }
+
+                                       if ( $this->isJsSubpage ) {
                                                $wgOut->wrapWikiMsg( "<div id='mw-userjsyoucanpreview'>\n$1\n</div>", array( 'userjsyoucanpreview' ) );
+                                       }
                                }
                        }
                }
@@ -2403,14 +2442,16 @@ class EditPage {
         * @return String
         */
        protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
-               if ( !$summary || ( !$this->preview && !$this->diff ) )
+               if ( !$summary || ( !$this->preview && !$this->diff ) ) {
                        return "";
+               }
 
                global $wgParser;
 
-               if ( $isSubjectPreview )
+               if ( $isSubjectPreview ) {
                        $summary = wfMessage( 'newsectionsummary', $wgParser->stripSectionName( $summary ) )
                                ->inContentLanguage()->text();
+               }
 
                $message = $isSubjectPreview ? 'subject-preview' : 'summary-preview';
 
@@ -2429,8 +2470,9 @@ class EditPage {
 
 HTML
                );
-               if ( !$this->checkUnicodeCompliantBrowser() )
+               if ( !$this->checkUnicodeCompliantBrowser() ) {
                        $wgOut->addHTML( Html::hidden( 'safemode', '1' ) );
+               }
        }
 
        protected function showFormAfterText() {
@@ -2546,8 +2588,9 @@ HTML
 
                $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
 
-               if ( $this->formtype != 'preview' )
+               if ( $this->formtype != 'preview' ) {
                        $attribs['style'] = 'display: none;';
+               }
 
                $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
 
@@ -2852,10 +2895,13 @@ HTML
                );
                // Quick paranoid permission checks...
                if ( is_object( $data ) ) {
-                       if ( $data->log_deleted & LogPage::DELETED_USER )
+                       if ( $data->log_deleted & LogPage::DELETED_USER ) {
                                $data->user_name = wfMessage( 'rev-deleted-user' )->escaped();
-                       if ( $data->log_deleted & LogPage::DELETED_COMMENT )
+                       }
+
+                       if ( $data->log_deleted & LogPage::DELETED_COMMENT ) {
                                $data->log_comment = wfMessage( 'rev-deleted-comment' )->escaped();
+                       }
                }
                return $data;
        }