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
This commit is contained in:
Alex Monk 2012-10-07 22:34:02 +01:00
parent 5ece17a46d
commit 388df2ee24
2 changed files with 14 additions and 12 deletions

View 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

View 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',