miscellaneous doxygen warnings
[lhc/web/wiklou.git] / includes / actions / InfoAction.php
index a4b0cb7..e986323 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();
@@ -75,7 +91,7 @@ class InfoAction extends FormlessAction {
                $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 ) {
@@ -149,7 +165,7 @@ class InfoAction extends FormlessAction {
         * @return array
         */
        protected function pageInfo() {
-               global $wgContLang, $wgDisableCounters, $wgRCMaxAge;
+               global $wgContLang, $wgRCMaxAge;
 
                $user = $this->getUser();
                $lang = $this->getLanguage();
@@ -157,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 );
@@ -188,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'] ) ) {
@@ -216,14 +246,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'] )
@@ -243,6 +273,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() . '/' );
@@ -259,6 +297,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 ) );
@@ -282,6 +344,10 @@ class InfoAction extends FormlessAction {
                        );
                }
 
+               if ( !$this->page->exists() ) {
+                       return $pageInfo;
+               }
+
                // Edit history
                $pageInfo['header-edits'] = array();
 
@@ -402,12 +468,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();
@@ -415,7 +480,7 @@ class InfoAction extends FormlessAction {
                $dbr = wfGetDB( DB_SLAVE );
                $result = array();
 
-               if ( !$disableCounter ) {
+               if ( !$wgDisableCounters ) {
                        // Number of views
                        $views = (int) $dbr->selectField(
                                'page',
@@ -426,7 +491,7 @@ class InfoAction extends FormlessAction {
                        $result['views'] = $views;
                }
 
-               if ( $canViewUnwatched ) {
+               if ( $user->isAllowed( 'unwatchedpages' ) ) {
                        // Number of page watchers
                        $watchers = (int) $dbr->selectField(
                                'watchlist',
@@ -517,7 +582,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
         */
@@ -588,7 +653,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
         */