Tidy up InfoAction and note it's hook in docs/hooks.txt
authorAlex Monk <krenair@gmail.com>
Sun, 7 Oct 2012 21:34:02 +0000 (22:34 +0100)
committerAlex Monk <krenair@gmail.com>
Thu, 11 Oct 2012 00:41:43 +0000 (01:41 +0100)
Also add $context parameter to the hook and (bug 40845) don't
overwrite pageInfo's $title parameter.

Change-Id: I41128abb72553142b45e90befabde541b2d8941f

docs/hooks.txt
includes/actions/InfoAction.php

index a4b4e57..f156ed7 100644 (file)
@@ -1223,6 +1223,10 @@ $reader: XMLReader object
 $revisionInfo: Array of information
 Return false to stop further processing of the tag
 
+'InfoAction': When building information to display on the action=info page
+$context: IContextSource object
+&$pageInfo: Array of information
+
 'InitializeArticleMaybeRedirect': MediaWiki check to see if title is a redirect
 $title: Title object ($wgTitle)
 $request: WebRequest
index a4b0cb7..b573b1a 100644 (file)
@@ -75,7 +75,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 +149,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 +157,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 );
@@ -216,14 +215,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'] )
@@ -402,12 +401,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 +413,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 +424,7 @@ class InfoAction extends FormlessAction {
                        $result['views'] = $views;
                }
 
-               if ( $canViewUnwatched ) {
+               if ( $user->isAllowed( 'unwatchedpages' ) ) {
                        // Number of page watchers
                        $watchers = (int) $dbr->selectField(
                                'watchlist',