Merge "Log the reason why revision->getContent() returns null"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 6847671..c7bb8ec 100644 (file)
@@ -434,8 +434,9 @@ class WikiPage implements Page, IDBAccessObject {
 
                if ( is_int( $from ) ) {
                        list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from );
-                       $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts );
                        $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
+                       $db = $loadBalancer->getConnection( $index );
+                       $data = $this->pageDataFromTitle( $db, $this->mTitle, $opts );
 
                        if ( !$data
                                && $index == DB_REPLICA
@@ -444,7 +445,8 @@ class WikiPage implements Page, IDBAccessObject {
                        ) {
                                $from = self::READ_LATEST;
                                list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from );
-                               $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts );
+                               $db = $loadBalancer->getConnection( $index );
+                               $data = $this->pageDataFromTitle( $db, $this->mTitle, $opts );
                        }
                } else {
                        // No idea from where the caller got this data, assume replica DB.
@@ -1425,16 +1427,17 @@ class WikiPage implements Page, IDBAccessObject {
        ) {
                $baseRevId = null;
                if ( $edittime && $sectionId !== 'new' ) {
-                       $dbr = wfGetDB( DB_REPLICA );
+                       $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+                       $dbr = $lb->getConnection( DB_REPLICA );
                        $rev = Revision::loadFromTimestamp( $dbr, $this->mTitle, $edittime );
                        // Try the master if this thread may have just added it.
                        // This could be abstracted into a Revision method, but we don't want
                        // to encourage loading of revisions by timestamp.
                        if ( !$rev
-                               && wfGetLB()->getServerCount() > 1
-                               && wfGetLB()->hasOrMadeRecentMasterChanges()
+                               && $lb->getServerCount() > 1
+                               && $lb->hasOrMadeRecentMasterChanges()
                        ) {
-                               $dbw = wfGetDB( DB_MASTER );
+                               $dbw = $lb->getConnection( DB_MASTER );
                                $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
                        }
                        if ( $rev ) {
@@ -2125,15 +2128,6 @@ class WikiPage implements Page, IDBAccessObject {
                $edit->newContent = $content;
                $edit->oldContent = $this->getContent( Revision::RAW );
 
-               // NOTE: B/C for hooks! don't use these fields!
-               $edit->newText = $edit->newContent
-                       ? ContentHandler::getContentText( $edit->newContent )
-                       : '';
-               $edit->oldText = $edit->oldContent
-                       ? ContentHandler::getContentText( $edit->oldContent )
-                       : '';
-               $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialFormat ) : '';
-
                if ( $edit->output ) {
                        $edit->output->setCacheTime( wfTimestampNow() );
                }
@@ -2277,7 +2271,9 @@ class WikiPage implements Page, IDBAccessObject {
                $edits = $options['changed'] ? 1 : 0;
                $total = $options['created'] ? 1 : 0;
 
-               DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, $edits, $good, $total ) );
+               DeferredUpdates::addUpdate( SiteStatsUpdate::factory(
+                       [ 'edits' => $edits, 'articles' => $good, 'total' => $total ]
+               ) );
                DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $content ) );
 
                // If this is another user's talk page, update newtalk.
@@ -2523,7 +2519,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $cascade = false;
 
                        if ( $limit['create'] != '' ) {
-                               $commentFields = CommentStore::newKey( 'pt_reason' )->insert( $dbw, $reason );
+                               $commentFields = CommentStore::getStore()->insert( $dbw, 'pt_reason', $reason );
                                $dbw->replace( 'protected_titles',
                                        [ [ 'pt_namespace', 'pt_title' ] ],
                                        [
@@ -2850,8 +2846,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $content = null;
                }
 
-               $revCommentStore = new CommentStore( 'rev_comment' );
-               $arCommentStore = new CommentStore( 'ar_comment' );
+               $commentStore = CommentStore::getStore();
 
                $revQuery = Revision::getQueryInfo();
                $bitfield = false;
@@ -2887,7 +2882,7 @@ class WikiPage implements Page, IDBAccessObject {
                $ipRevIds = [];
 
                foreach ( $res as $row ) {
-                       $comment = $revCommentStore->getComment( $row );
+                       $comment = $commentStore->getComment( 'rev_comment', $row );
                        $rowInsert = [
                                'ar_namespace'  => $namespace,
                                'ar_title'      => $dbKey,
@@ -2904,7 +2899,7 @@ class WikiPage implements Page, IDBAccessObject {
                                'ar_page_id'    => $id,
                                'ar_deleted'    => $suppress ? $bitfield : $row->rev_deleted,
                                'ar_sha1'       => $row->rev_sha1,
-                       ] + $arCommentStore->insert( $dbw, $comment );
+                       ] + $commentStore->insert( $dbw, 'ar_comment', $comment );
                        if ( $wgContentHandlerUseDB ) {
                                $rowInsert['ar_content_model'] = $row->rev_content_model;
                                $rowInsert['ar_content_format'] = $row->rev_content_format;
@@ -3025,7 +3020,9 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                // Update site status
-               DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$countable, -1 ) );
+               DeferredUpdates::addUpdate( SiteStatsUpdate::factory(
+                       [ 'edits' => 1, 'articles' => -$countable, 'pages' => -1 ]
+               ) );
 
                // Delete pagelinks, update secondary indexes, etc
                $updates = $this->getDeletionUpdates( $content );