3 * Display informations about a page.
4 * Very inefficient for the moment.
6 * Copyright © 2011 Alexandre Emsenhuber
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 class InfoAction
extends FormlessAction
{
28 public function getName() {
32 protected function getDescription() {
36 public function requiresWrite() {
40 public function requiresUnblock() {
44 protected function getPageTitle() {
45 return $this->msg( 'pageinfo-title', $this->getTitle()->getSubjectPage()->getPrefixedText() )->text();
48 public function onView() {
49 global $wgDisableCounters;
51 $title = $this->getTitle()->getSubjectPage();
53 $userCanViewUnwatchedPages = $this->getUser()->isAllowed( 'unwatchedpages' );
55 $pageInfo = self
::pageCountInfo( $title, $userCanViewUnwatchedPages, $wgDisableCounters );
56 $talkInfo = self
::pageCountInfo( $title->getTalkPage(), $userCanViewUnwatchedPages, $wgDisableCounters );
58 $lang = $this->getLanguage();
61 Html
::rawElement( 'tr', array(),
62 Html
::element( 'th', array(), '' ) .
63 Html
::element( 'th', array(), $this->msg( 'pageinfo-subjectpage' )->text() ) .
64 Html
::element( 'th', array(), $this->msg( 'pageinfo-talkpage' )->text() )
66 Html
::rawElement( 'tr', array(),
67 Html
::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-edits' )->text() )
69 Html
::rawElement( 'tr', array(),
70 Html
::element( 'td', array(), $this->msg( 'pageinfo-edits' )->text() ) .
71 Html
::element( 'td', array(), $lang->formatNum( $pageInfo['edits'] ) ) .
72 Html
::element( 'td', array(), $lang->formatNum( $talkInfo['edits'] ) )
74 Html
::rawElement( 'tr', array(),
75 Html
::element( 'td', array(), $this->msg( 'pageinfo-authors' )->text() ) .
76 Html
::element( 'td', array(), $lang->formatNum( $pageInfo['authors'] ) ) .
77 Html
::element( 'td', array(), $lang->formatNum( $talkInfo['authors'] ) )
80 if ( $userCanViewUnwatchedPages ) {
81 $content .= Html
::rawElement( 'tr', array(),
82 Html
::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-watchlist' )->text() )
84 Html
::rawElement( 'tr', array(),
85 Html
::element( 'td', array(), $this->msg( 'pageinfo-watchers' )->text() ) .
86 Html
::element( 'td', array( 'colspan' => 2 ), $lang->formatNum( $pageInfo['watchers'] ) )
90 if ( $wgDisableCounters ) {
91 $content .= Html
::rawElement( 'tr', array(),
92 Html
::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-views' )->text() )
94 Html
::rawElement( 'tr', array(),
95 Html
::element( 'td', array(), $this->msg( 'pageinfo-views' )->text() ) .
96 Html
::element( 'td', array(), $lang->formatNum( $pageInfo['views'] ) ) .
97 Html
::element( 'td', array(), $lang->formatNum( $talkInfo['views'] ) )
99 Html
::rawElement( 'tr', array(),
100 Html
::element( 'td', array(), $this->msg( 'pageinfo-viewsperedit' )->text() ) .
101 Html
::element( 'td', array(), $lang->formatNum( sprintf( '%.2f', $pageInfo['edits'] ?
$pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) .
102 Html
::element( 'td', array(), $lang->formatNum( sprintf( '%.2f', $talkInfo['edits'] ?
$talkInfo['views'] / $talkInfo['edits'] : 0 ) ) )
105 return Html
::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ), $content );
109 * Return the total number of edits and number of unique editors
110 * on a given page. If page does not exist, returns false.
112 * @param $title Title object
113 * @param $canViewUnwatched bool
114 * @param $disableCounter bool
117 public static function pageCountInfo( $title, $canViewUnwatched, $disableCounter ) {
118 wfProfileIn( __METHOD__
);
119 $id = $title->getArticleID();
120 $dbr = wfGetDB( DB_SLAVE
);
123 if ( $canViewUnwatched ) {
124 $watchers = (int)$dbr->selectField(
128 'wl_namespace' => $title->getNamespace(),
129 'wl_title' => $title->getDBkey(),
133 $result['watchers'] = $watchers;
136 $edits = (int)$dbr->selectField(
139 array( 'rev_page' => $id ),
142 $result['edits'] = $edits;
144 $authors = (int)$dbr->selectField(
146 'COUNT(DISTINCT rev_user_text)',
147 array( 'rev_page' => $id ),
150 $result['authors'] = $authors;
152 if ( !$disableCounter ) {
153 $views = (int)$dbr->selectField(
156 array( 'page_id' => $id ),
159 $result['views'] = $views;
162 wfProfileOut( __METHOD__
);