Merge "Add line breaks to the output of Special:Watchlist"
[lhc/web/wiklou.git] / includes / specials / SpecialMergeHistory.php
index 1f05749..85e1d65 100644 (file)
@@ -373,26 +373,33 @@ class SpecialMergeHistory extends SpecialPage {
                                        $destTitle->getPrefixedText()
                                )->inContentLanguage()->text();
                        }
-                       $mwRedir = MagicWord::get( 'redirect' );
-                       $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $destTitle->getPrefixedText() . "]]\n";
-                       $redirectPage = WikiPage::factory( $targetTitle );
-                       $redirectRevision = new Revision( array(
-                               'page'    => $this->mTargetID,
-                               'comment' => $comment,
-                               'text'    => $redirectText ) );
-                       $redirectRevision->insertOn( $dbw );
-                       $redirectPage->updateRevisionOn( $dbw, $redirectRevision );
-
-                       # Now, we record the link from the redirect to the new title.
-                       # It should have no other outgoing links...
-                       $dbw->delete( 'pagelinks', array( 'pl_from' => $this->mDestID ), __METHOD__ );
-                       $dbw->insert( 'pagelinks',
-                               array(
-                                       'pl_from'      => $this->mDestID,
-                                       'pl_namespace' => $destTitle->getNamespace(),
-                                       'pl_title'     => $destTitle->getDBkey() ),
-                               __METHOD__
-                       );
+
+                       $contentHandler = ContentHandler::getForTitle( $targetTitle );
+                       $redirectContent = $contentHandler->makeRedirectContent( $destTitle );
+
+                       if ( $redirectContent ) {
+                               $redirectPage = WikiPage::factory( $targetTitle );
+                               $redirectRevision = new Revision( array(
+                                       'title'   => $targetTitle,
+                                       'page'    => $this->mTargetID,
+                                       'comment' => $comment,
+                                       'content' => $redirectContent ) );
+                               $redirectRevision->insertOn( $dbw );
+                               $redirectPage->updateRevisionOn( $dbw, $redirectRevision );
+
+                               # Now, we record the link from the redirect to the new title.
+                               # It should have no other outgoing links...
+                               $dbw->delete( 'pagelinks', array( 'pl_from' => $this->mDestID ), __METHOD__ );
+                               $dbw->insert( 'pagelinks',
+                                       array(
+                                               'pl_from'      => $this->mDestID,
+                                               'pl_namespace' => $destTitle->getNamespace(),
+                                               'pl_title'     => $destTitle->getDBkey() ),
+                                       __METHOD__
+                               );
+                       } else {
+                               // would be nice to show a warning if we couldn't create a redirect
+                       }
                } else {
                        $targetTitle->invalidateCache(); // update histories
                }