Merge "Do not use OutputPage to output exceptions in Installer"
[lhc/web/wiklou.git] / includes / Article.php
index c82b39f..a5d4d5b 100644 (file)
@@ -158,7 +158,7 @@ class Article implements Page {
                }
 
                $page = null;
-               wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
+               wfRunHooks( 'ArticleFromTitle', array( &$title, &$page, $context ) );
                if ( !$page ) {
                        switch ( $title->getNamespace() ) {
                                case NS_FILE:
@@ -460,14 +460,6 @@ class Article implements Page {
                return $this->mContentObject;
        }
 
-       /**
-        * No-op
-        * @deprecated since 1.18
-        */
-       public function forUpdate() {
-               wfDeprecated( __METHOD__, '1.18' );
-       }
-
        /**
         * Returns true if the currently-referenced revision is the current edit
         * to this page (and it exists).
@@ -684,26 +676,15 @@ class Article implements Page {
 
                                                # Allow extensions do their own custom view for certain pages
                                                $outputDone = true;
-                                       } else {
-                                               $content = $this->getContentObject();
-                                               $rt = $content ? $content->getRedirectChain() : null;
-                                               if ( $rt ) {
-                                                       wfDebug( __METHOD__ . ": showing redirect=no page\n" );
-                                                       # Viewing a redirect page (e.g. with parameter redirect=no)
-                                                       $outputPage->addHTML( $this->viewRedirect( $rt ) );
-                                                       # Parse just to get categories, displaytitle, etc.
-                                                       $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
-                                                       $outputPage->addParserOutputNoText( $this->mParserOutput );
-                                                       $outputDone = true;
-                                               }
                                        }
                                        break;
                                case 4:
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
 
+                                       $content = $this->getContentObject();
                                        $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
-                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
+                                               $this->getRevIdFetched(), $useParserCache, $content );
 
                                        if ( !$poolArticleView->execute() ) {
                                                $error = $poolArticleView->getError();
@@ -722,6 +703,9 @@ class Article implements Page {
 
                                        $this->mParserOutput = $poolArticleView->getParserOutput();
                                        $outputPage->addParserOutput( $this->mParserOutput );
+                                       if ( $content->getRedirectTarget() ) {
+                                               $outputPage->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
+                                       }
 
                                        # Don't cache a dirty ParserOutput object
                                        if ( $poolArticleView->getIsDirty() ) {
@@ -988,10 +972,9 @@ class Article implements Page {
                                $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
 
                                // Set the fragment if one was specified in the redirect
-                               if ( strval( $this->getTitle()->getFragment() ) != '' ) {
-                                       $outputPage->addInlineScript( Xml::encodeJsCall(
-                                               'redirectToFragment', array( $this->getTitle()->getFragmentForURL() )
-                                       ) );
+                               if ( $this->getTitle()->hasFragment() ) {
+                                       $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
+                                       $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
                                }
 
                                // Add a <link rel="canonical"> tag
@@ -1420,7 +1403,10 @@ class Article implements Page {
        }
 
        /**
-        * View redirect
+        * Return the HTML for the top of a redirect page
+        *
+        * Chances are you should just be using the ParserOutput from
+        * WikitextContent::getParserOutput instead of calling this for redirects.
         *
         * @param $target Title|Array of destination(s) to redirect
         * @param $appendSubtitle Boolean [optional]
@@ -1428,20 +1414,35 @@ class Article implements Page {
         * @return string containing HMTL with redirect link
         */
        public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
+               $lang = $this->getTitle()->getPageLanguage();
+               if ( $appendSubtitle ) {
+                       $out = $this->getContext()->getOutput();
+                       $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
+               }
+               return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
+       }
+
+       /**
+        * Return the HTML for the top of a redirect page
+        *
+        * Chances are you should just be using the ParserOutput from
+        * WikitextContent::getParserOutput instead of calling this for redirects.
+        *
+        * @since 1.23
+        * @param Language $lang
+        * @param Title|array $target destination(s) to redirect
+        * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
+        * @return string containing HMTL with redirect link
+        */
+       public static function getRedirectHeaderHtml( Language $lang, $target, $forceKnown = false ) {
                global $wgStylePath;
 
                if ( !is_array( $target ) ) {
                        $target = array( $target );
                }
 
-               $lang = $this->getTitle()->getPageLanguage();
                $imageDir = $lang->getDir();
 
-               if ( $appendSubtitle ) {
-                       $out = $this->getContext()->getOutput();
-                       $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
-               }
-
                // the loop prepends the arrow image before the link, so the first case needs to be outside
 
                /**
@@ -1611,7 +1612,8 @@ class Article implements Page {
                $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
                $outputPage->addBacklinkSubtitle( $this->getTitle() );
                $outputPage->setRobotPolicy( 'noindex,nofollow' );
-               if ( $this->getTitle()->getBacklinkCache()->hasLinks( 'pagelinks' ) ) {
+               $backlinkCache = $this->getTitle()->getBacklinkCache();
+               if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
                        $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
                                'deleting-backlinks-warning' );
                }
@@ -1889,15 +1891,6 @@ class Article implements Page {
                Action::factory( 'info', $this )->show();
        }
 
-       /**
-        * Mark this particular edit/page as patrolled
-        * @deprecated since 1.18
-        */
-       public function markpatrolled() {
-               wfDeprecated( __METHOD__, '1.18' );
-               Action::factory( 'markpatrolled', $this )->show();
-       }
-
        /**
         * Handle action=purge
         * @deprecated since 1.19
@@ -1925,72 +1918,6 @@ class Article implements Page {
                Action::factory( 'rollback', $this )->show();
        }
 
-       /**
-        * User-interface handler for the "watch" action.
-        * Requires Request to pass a token as of 1.18.
-        * @deprecated since 1.18
-        */
-       public function watch() {
-               wfDeprecated( __METHOD__, '1.18' );
-               Action::factory( 'watch', $this )->show();
-       }
-
-       /**
-        * Add this page to the current user's watchlist
-        *
-        * This is safe to be called multiple times
-        *
-        * @return bool true on successful watch operation
-        * @deprecated since 1.18
-        */
-       public function doWatch() {
-               wfDeprecated( __METHOD__, '1.18' );
-               return WatchAction::doWatch( $this->getTitle(), $this->getContext()->getUser() );
-       }
-
-       /**
-        * User interface handler for the "unwatch" action.
-        * Requires Request to pass a token as of 1.18.
-        * @deprecated since 1.18
-        */
-       public function unwatch() {
-               wfDeprecated( __METHOD__, '1.18' );
-               Action::factory( 'unwatch', $this )->show();
-       }
-
-       /**
-        * Stop watching a page
-        * @return bool true on successful unwatch
-        * @deprecated since 1.18
-        */
-       public function doUnwatch() {
-               wfDeprecated( __METHOD__, '1.18' );
-               return WatchAction::doUnwatch( $this->getTitle(), $this->getContext()->getUser() );
-       }
-
-       /**
-        * Output a redirect back to the article.
-        * This is typically used after an edit.
-        *
-        * @deprecated in 1.18; call OutputPage::redirect() directly
-        * @param $noRedir Boolean: add redirect=no
-        * @param string $sectionAnchor section to redirect to, including "#"
-        * @param string $extraQuery extra query params
-        */
-       public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
-               wfDeprecated( __METHOD__, '1.18' );
-               if ( $noRedir ) {
-                       $query = 'redirect=no';
-                       if ( $extraQuery ) {
-                               $query .= "&$extraQuery";
-                       }
-               } else {
-                       $query = $extraQuery;
-               }
-
-               $this->getContext()->getOutput()->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
-       }
-
        /**
         * Use PHP's magic __get handler to handle accessing of
         * raw WikiPage fields for backwards compatibility.