Merge "Move MediaHandler defaults out of global scope"
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index 0b1fd6a..33955b2 100644 (file)
  * @ingroup DifferenceEngine
  */
 
-/**
- * Constant to indicate diff cache compatibility.
- * Bump this when changing the diff formatting in a way that
- * fixes important bugs or such to force cached diff views to
- * clear.
- */
+// Deprecated, use class constant instead
 define( 'MW_DIFF_VERSION', '1.11a' );
 
 /**
@@ -34,6 +29,13 @@ define( 'MW_DIFF_VERSION', '1.11a' );
  * @ingroup DifferenceEngine
  */
 class DifferenceEngine extends ContextSource {
+       /**
+        * Constant to indicate diff cache compatibility.
+        * Bump this when changing the diff formatting in a way that
+        * fixes important bugs or such to force cached diff views to
+        * clear.
+        */
+       const DIFF_VERSION = MW_DIFF_VERSION;
 
        /** @var int */
        public $mOldid;
@@ -236,14 +238,12 @@ class DifferenceEngine extends ContextSource {
        }
 
        public function showDiffPage( $diffOnly = false ) {
+
                # Allow frames except in certain special cases
                $out = $this->getOutput();
                $out->allowClickjacking();
                $out->setRobotPolicy( 'noindex,nofollow' );
 
-               // Allow extensions to add any extra output here
-               Hooks::run( 'DifferenceEngineShowDiffPage', [ $out ] );
-
                if ( !$this->loadRevisionData() ) {
                        $this->showMissingRevision();
 
@@ -285,8 +285,6 @@ class DifferenceEngine extends ContextSource {
                        $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
                        $samePage = true;
                        $oldHeader = '';
-                       // Allow extensions to change the $oldHeader variable
-                       Hooks::run( 'DifferenceEngineOldHeaderNoOldRev', [ &$oldHeader ] );
                } else {
                        Hooks::run( 'DiffViewHeader', [ $this, $this->mOldRev, $this->mNewRev ] );
 
@@ -356,10 +354,6 @@ class DifferenceEngine extends ContextSource {
                                '<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
                                '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
 
-                       // Allow extensions to change the $oldHeader variable
-                       Hooks::run( 'DifferenceEngineOldHeader', [ $this, &$oldHeader, $prevlink, $oldminor,
-                               $diffOnly, $ldel, $this->unhide ] );
-
                        if ( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
                                $deleted = true; // old revisions text is hidden
                                if ( $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
@@ -421,10 +415,6 @@ class DifferenceEngine extends ContextSource {
                        '<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
                        '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
 
-               // Allow extensions to change the $newHeader variable
-               Hooks::run( 'DifferenceEngineNewHeader', [ $this, &$newHeader, $formattedRevisionTools,
-                       $nextlink, $rollback, $newminor, $diffOnly, $rdel, $this->unhide ] );
-
                if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $deleted = true; // new revisions text is hidden
                        if ( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
@@ -497,9 +487,6 @@ class DifferenceEngine extends ContextSource {
                                                        'token' => $linkInfo['token'],
                                                ]
                                        ) . ']</span>';
-                               // Allow extensions to change the markpatrolled link
-                               Hooks::run( 'DifferenceEngineMarkPatrolledLink', [ $this,
-                                       &$this->mMarkPatrolledLink, $linkInfo['rcid'], $linkInfo['token'] ] );
                        }
                }
                return $this->mMarkPatrolledLink;
@@ -543,13 +530,6 @@ class DifferenceEngine extends ContextSource {
                                // If the user could patrol this it already would be patrolled
                                $rcid = 0;
                        }
-
-                       // Allow extensions to possibly change the rcid here
-                       // For example the rcid might be set to zero due to the user
-                       // being the same as the performer of the change but an extension
-                       // might still want to show it under certain conditions
-                       Hooks::run( 'DifferenceEngineMarkPatrolledRCID', [ &$rcid, $this, $change, $user ] );
-
                        // Build the link
                        if ( $rcid ) {
                                $this->getOutput()->preventClickjacking();
@@ -637,20 +617,15 @@ class DifferenceEngine extends ContextSource {
 
                                # WikiPage::getParserOutput() should not return false, but just in case
                                if ( $parserOutput ) {
-                                       // Allow extensions to change parser output here
-                                       if ( Hooks::run( 'DifferenceEngineRenderRevisionAddParserOutput', [ $this, $out, $parserOutput, $wikiPage ] ) ) {
-                                               $out->addParserOutput( $parserOutput );
-                                       }
+                                       $out->addParserOutput( $parserOutput );
                                }
                        }
                }
                # @codingStandardsIgnoreEnd
 
-               // Allow extensions to optionally not show the final patrolled link
-               if ( Hooks::run( 'DifferenceEngineRenderRevisionShowFinalPatrolLink' ) ) {
-                       # Add redundant patrol link on bottom...
-                       $out->addHTML( $this->markPatrolledLink() );
-               }
+               # Add redundant patrol link on bottom...
+               $out->addHTML( $this->markPatrolledLink() );
+
        }
 
        protected function getParserOutput( WikiPage $page, Revision $rev ) {
@@ -676,9 +651,6 @@ class DifferenceEngine extends ContextSource {
         * @return bool
         */
        public function showDiff( $otitle, $ntitle, $notice = '' ) {
-               // Allow extensions to affect the output here
-               Hooks::run( 'DifferenceEngineShowDiff', [ $this ] );
-
                $diff = $this->getDiff( $otitle, $ntitle, $notice );
                if ( $diff === false ) {
                        $this->showMissingRevision();
@@ -748,9 +720,7 @@ class DifferenceEngine extends ContextSource {
                if ( $this->mOldRev === false || ( $this->mOldRev && $this->mNewRev
                        && $this->mOldRev->getId() == $this->mNewRev->getId() )
                ) {
-                       if ( !Hooks::run( 'DifferenceEngineShowEmptyOldContent', [ $this ] ) ) {
-                               return '';
-                       }
+                       return '';
                }
                // Cacheable?
                $key = false;
@@ -809,7 +779,7 @@ class DifferenceEngine extends ContextSource {
                        throw new MWException( 'mOldid and mNewid must be set to get diff cache key.' );
                }
 
-               return wfMemcKey( 'diff', 'version', MW_DIFF_VERSION,
+               return wfMemcKey( 'diff', 'version', self::DIFF_VERSION,
                        'oldid', $this->mOldid, 'newid', $this->mNewid );
        }
 
@@ -849,21 +819,6 @@ class DifferenceEngine extends ContextSource {
                return $this->generateTextDiffBody( $otext, $ntext );
        }
 
-       /**
-        * Generate a diff, no caching
-        *
-        * @param string $otext Old text, must be already segmented
-        * @param string $ntext New text, must be already segmented
-        *
-        * @return bool|string
-        * @deprecated since 1.21, use generateContentDiffBody() instead!
-        */
-       public function generateDiffBody( $otext, $ntext ) {
-               ContentHandler::deprecated( __METHOD__, "1.21" );
-
-               return $this->generateTextDiffBody( $otext, $ntext );
-       }
-
        /**
         * Generate a diff, no caching
         *
@@ -926,7 +881,7 @@ class DifferenceEngine extends ContextSource {
                } elseif ( $wgExternalDiffEngine == 'wikidiff2' ) {
                        // Same as above, but with no deprecation warnings
                        $wgExternalDiffEngine = false;
-               } elseif ( !is_string( $wgExternalDiffEngine ) ) {
+               } elseif ( !is_string( $wgExternalDiffEngine ) && $wgExternalDiffEngine !== false ) {
                        // And prevent people from shooting themselves in the foot...
                        wfWarn( '$wgExternalDiffEngine is set to a non-string value, forcing it to false' );
                        $wgExternalDiffEngine = false;