Merge "Convert JobRunner to PSR-3 logger"
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
index 428e7b2..e9e72be 100644 (file)
@@ -54,6 +54,7 @@ class ParserOutput extends CacheTime {
        private $mIndexPolicy = '';       # 'index' or 'noindex'?  Any other value will result in no change.
        private $mAccessedOptions = array(); # List of ParserOptions (stored in the keys)
        private $mSecondaryDataUpdates = array(); # List of DataUpdate, used to save info from the page somewhere else.
+       private $mCustomDataUpdateCount = 0; # Number of custom updaters in $mSecondaryDataUpdates.
        private $mExtensionData = array(); # extra data used by extensions
        private $mLimitReportData = array(); # Parser limit report data
        private $mParseStartTime = array(); # Timestamps for getTimeSinceStart()
@@ -73,7 +74,6 @@ class ParserOutput extends CacheTime {
        }
 
        public function getText() {
-               wfProfileIn( __METHOD__ );
                $text = $this->mText;
                if ( $this->mEditSectionTokens ) {
                        $text = preg_replace_callback(
@@ -111,7 +111,6 @@ class ParserOutput extends CacheTime {
                                $text
                        );
                }
-               wfProfileOut( __METHOD__ );
                return $text;
        }
 
@@ -490,9 +489,10 @@ class ParserOutput extends CacheTime {
         * Add a tracking category, getting the title from a system message,
         * or print a debug message if the title is invalid.
         *
-        * Please add any message that you use with this function to
-        * $wgTrackingCategories. That way they will be listed on
-        * Special:TrackingCategories.
+        * Any message used with this function should be registered so it will
+        * show up on Special:TrackingCategories. Core messages should be added
+        * to SpecialTrackingCategories::$coreTrackingCategories, and extensions
+        * should add to "TrackingCategories" in their extension.json.
         *
         * @param string $msg Message key
         * @param Title $title title of the page which is being tracked
@@ -682,12 +682,30 @@ class ParserOutput extends CacheTime {
         * from the page's content. This is triggered by calling getSecondaryDataUpdates()
         * and is used for forward links updates on edit and backlink updates by jobs.
         *
+        * @note: custom DataUpdates do not survive serialization of the ParserOutput!
+        * This is especially relevant when using a cached ParserOutput for updating
+        * the database, as WikiPage does if $wgAjaxStashEdit is enabled. For this
+        * reason, ApiStashEdit will skip any ParserOutput that has custom DataUpdates.
+        *
         * @since 1.20
         *
         * @param DataUpdate $update
         */
        public function addSecondaryDataUpdate( DataUpdate $update ) {
                $this->mSecondaryDataUpdates[] = $update;
+               $this->mCustomDataUpdateCount = count( $this->mSecondaryDataUpdates );
+       }
+
+       /**
+        * Whether this ParserOutput contains custom DataUpdate objects that may not survive
+        * serialization of the ParserOutput.
+        *
+        * @see __sleep()
+        *
+        * @return bool
+        */
+       public function hasCustomDataUpdates() {
+               return ( $this->mCustomDataUpdateCount > 0 );
        }
 
        /**
@@ -704,6 +722,9 @@ class ParserOutput extends CacheTime {
         *    be created based on $this->getTitleText()
         * @param bool $recursive Queue jobs for recursive updates?
         *
+        * @throws MWException if called on a ParserOutput instance that was restored from serialization.
+        *         DataUpdates are generally not serializable, so after serialization, they are undefined.
+        *
         * @return array An array of instances of DataUpdate
         */
        public function getSecondaryDataUpdates( Title $title = null, $recursive = true ) {
@@ -711,6 +732,15 @@ class ParserOutput extends CacheTime {
                        $title = Title::newFromText( $this->getTitleText() );
                }
 
+               if ( count( $this->mSecondaryDataUpdates ) !== $this->mCustomDataUpdateCount ) {
+                       // NOTE: This happens when mSecondaryDataUpdates are lost during serialization
+                       // (see __sleep below). After (un)serialization, getSecondaryDataUpdates()
+                       // has no defined behavior in that case, and should throw an exception.
+                       throw new MWException( 'getSecondaryDataUpdates() must not be called on ParserOutput restored from serialization.' );
+               }
+
+               // NOTE: ApiStashEdit knows about this "magic" update object. If this goes away,
+               // ApiStashEdit::buildStashValue needs to be adjusted.
                $linksUpdate = new LinksUpdate( $title, $this, $recursive );
 
                return array_merge( $this->mSecondaryDataUpdates, array( $linksUpdate ) );
@@ -861,7 +891,7 @@ class ParserOutput extends CacheTime {
        }
 
        /**
-        * Save space for for serialization by removing useless values
+        * Save space for serialization by removing useless values
         * @return array
         */
        public function __sleep() {