From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/actions/InfoAction.php | 151 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 includes/actions/InfoAction.php (limited to 'includes/actions/InfoAction.php') diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php new file mode 100644 index 00000000..b0b5f259 --- /dev/null +++ b/includes/actions/InfoAction.php @@ -0,0 +1,151 @@ +getTitle()->getSubjectPage()->getPrefixedText() ); + } + + public function onView() { + global $wgDisableCounters; + + $title = $this->getTitle()->getSubjectPage(); + + $pageInfo = self::pageCountInfo( $title ); + $talkInfo = self::pageCountInfo( $title->getTalkPage() ); + + return Html::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ), + Html::rawElement( 'tr', array(), + Html::element( 'th', array(), '' ) . + Html::element( 'th', array(), wfMsg( 'pageinfo-subjectpage' ) ) . + Html::element( 'th', array(), wfMsg( 'pageinfo-talkpage' ) ) + ) . + Html::rawElement( 'tr', array(), + Html::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-edits' ) ) + ) . + Html::rawElement( 'tr', array(), + Html::element( 'td', array(), wfMsg( 'pageinfo-edits' ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['edits'] ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['edits'] ) ) + ) . + Html::rawElement( 'tr', array(), + Html::element( 'td', array(), wfMsg( 'pageinfo-authors' ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['authors'] ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['authors'] ) ) + ) . + ( !$this->getUser()->isAllowed( 'unwatchedpages' ) ? '' : + Html::rawElement( 'tr', array(), + Html::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-watchlist' ) ) + ) . + Html::rawElement( 'tr', array(), + Html::element( 'td', array(), wfMsg( 'pageinfo-watchers' ) ) . + Html::element( 'td', array( 'colspan' => 2 ), $this->getLang()->formatNum( $pageInfo['watchers'] ) ) + ) + ). + ( $wgDisableCounters ? '' : + Html::rawElement( 'tr', array(), + Html::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-views' ) ) + ) . + Html::rawElement( 'tr', array(), + Html::element( 'td', array(), wfMsg( 'pageinfo-views' ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['views'] ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['views'] ) ) + ) . + Html::rawElement( 'tr', array(), + Html::element( 'td', array(), wfMsg( 'pageinfo-viewsperedit' ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $pageInfo['edits'] ? $pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) . + Html::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $talkInfo['edits'] ? $talkInfo['views'] / $talkInfo['edits'] : 0 ) ) ) + ) + ) + ); + } + + /** + * Return the total number of edits and number of unique editors + * on a given page. If page does not exist, returns false. + * + * @param $title Title object + * @return mixed array or boolean false + */ + public static function pageCountInfo( $title ) { + $id = $title->getArticleId(); + $dbr = wfGetDB( DB_SLAVE ); + + $watchers = (int)$dbr->selectField( + 'watchlist', + 'COUNT(*)', + array( + 'wl_title' => $title->getDBkey(), + 'wl_namespace' => $title->getNamespace() + ), + __METHOD__ + ); + + $edits = (int)$dbr->selectField( + 'revision', + 'COUNT(rev_page)', + array( 'rev_page' => $id ), + __METHOD__ + ); + + $authors = (int)$dbr->selectField( + 'revision', + 'COUNT(DISTINCT rev_user_text)', + array( 'rev_page' => $id ), + __METHOD__ + ); + + $views = (int)$dbr->selectField( + 'page', + 'page_counter', + array( 'page_id' => $id ), + __METHOD__ + ); + + return array( 'watchers' => $watchers, 'edits' => $edits, + 'authors' => $authors, 'views' => $views ); + } +} -- cgit v1.2.2