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 public function getRestriction() {
36 protected function getDescription() {
40 public function requiresWrite() {
44 public function requiresUnblock() {
48 protected function getPageTitle() {
49 return wfMsg( 'pageinfo-title', $this->getTitle()->getSubjectPage()->getPrefixedText() );
52 public function onView() {
53 global $wgDisableCounters;
55 $title = $this->getTitle()->getSubjectPage();
57 $pageInfo = self
::pageCountInfo( $title );
58 $talkInfo = self
::pageCountInfo( $title->getTalkPage() );
60 return Html
::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ),
61 Html
::rawElement( 'tr', array(),
62 Html
::element( 'th', array(), '' ) .
63 Html
::element( 'th', array(), wfMsg( 'pageinfo-subjectpage' ) ) .
64 Html
::element( 'th', array(), wfMsg( 'pageinfo-talkpage' ) )
66 Html
::rawElement( 'tr', array(),
67 Html
::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-edits' ) )
69 Html
::rawElement( 'tr', array(),
70 Html
::element( 'td', array(), wfMsg( 'pageinfo-edits' ) ) .
71 Html
::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['edits'] ) ) .
72 Html
::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['edits'] ) )
74 Html
::rawElement( 'tr', array(),
75 Html
::element( 'td', array(), wfMsg( 'pageinfo-authors' ) ) .
76 Html
::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['authors'] ) ) .
77 Html
::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['authors'] ) )
79 ( !$this->getUser()->isAllowed( 'unwatchedpages' ) ?
'' :
80 Html
::rawElement( 'tr', array(),
81 Html
::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-watchlist' ) )
83 Html
::rawElement( 'tr', array(),
84 Html
::element( 'td', array(), wfMsg( 'pageinfo-watchers' ) ) .
85 Html
::element( 'td', array( 'colspan' => 2 ), $this->getLang()->formatNum( $pageInfo['watchers'] ) )
88 ( $wgDisableCounters ?
'' :
89 Html
::rawElement( 'tr', array(),
90 Html
::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-views' ) )
92 Html
::rawElement( 'tr', array(),
93 Html
::element( 'td', array(), wfMsg( 'pageinfo-views' ) ) .
94 Html
::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['views'] ) ) .
95 Html
::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['views'] ) )
97 Html
::rawElement( 'tr', array(),
98 Html
::element( 'td', array(), wfMsg( 'pageinfo-viewsperedit' ) ) .
99 Html
::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $pageInfo['edits'] ?
$pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) .
100 Html
::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $talkInfo['edits'] ?
$talkInfo['views'] / $talkInfo['edits'] : 0 ) ) )
107 * Return the total number of edits and number of unique editors
108 * on a given page. If page does not exist, returns false.
110 * @param $title Title object
111 * @return mixed array or boolean false
113 public static function pageCountInfo( $title ) {
114 $id = $title->getArticleId();
115 $dbr = wfGetDB( DB_SLAVE
);
117 $watchers = (int)$dbr->selectField(
121 'wl_title' => $title->getDBkey(),
122 'wl_namespace' => $title->getNamespace()
127 $edits = (int)$dbr->selectField(
130 array( 'rev_page' => $id ),
134 $authors = (int)$dbr->selectField(
136 'COUNT(DISTINCT rev_user_text)',
137 array( 'rev_page' => $id ),
141 $views = (int)$dbr->selectField(
144 array( 'page_id' => $id ),
148 return array( 'watchers' => $watchers, 'edits' => $edits,
149 'authors' => $authors, 'views' => $views );