Drop ancient PHP4 wrapper for cloning, completely unused
[lhc/web/wiklou.git] / includes / DoubleRedirectJob.php
index 41f5a2e..0857408 100644 (file)
@@ -1,13 +1,19 @@
 <?php
 
+/**
+ * Job to fix double redirects after moving a page
+ *
+ * @ingroup JobQueue
+ */
 class DoubleRedirectJob extends Job {
        var $reason, $redirTitle, $destTitleText;
        static $user;
 
        /** 
         * Insert jobs into the job queue to fix redirects to the given title
-        * @param string $type The reason for the fix, see message double-redirect-fixed-<reason>
-        * @param Title $redirTitle The title which has changed, redirects pointing to this title are fixed
+        * @param $reason String: the reason for the fix, see message double-redirect-fixed-<reason>
+        * @param $redirTitle Title: the title which has changed, redirects pointing to this title are fixed
+        * @param $destTitle Not used
         */
        public static function fixRedirects( $reason, $redirTitle, $destTitle = false ) {
                # Need to use the master to get the redirect table updated in the same transaction
@@ -66,6 +72,13 @@ class DoubleRedirectJob extends Job {
                        return true;
                }
 
+               # Check for a suppression tag (used e.g. in periodically archived discussions)
+               $mw = MagicWord::get( 'staticredirect' );
+               if ( $mw->match( $text ) ) {
+                       wfDebug( __METHOD__.": skipping: suppressed with __STATICREDIRECT__\n" );
+                       return true;
+               }
+
                # Find the current final destination
                $newTitle = self::getFinalDestination( $this->redirTitle );
                if ( !$newTitle ) {
@@ -78,11 +91,15 @@ class DoubleRedirectJob extends Job {
                        wfDebug( __METHOD__.": skipping, already good\n" );
                }
 
+               # Preserve fragment (bug 14904)
+               $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), 
+                       $currentDest->getFragment() );
+
                # Fix the text
                # Remember that redirect pages can have categories, templates, etc.,
                # so the regex has to be fairly general
                $newText = preg_replace( '/ \[ \[  [^\]]*  \] \] /x', 
-                       '[[' . $newTitle->getPrefixedText() . ']]',
+                       '[[' . $newTitle->getFullText() . ']]',
                        $text, 1 );
 
                if ( $newText === $text ) {
@@ -105,7 +122,7 @@ class DoubleRedirectJob extends Job {
 
        /**
         * Get the final destination of a redirect
-        * Returns false if the specified title is not a redirect, or if it is a circular redirect
+        * @return false if the specified title is not a redirect, or if it is a circular redirect
         */
        public static function getFinalDestination( $title ) {
                $dbw = wfGetDB( DB_MASTER );