Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index ac9cd84..a7f53df 100644 (file)
@@ -21,8 +21,9 @@
  */
 
 use MediaWiki\Edit\PreparedEdit;
-use \MediaWiki\Logger\LoggerFactory;
-use \MediaWiki\MediaWikiServices;
+use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Assert\Assert;
 use Wikimedia\Rdbms\FakeResultWrapper;
 use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\DBError;
@@ -433,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
@@ -443,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.
@@ -671,7 +674,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $revision = Revision::newFromPageId( $this->getId(), $latest, $flags );
                } else {
                        $dbr = wfGetDB( DB_REPLICA );
-                       $revision = Revision::newKnownCurrent( $dbr, $this->getId(), $latest );
+                       $revision = Revision::newKnownCurrent( $dbr, $this->getTitle(), $latest );
                }
 
                if ( $revision ) { // sanity
@@ -1264,8 +1267,11 @@ class WikiPage implements Page, IDBAccessObject {
                        $conditions['page_latest'] = $lastRevision;
                }
 
+               $revId = $revision->getId();
+               Assert::parameter( $revId > 0, '$revision->getId()', 'must be > 0' );
+
                $row = [ /* SET */
-                       'page_latest'      => $revision->getId(),
+                       'page_latest'      => $revId,
                        'page_touched'     => $dbw->timestamp( $revision->getTimestamp() ),
                        'page_is_new'      => ( $lastRevision === 0 ) ? 1 : 0,
                        'page_is_redirect' => $rt !== null ? 1 : 0,
@@ -1421,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 ) {
@@ -1624,6 +1631,11 @@ class WikiPage implements Page, IDBAccessObject {
                        $tags[] = $tag;
                }
 
+               // Check for undo tag
+               if ( $undidRevId !== 0 && in_array( 'mw-undo', ChangeTags::getSoftwareTags() ) ) {
+                       $tags[] = 'mw-undo';
+               }
+
                // Provide autosummaries if summary is not provided and autosummaries are enabled
                if ( $wgUseAutomaticEditSummaries && ( $flags & EDIT_AUTOSUMMARY ) && $summary == '' ) {
                        $summary = $handler->getAutosummary( $old_content, $content, $flags );
@@ -2116,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() );
                }
@@ -3344,6 +3347,8 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public static function onArticleDelete( Title $title ) {
                // Update existence markers on article/talk tabs...
+               // Clear Backlink cache first so that purge jobs use more up-to-date backlink information
+               BacklinkCache::get( $title )->clear();
                $other = $title->getOtherPage();
 
                $other->purgeSquid();