From: Reedy Date: Tue, 17 Jul 2012 21:53:17 +0000 (+0100) Subject: Cleanup InfoAction X-Git-Tag: 1.31.0-rc.0~22927^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=2ee4653;p=lhc%2Fweb%2Fwiklou.git Cleanup InfoAction Only do unwatched query if needed Fixup layout of onView PS2: Removed description, not i18n-ified. Duhhh Change-Id: Ia74ac3991433ef056c8bc09fa735c5bfd4579fa1 --- diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index 89e2cfeede..ea4425471c 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -50,53 +50,59 @@ class InfoAction extends FormlessAction { $title = $this->getTitle()->getSubjectPage(); - $pageInfo = self::pageCountInfo( $title ); - $talkInfo = self::pageCountInfo( $title->getTalkPage() ); + $userCanViewUnwatchedPages = $this->getUser()->isAllowed( 'unwatchedpages' ); - return Html::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ), + $pageInfo = self::pageCountInfo( $title, $userCanViewUnwatchedPages, $wgDisableCounters ); + $talkInfo = self::pageCountInfo( $title->getTalkPage(), $userCanViewUnwatchedPages, $wgDisableCounters ); + + $lang = $this->getLanguage(); + + $content = Html::rawElement( 'tr', array(), Html::element( 'th', array(), '' ) . - Html::element( 'th', array(), $this->msg( 'pageinfo-subjectpage' )->text() ) . - Html::element( 'th', array(), $this->msg( 'pageinfo-talkpage' )->text() ) + Html::element( 'th', array(), $this->msg( 'pageinfo-subjectpage' )->text() ) . + Html::element( 'th', array(), $this->msg( 'pageinfo-talkpage' )->text() ) ) . Html::rawElement( 'tr', array(), Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-edits' )->text() ) ) . Html::rawElement( 'tr', array(), Html::element( 'td', array(), $this->msg( 'pageinfo-edits' )->text() ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['edits'] ) ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['edits'] ) ) + Html::element( 'td', array(), $lang->formatNum( $pageInfo['edits'] ) ) . + Html::element( 'td', array(), $lang->formatNum( $talkInfo['edits'] ) ) ) . Html::rawElement( 'tr', array(), Html::element( 'td', array(), $this->msg( 'pageinfo-authors' )->text() ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['authors'] ) ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['authors'] ) ) + Html::element( 'td', array(), $lang->formatNum( $pageInfo['authors'] ) ) . + Html::element( 'td', array(), $lang->formatNum( $talkInfo['authors'] ) ) + ); + + if ( $userCanViewUnwatchedPages ) { + $content .= Html::rawElement( 'tr', array(), + Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-watchlist' )->text() ) ) . - ( !$this->getUser()->isAllowed( 'unwatchedpages' ) ? '' : - Html::rawElement( 'tr', array(), - Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-watchlist' )->text() ) - ) . Html::rawElement( 'tr', array(), Html::element( 'td', array(), $this->msg( 'pageinfo-watchers' )->text() ) . - Html::element( 'td', array( 'colspan' => 2 ), $this->getLanguage()->formatNum( $pageInfo['watchers'] ) ) - ) - ). - ( $wgDisableCounters ? '' : - Html::rawElement( 'tr', array(), - Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-views' )->text() ) - ) . + Html::element( 'td', array( 'colspan' => 2 ), $lang->formatNum( $pageInfo['watchers'] ) ) + ); + } + + if ( $wgDisableCounters ) { + $content .= Html::rawElement( 'tr', array(), + Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-views' )->text() ) + ) . Html::rawElement( 'tr', array(), Html::element( 'td', array(), $this->msg( 'pageinfo-views' )->text() ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['views'] ) ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['views'] ) ) + Html::element( 'td', array(), $lang->formatNum( $pageInfo['views'] ) ) . + Html::element( 'td', array(), $lang->formatNum( $talkInfo['views'] ) ) ) . Html::rawElement( 'tr', array(), Html::element( 'td', array(), $this->msg( 'pageinfo-viewsperedit' )->text() ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( sprintf( '%.2f', $pageInfo['edits'] ? $pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) . - Html::element( 'td', array(), $this->getLanguage()->formatNum( sprintf( '%.2f', $talkInfo['edits'] ? $talkInfo['views'] / $talkInfo['edits'] : 0 ) ) ) - ) - ) - ); + Html::element( 'td', array(), $lang->formatNum( sprintf( '%.2f', $pageInfo['edits'] ? $pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) . + Html::element( 'td', array(), $lang->formatNum( sprintf( '%.2f', $talkInfo['edits'] ? $talkInfo['views'] / $talkInfo['edits'] : 0 ) ) ) + ); + } + return Html::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ), $content ); } /** @@ -104,22 +110,28 @@ class InfoAction extends FormlessAction { * on a given page. If page does not exist, returns false. * * @param $title Title object - * @return mixed array or boolean false + * @param $canViewUnwatched bool + * @param $disableCounter bool + * @return array */ - public static function pageCountInfo( $title ) { + public static function pageCountInfo( $title, $canViewUnwatched, $disableCounter ) { wfProfileIn( __METHOD__ ); $id = $title->getArticleID(); $dbr = wfGetDB( DB_SLAVE ); - $watchers = (int)$dbr->selectField( - 'watchlist', - 'COUNT(*)', - array( - 'wl_namespace' => $title->getNamespace(), - 'wl_title' => $title->getDBkey(), - ), - __METHOD__ - ); + $result = array(); + if ( $canViewUnwatched ) { + $watchers = (int)$dbr->selectField( + 'watchlist', + 'COUNT(*)', + array( + 'wl_namespace' => $title->getNamespace(), + 'wl_title' => $title->getDBkey(), + ), + __METHOD__ + ); + $result['watchers'] = $watchers; + } $edits = (int)$dbr->selectField( 'revision', @@ -127,6 +139,7 @@ class InfoAction extends FormlessAction { array( 'rev_page' => $id ), __METHOD__ ); + $result['edits'] = $edits; $authors = (int)$dbr->selectField( 'revision', @@ -134,11 +147,9 @@ class InfoAction extends FormlessAction { array( 'rev_page' => $id ), __METHOD__ ); - $result = array( 'watchers' => $watchers, 'edits' => $edits, - 'authors' => $authors ); + $result['authors'] = $authors; - global $wgDisableCounters; - if ( !$wgDisableCounters ) { + if ( !$disableCounter ) { $views = (int)$dbr->selectField( 'page', 'page_counter',