From: Alex Monk Date: Sun, 7 Oct 2012 21:34:02 +0000 (+0100) Subject: Tidy up InfoAction and note it's hook in docs/hooks.txt X-Git-Tag: 1.31.0-rc.0~22065^2 X-Git-Url: http://git.cyclocoop.org/%24dirpuce/puce%24spip_lang_rtl.gif?a=commitdiff_plain;h=388df2ee2474b8d9e002bbad1055321c6d6ff7ac;p=lhc%2Fweb%2Fwiklou.git Tidy up InfoAction and note it's hook in docs/hooks.txt Also add $context parameter to the hook and (bug 40845) don't overwrite pageInfo's $title parameter. Change-Id: I41128abb72553142b45e90befabde541b2d8941f --- diff --git a/docs/hooks.txt b/docs/hooks.txt index a4b4e571f9..f156ed7bd8 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index a4b0cb7a29..b573b1addf 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -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',