Merge "Drop outdated "documentation reviewed" tags"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index d30f589..5527ace 100644 (file)
@@ -31,8 +31,6 @@ interface Page {
  *
  * Some fields are public only for backwards-compatibility. Use accessors.
  * In the past, this class was part of Article.php and everything was public.
- *
- * @internal documentation reviewed 15 Mar 2010
  */
 class WikiPage implements Page, IDBAccessObject {
        // Constants for $mDataLoadedFrom and related
@@ -1608,7 +1606,9 @@ class WikiPage implements Page, IDBAccessObject {
         * error will be returned. These two conditions are also possible with
         * auto-detection due to MediaWiki's performance-optimised locking strategy.
         *
-        * @param bool|int $baseRevId The revision ID this edit was based off, if any
+        * @param bool|int $baseRevId The revision ID this edit was based off, if any.
+        *   This is not the parent revision ID, rather the revision ID for older
+        *   content used as the source for a rollback, for example.
         * @param User $user The user doing the edit
         *
         * @throws MWException
@@ -1668,7 +1668,9 @@ class WikiPage implements Page, IDBAccessObject {
         * error will be returned. These two conditions are also possible with
         * auto-detection due to MediaWiki's performance-optimised locking strategy.
         *
-        * @param bool|int $baseRevId The revision ID this edit was based off, if any
+        * @param bool|int $baseRevId The revision ID this edit was based off, if any.
+        *   This is not the parent revision ID, rather the revision ID for older
+        *   content used as the source for a rollback, for example.
         * @param User $user The user doing the edit
         * @param string $serialFormat Format for storing the content in the
         *   database.
@@ -1802,7 +1804,7 @@ class WikiPage implements Page, IDBAccessObject {
                                $dbw->begin( __METHOD__ );
                                try {
 
-                                       $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+                                       $prepStatus = $content->prepareSave( $this, $flags, $oldid, $user );
                                        $status->merge( $prepStatus );
 
                                        if ( !$status->isOK() ) {
@@ -1881,7 +1883,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $dbw->begin( __METHOD__ );
                        try {
 
-                               $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+                               $prepStatus = $content->prepareSave( $this, $flags, $oldid, $user );
                                $status->merge( $prepStatus );
 
                                if ( !$status->isOK() ) {
@@ -3061,7 +3063,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                // Generate the edit summary if necessary
-               $target = Revision::newFromId( $s->rev_id );
+               $target = Revision::newFromId( $s->rev_id, Revision::READ_LATEST );
                if ( empty( $summary ) ) {
                        if ( $from == '' ) { // no public user name
                                $summary = wfMessage( 'revertpage-nouser' );
@@ -3378,70 +3380,37 @@ class WikiPage implements Page, IDBAccessObject {
        }
 
        /**
-        * Updates cascading protections
+        * Opportunistically enqueue link update jobs given fresh parser output if useful
         *
-        * @param ParserOutput $parserOutput ParserOutput object for the current version
+        * @param ParserOutput $parserOutput Current version page output
+        * @return bool Whether a job was pushed
+        * @since 1.25
         */
-       public function doCascadeProtectionUpdates( ParserOutput $parserOutput ) {
-               if ( wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
-                       return;
-               }
-
-               // templatelinks or imagelinks tables may have become out of sync,
-               // especially if using variable-based transclusions.
-               // For paranoia, check if things have changed and if
-               // so apply updates to the database. This will ensure
-               // that cascaded protections apply as soon as the changes
-               // are visible.
-
-               // Get templates from templatelinks and images from imagelinks
-               $id = $this->getId();
-
-               $dbLinks = array();
-
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( array( 'templatelinks' ),
-                       array( 'tl_namespace', 'tl_title' ),
-                       array( 'tl_from' => $id ),
-                       __METHOD__
-               );
-
-               foreach ( $res as $row ) {
-                       $dbLinks["{$row->tl_namespace}:{$row->tl_title}"] = true;
+       public function triggerOpportunisticLinksUpdate( ParserOutput $parserOutput ) {
+               if ( wfReadOnly() ) {
+                       return false;
                }
 
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( array( 'imagelinks' ),
-                       array( 'il_to' ),
-                       array( 'il_from' => $id ),
-                       __METHOD__
-               );
-
-               foreach ( $res as $row ) {
-                       $dbLinks[NS_FILE . ":{$row->il_to}"] = true;
+               if ( $this->mTitle->areRestrictionsCascading() ) {
+                       // If the page is cascade protecting, the links should really be up-to-date
+                       $params = array( 'prioritize' => true );
+               } elseif ( $parserOutput->hasDynamicContent() ) {
+                       // Assume the output contains time/random based magic words
+                       $params = array();
+               } else {
+                       // If the inclusions are deterministic, the edit-triggered link jobs are enough
+                       return false;
                }
 
-               // Get templates and images from parser output.
-               $poLinks = array();
-               foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
-                       foreach ( $templates as $dbk => $id ) {
-                               $poLinks["$ns:$dbk"] = true;
-                       }
-               }
-               foreach ( $parserOutput->getImages() as $dbk => $id ) {
-                       $poLinks[NS_FILE . ":$dbk"] = true;
+               // Check if the last link refresh was before page_touched
+               if ( $this->getLinksTimestamp() < $this->getTouched() ) {
+                       JobQueueGroup::singleton()->push( EnqueueJob::newFromLocalJobs(
+                               new JobSpecification( 'refreshLinks', $params, array(), $this->mTitle )
+                       ) );
+                       return true;
                }
 
-               // Get the diff
-               $links_diff = array_diff_key( $poLinks, $dbLinks );
-
-               if ( count( $links_diff ) > 0 ) {
-                       // Whee, link updates time.
-                       // Note: we are only interested in links here. We don't need to get
-                       // other DataUpdate items from the parser output.
-                       $u = new LinksUpdate( $this->mTitle, $parserOutput, false );
-                       $u->doUpdate();
-               }
+               return false;
        }
 
        /**