Merge "ResourceLoaderFileModule: Do not separately cache .less files"
[lhc/web/wiklou.git] / includes / page / Article.php
index a189c2e..984b01d 100644 (file)
@@ -975,7 +975,14 @@ class Article implements Page {
                global $wgRedirectSources;
                $outputPage = $this->getContext()->getOutput();
 
-               $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
+               $request = $this->getContext()->getRequest();
+               $rdfrom = $request->getVal( 'rdfrom' );
+
+               // Construct a URL for the current page view, but with the target title
+               $query = $request->getValues();
+               unset( $query['rdfrom'] );
+               unset( $query['title'] );
+               $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
 
                if ( isset( $this->mRedirectedFrom ) ) {
                        // This is an internally redirected page view.
@@ -990,11 +997,12 @@ class Article implements Page {
 
                                $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
 
-                               // Set the fragment if one was specified in the redirect
-                               if ( $this->getTitle()->hasFragment() ) {
-                                       $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
-                                       $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
-                               }
+                               // Add the script to update the displayed URL and
+                               // set the fragment if one was specified in the redirect
+                               $outputPage->addJsConfigVars( array(
+                                       'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
+                               ) );
+                               $outputPage->addModules( 'mediawiki.action.view.redirect' );
 
                                // Add a <link rel="canonical"> tag
                                $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
@@ -1011,6 +1019,12 @@ class Article implements Page {
                                $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
                                $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
 
+                               // Add the script to update the displayed URL
+                               $outputPage->addJsConfigVars( array(
+                                       'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
+                               ) );
+                               $outputPage->addModules( 'mediawiki.action.view.redirect' );
+
                                return true;
                        }
                }
@@ -1551,9 +1565,9 @@ class Article implements Page {
                $user = $this->getContext()->getUser();
 
                # Check permissions
-               $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
-               if ( count( $permission_errors ) ) {
-                       throw new PermissionsError( 'delete', $permission_errors );
+               $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
+               if ( count( $permissionErrors ) ) {
+                       throw new PermissionsError( 'delete', $permissionErrors );
                }
 
                # Read-only check...
@@ -1624,7 +1638,20 @@ class Article implements Page {
 
                // If the page has a history, insert a warning
                if ( $hasHistory ) {
-                       $revisions = $this->mTitle->estimateRevisionCount();
+                       $title = $this->getTitle();
+
+                       // The following can use the real revision count as this is only being shown for users that can delete
+                       // this page.
+                       // This, as a side-effect, also makes sure that the following query isn't being run for pages with a
+                       // larger history, unless the user has the 'bigdelete' right (and is about to delete this page).
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $revisions = $edits = (int)$dbr->selectField(
+                               'revision',
+                               'COUNT(rev_page)',
+                               array( 'rev_page' => $title->getArticleID() ),
+                               __METHOD__
+                       );
+
                        // @todo FIXME: i18n issue/patchwork message
                        $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
                                wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
@@ -1635,7 +1662,7 @@ class Article implements Page {
                                '</strong>'
                        );
 
-                       if ( $this->mTitle->isBigDeletion() ) {
+                       if ( $title->isBigDeletion() ) {
                                global $wgDeleteRevisionsLimit;
                                $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
                                        array(
@@ -1657,11 +1684,12 @@ class Article implements Page {
        public function confirmDelete( $reason ) {
                wfDebug( "Article::confirmDelete\n" );
 
+               $title = $this->getTitle();
                $outputPage = $this->getContext()->getOutput();
-               $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
-               $outputPage->addBacklinkSubtitle( $this->getTitle() );
+               $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
+               $outputPage->addBacklinkSubtitle( $title );
                $outputPage->setRobotPolicy( 'noindex,nofollow' );
-               $backlinkCache = $this->getTitle()->getBacklinkCache();
+               $backlinkCache = $title->getBacklinkCache();
                if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
                        $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
                                'deleting-backlinks-warning' );
@@ -1683,10 +1711,10 @@ class Article implements Page {
                } else {
                        $suppress = '';
                }
-               $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $this->getTitle() );
+               $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $title );
 
                $form = Xml::openElement( 'form', array( 'method' => 'post',
-                       'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
+                       'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
                        Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
                        Xml::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
                        Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
@@ -1745,14 +1773,14 @@ class Article implements Page {
                        Xml::closeElement( 'fieldset' ) .
                        Html::hidden(
                                'wpEditToken',
-                               $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) )
+                               $user->getEditToken( array( 'delete', $title->getPrefixedText() ) )
                        ) .
                        Xml::closeElement( 'form' );
 
                        if ( $user->isAllowed( 'editinterface' ) ) {
-                               $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
+                               $dropdownTitle = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
                                $link = Linker::link(
-                                       $title,
+                                       $dropdownTitle,
                                        wfMessage( 'delete-edit-reasonlist' )->escaped(),
                                        array(),
                                        array( 'action' => 'edit' )
@@ -1764,9 +1792,7 @@ class Article implements Page {
 
                $deleteLogPage = new LogPage( 'delete' );
                $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
-               LogEventsList::showLogExtract( $outputPage, 'delete',
-                       $this->getTitle()
-               );
+               LogEventsList::showLogExtract( $outputPage, 'delete', $title );
        }
 
        /**