Merge "Improve logging of exceptions which are not thrown but attached to context"
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index 1537535..5367199 100644 (file)
@@ -21,7 +21,7 @@
  * @ingroup DifferenceEngine
  */
 
-// Deprecated, use class constant instead
+/** @deprecated use class constant instead */
 define( 'MW_DIFF_VERSION', '1.11a' );
 
 /**
@@ -176,7 +176,7 @@ class DifferenceEngine extends ContextSource {
         *
         * @param int $id Revision ID
         *
-        * @return mixed URL or false
+        * @return string|bool Link HTML or false
         */
        public function deletedLink( $id ) {
                if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
@@ -210,7 +210,7 @@ class DifferenceEngine extends ContextSource {
                if ( $link ) {
                        return "[$link $id]";
                } else {
-                       return $id;
+                       return (string)$id;
                }
        }
 
@@ -247,8 +247,9 @@ class DifferenceEngine extends ContextSource {
                Hooks::run( 'DifferenceEngineShowDiffPage', [ $out ] );
 
                if ( !$this->loadRevisionData() ) {
-                       $this->showMissingRevision();
-
+                       if ( Hooks::run( 'DifferenceEngineShowDiffPageMaybeShowMissingRevision', [ $this ] ) ) {
+                               $this->showMissingRevision();
+                       }
                        return;
                }
 
@@ -481,7 +482,7 @@ class DifferenceEngine extends ContextSource {
         *
         * @return string HTML or empty string
         */
-       protected function markPatrolledLink() {
+       public function markPatrolledLink() {
                if ( $this->mMarkPatrolledLink === null ) {
                        $linkInfo = $this->getMarkPatrolledLinkInfo();
                        // If false, there is no patrol link needed/allowed
@@ -496,12 +497,11 @@ class DifferenceEngine extends ContextSource {
                                                [
                                                        'action' => 'markpatrolled',
                                                        'rcid' => $linkInfo['rcid'],
-                                                       'token' => $linkInfo['token'],
                                                ]
                                        ) . ']</span>';
                                // Allow extensions to change the markpatrolled link
                                Hooks::run( 'DifferenceEngineMarkPatrolledLink', [ $this,
-                                       &$this->mMarkPatrolledLink, $linkInfo['rcid'], $linkInfo['token'] ] );
+                                       &$this->mMarkPatrolledLink, $linkInfo['rcid'] ] );
                        }
                }
                return $this->mMarkPatrolledLink;
@@ -511,7 +511,7 @@ class DifferenceEngine extends ContextSource {
         * Returns an array of meta data needed to build a "mark as patrolled" link and
         * adds the mediawiki.page.patrol.ajax to the output.
         *
-        * @return array|false An array of meta data for a patrol link (rcid & token)
+        * @return array|false An array of meta data for a patrol link (rcid only)
         *  or false if no link is needed
         */
        protected function getMarkPatrolledLinkInfo() {
@@ -561,10 +561,8 @@ class DifferenceEngine extends ContextSource {
                                        $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' );
                                }
 
-                               $token = $user->getEditToken( $rcid );
                                return [
                                        'rcid' => $rcid,
-                                       'token' => $token,
                                ];
                        }
                }
@@ -604,24 +602,7 @@ class DifferenceEngine extends ContextSource {
                        $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
                        $out->setArticleFlag( true );
 
-                       // NOTE: only needed for B/C: custom rendering of JS/CSS via hook
-                       if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) {
-                               // This needs to be synchronised with Article::showCssOrJsPage(), which sucks
-                               // Give hooks a chance to customise the output
-                               // @todo standardize this crap into one function
-                               if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
-                                       // NOTE: deprecated hook, B/C only
-                                       // use the content object's own rendering
-                                       $cnt = $this->mNewRev->getContent();
-                                       $po = $cnt ? $cnt->getParserOutput( $this->mNewRev->getTitle(), $this->mNewRev->getId() ) : null;
-                                       if ( $po ) {
-                                               $out->addParserOutputContent( $po );
-                                       }
-                               }
-                       } elseif ( !Hooks::run( 'ArticleContentViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
-                               // Handled by extension
-                       } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
-                               // NOTE: deprecated hook, B/C only
+                       if ( !Hooks::run( 'ArticleContentViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
                                // Handled by extension
                        } else {
                                // Normal page
@@ -781,8 +762,11 @@ class DifferenceEngine extends ContextSource {
 
                $difftext = $this->generateContentDiffBody( $this->mOldContent, $this->mNewContent );
 
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $diffEngine = $this;
+
                // Save to cache for 7 days
-               if ( !Hooks::run( 'AbortDiffCache', [ &$this ] ) ) {
+               if ( !Hooks::run( 'AbortDiffCache', [ &$diffEngine ] ) ) {
                        wfIncrStats( 'diff_cache.uncacheable' );
                } elseif ( $key !== false && $difftext !== false ) {
                        wfIncrStats( 'diff_cache.miss' );
@@ -878,6 +862,10 @@ class DifferenceEngine extends ContextSource {
                        return $result;
                };
 
+               /**
+                * @param Status $status
+                * @throws FatalError
+                */
                $error = function( $status ) {
                        throw new FatalError( $status->getWikiText() );
                };
@@ -997,7 +985,7 @@ class DifferenceEngine extends ContextSource {
        public function localiseLineNumbers( $text ) {
                return preg_replace_callback(
                        '/<!--LINE (\d+)-->/',
-                       [ &$this, 'localiseLineNumbersCb' ],
+                       [ $this, 'localiseLineNumbersCb' ],
                        $text
                );
        }
@@ -1080,7 +1068,7 @@ class DifferenceEngine extends ContextSource {
         *
         * @return string HTML fragment
         */
-       protected function getRevisionHeader( Revision $rev, $complete = '' ) {
+       public function getRevisionHeader( Revision $rev, $complete = '' ) {
                $lang = $this->getLanguage();
                $user = $this->getUser();
                $revtimestamp = $rev->getTimestamp();
@@ -1385,6 +1373,7 @@ class DifferenceEngine extends ContextSource {
 
                if ( $this->mNewRev ) {
                        $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+                       Hooks::run( 'DifferenceEngineLoadTextAfterNewContentIsLoaded', [ $this ] );
                        if ( $this->mNewContent === null ) {
                                return false;
                        }
@@ -1411,6 +1400,8 @@ class DifferenceEngine extends ContextSource {
 
                $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
 
+               Hooks::run( 'DifferenceEngineAfterLoadNewText', [ $this ] );
+
                return true;
        }