Merge "(Bug 41352) Provide tests for edit conflicts."
[lhc/web/wiklou.git] / includes / actions / InfoAction.php
index e09cd20..29c3d7e 100644 (file)
@@ -58,6 +58,22 @@ class InfoAction extends FormlessAction {
        public function onView() {
                $content = '';
 
+               // Validate revision
+               $oldid = $this->page->getOldID();
+               if ( $oldid ) {
+                       $revision = $this->page->getRevisionFetched();
+
+                       // Revision is missing
+                       if ( $revision === null ) {
+                               return $this->msg( 'missing-revision', $oldid )->parse();
+                       }
+
+                       // Revision is not current
+                       if ( !$revision->isCurrent() ) {
+                               return $this->msg( 'pageinfo-not-current' )->plain();
+                       }
+               }
+
                // Page header
                if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
                        $content .= $this->msg( 'pageinfo-header' )->parse();
@@ -72,11 +88,10 @@ class InfoAction extends FormlessAction {
                        '.mw-templatesUsedExplanation { display: none; }' );
 
                // Get page information
-               $title = $this->getTitle();
-               $pageInfo = $this->pageInfo( $title );
+               $pageInfo = $this->pageInfo();
 
                // Allow extensions to add additional information
-               wfRunHooks( 'InfoAction', array( &$pageInfo ) );
+               wfRunHooks( 'InfoAction', array( $this->getContext(), &$pageInfo ) );
 
                // Render page information
                foreach ( $pageInfo as $header => $infoTable ) {
@@ -96,7 +111,7 @@ class InfoAction extends FormlessAction {
                }
 
                // Page credits
-               /*if ( $title->exists() ) {
+               /*if ( $this->page->exists() ) {
                        $content .= Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $this->getContributors() );
                }*/
 
@@ -147,10 +162,10 @@ class InfoAction extends FormlessAction {
         * may add additional information in arbitrary positions. Array values are arrays with one
         * element to be rendered as a header, arrays with two elements to be rendered as a table row.
         *
-        * @param $title Title object
+        * @return array
         */
-       protected function pageInfo( $title ) {
-               global $wgContLang, $wgDisableCounters, $wgRCMaxAge;
+       protected function pageInfo() {
+               global $wgContLang, $wgRCMaxAge;
 
                $user = $this->getUser();
                $lang = $this->getLanguage();
@@ -158,8 +173,7 @@ class InfoAction extends FormlessAction {
                $id = $title->getArticleID();
 
                // Get page information that would be too "expensive" to retrieve by normal means
-               $userCanViewUnwatchedPages = $user->isAllowed( 'unwatchedpages' );
-               $pageCounts = self::pageCounts( $title, $userCanViewUnwatchedPages, $wgDisableCounters );
+               $pageCounts = self::pageCounts( $title, $user );
 
                // Get page properties
                $dbr = wfGetDB( DB_SLAVE );
@@ -189,6 +203,21 @@ class InfoAction extends FormlessAction {
                        $this->msg( 'pageinfo-display-title' ), $displayTitle
                );
 
+               // Is it a redirect? If so, where to?
+               if ( $title->isRedirect() ) {
+                       $pageInfo['header-basic'][] = array(
+                               $this->msg( 'pageinfo-redirectsto' ),
+                               Linker::link( $this->page->getRedirectTarget() ) .
+                               $this->msg( 'word-separator' )->text() .
+                               $this->msg( 'parentheses', Linker::link(
+                                       $this->page->getRedirectTarget(),
+                                       $this->msg( 'pageinfo-redirectsto-info' )->escaped(),
+                                       array(),
+                                       array( 'action' => 'info' )
+                               ) )->text()
+                       );
+               }
+
                // Default sort key
                $sortKey = $title->getCategorySortKey();
                if ( !empty( $pageProperties['defaultsort'] ) ) {
@@ -205,6 +234,12 @@ class InfoAction extends FormlessAction {
                // Page ID (number not localised, as it's a database ID)
                $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-article-id' ), $id );
 
+               // Language in which the page content is (supposed to be) written
+               $pageLang = $title->getPageLanguage()->getCode();
+               $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-language' ),
+                       Language::fetchLanguageName( $pageLang, $lang->getCode() )
+                       . ' ' . $this->msg( 'parentheses', $pageLang ) );
+
                // Search engine status
                $pOutput = new ParserOutput();
                if ( isset( $pageProperties['noindex'] ) ) {
@@ -217,14 +252,14 @@ class InfoAction extends FormlessAction {
                        $this->msg( 'pageinfo-robot-policy' ), $this->msg( "pageinfo-robot-${policy['index']}" )
                );
 
-               if ( !$wgDisableCounters ) {
+               if ( isset( $pageCounts['views'] ) ) {
                        // Number of views
                        $pageInfo['header-basic'][] = array(
                                $this->msg( 'pageinfo-views' ), $lang->formatNum( $pageCounts['views'] )
                        );
                }
 
-               if ( $userCanViewUnwatchedPages ) {
+               if ( isset( $pageCounts['watchers'] ) ) {
                        // Number of page watchers
                        $pageInfo['header-basic'][] = array(
                                $this->msg( 'pageinfo-watchers' ), $lang->formatNum( $pageCounts['watchers'] )
@@ -244,6 +279,14 @@ class InfoAction extends FormlessAction {
                                ->numParams( count( $title->getRedirectsHere() ) )
                );
 
+               // Is it counted as a content page?
+               if ( $this->page->isCountable() ) {
+                       $pageInfo['header-basic'][] = array(
+                               $this->msg( 'pageinfo-contentpage' ),
+                               $this->msg( 'pageinfo-contentpage-yes' )
+                       );
+               }
+
                // Subpages of this page, if subpages are enabled for the current NS
                if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
                        $prefixIndex = SpecialPage::getTitleFor( 'Prefixindex', $title->getPrefixedText() . '/' );
@@ -260,6 +303,30 @@ class InfoAction extends FormlessAction {
                // Page protection
                $pageInfo['header-restrictions'] = array();
 
+               // Is this page effected by the cascading protection of something which includes it?
+               if ( $title->isCascadeProtected() ) {
+                       $cascadingFrom = '';
+                       $sources = $title->getCascadeProtectionSources(); // Array deferencing is in PHP 5.4 :(
+
+                       foreach ( $sources[0] as $sourceTitle ) {
+                               $cascadingFrom .= Html::rawElement( 'li', array(), Linker::linkKnown( $sourceTitle ) );
+                       }
+
+                       $cascadingFrom = Html::rawElement( 'ul', array(), $cascadingFrom );
+                       $pageInfo['header-restrictions'][] = array(
+                               $this->msg( 'pageinfo-protect-cascading-from' ),
+                               $cascadingFrom
+                       );
+               }
+
+               // Is out protection set to cascade to other pages?
+               if ( $title->areRestrictionsCascading() ) {
+                       $pageInfo['header-restrictions'][] = array(
+                               $this->msg( 'pageinfo-protect-cascading' ),
+                               $this->msg( 'pageinfo-protect-cascading-yes' )
+                       );
+               }
+
                // Page protection
                foreach ( $title->getRestrictionTypes() as $restrictionType ) {
                        $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
@@ -283,6 +350,10 @@ class InfoAction extends FormlessAction {
                        );
                }
 
+               if ( !$this->page->exists() ) {
+                       return $pageInfo;
+               }
+
                // Edit history
                $pageInfo['header-edits'] = array();
 
@@ -403,12 +474,11 @@ class InfoAction extends FormlessAction {
         * Returns page counts that would be too "expensive" to retrieve by normal means.
         *
         * @param $title Title object
-        * @param $canViewUnwatched bool
-        * @param $disableCounter bool
+        * @param $user User object
         * @return array
         */
-       protected static function pageCounts( $title, $canViewUnwatched, $disableCounter ) {
-               global $wgRCMaxAge;
+       protected static function pageCounts( $title, $user ) {
+               global $wgRCMaxAge, $wgDisableCounters;
 
                wfProfileIn( __METHOD__ );
                $id = $title->getArticleID();
@@ -416,7 +486,7 @@ class InfoAction extends FormlessAction {
                $dbr = wfGetDB( DB_SLAVE );
                $result = array();
 
-               if ( !$disableCounter ) {
+               if ( !$wgDisableCounters ) {
                        // Number of views
                        $views = (int) $dbr->selectField(
                                'page',
@@ -427,7 +497,7 @@ class InfoAction extends FormlessAction {
                        $result['views'] = $views;
                }
 
-               if ( $canViewUnwatched ) {
+               if ( $user->isAllowed( 'unwatchedpages' ) ) {
                        // Number of page watchers
                        $watchers = (int) $dbr->selectField(
                                'watchlist',
@@ -518,7 +588,7 @@ class InfoAction extends FormlessAction {
        }
 
        /**
-        * Returns the name that goes in the <h1> page title.
+        * Returns the name that goes in the "<h1>" page title.
         *
         * @return string
         */
@@ -589,7 +659,7 @@ class InfoAction extends FormlessAction {
        }
 
        /**
-        * Returns the description that goes below the <h1> tag.
+        * Returns the description that goes below the "<h1>" tag.
         *
         * @return string
         */