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 public function onView() {
49 global $wgDisableCounters;
51 $title = $this->getTitle()->getSubjectPage();
53 $this->getOutput()->setPagetitle( wfMsg( 'pageinfo-title', $title->getPrefixedText() ) );
55 $pageInfo = self
::pageCountInfo( $title );
56 $talkInfo = self
::pageCountInfo( $title->getTalkPage() );
58 return Html
::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ),
59 Html
::rawElement( 'tr', array(),
60 Html
::element( 'th', array(), '' ) .
61 Html
::element( 'th', array(), wfMsg( 'pageinfo-subjectpage' ) ) .
62 Html
::element( 'th', array(), wfMsg( 'pageinfo-talkpage' ) )
64 Html
::rawElement( 'tr', array(),
65 Html
::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-edits' ) )
67 Html
::rawElement( 'tr', array(),
68 Html
::element( 'td', array(), wfMsg( 'pageinfo-edits' ) ) .
69 Html
::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['edits'] ) ) .
70 Html
::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['edits'] ) )
72 Html
::rawElement( 'tr', array(),
73 Html
::element( 'td', array(), wfMsg( 'pageinfo-authors' ) ) .
74 Html
::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['authors'] ) ) .
75 Html
::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['authors'] ) )
77 ( !$this->getUser()->isAllowed( 'unwatchedpages' ) ?
'' :
78 Html
::rawElement( 'tr', array(),
79 Html
::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-watchlist' ) )
81 Html
::rawElement( 'tr', array(),
82 Html
::element( 'td', array(), wfMsg( 'pageinfo-watchers' ) ) .
83 Html
::element( 'td', array( 'colspan' => 2 ), $this->getLang()->formatNum( $pageInfo['watchers'] ) )
86 ( $wgDisableCounters ?
'' :
87 Html
::rawElement( 'tr', array(),
88 Html
::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-views' ) )
90 Html
::rawElement( 'tr', array(),
91 Html
::element( 'td', array(), wfMsg( 'pageinfo-views' ) ) .
92 Html
::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['views'] ) ) .
93 Html
::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['views'] ) )
95 Html
::rawElement( 'tr', array(),
96 Html
::element( 'td', array(), wfMsg( 'pageinfo-viewsperedit' ) ) .
97 Html
::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $pageInfo['edits'] ?
$pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) .
98 Html
::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $talkInfo['edits'] ?
$talkInfo['views'] / $talkInfo['edits'] : 0 ) ) )
105 * Return the total number of edits and number of unique editors
106 * on a given page. If page does not exist, returns false.
108 * @param $title Title object
109 * @return mixed array or boolean false
111 public static function pageCountInfo( $title ) {
112 $id = $title->getArticleId();
113 $dbr = wfGetDB( DB_SLAVE
);
115 $watchers = (int)$dbr->selectField(
119 'wl_title' => $title->getDBkey(),
120 'wl_namespace' => $title->getNamespace()
125 $edits = (int)$dbr->selectField(
128 array( 'rev_page' => $id ),
132 $authors = (int)$dbr->selectField(
134 'COUNT(DISTINCT rev_user_text)',
135 array( 'rev_page' => $id ),
139 $views = (int)$dbr->selectField(
142 array( 'page_id' => $id ),
146 return array( 'watchers' => $watchers, 'edits' => $edits,
147 'authors' => $authors, 'views' => $views );