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 $pageInfo = self
::pageCountInfo( $title );
54 $talkInfo = self
::pageCountInfo( $title->getTalkPage() );
56 return Html
::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ),
57 Html
::rawElement( 'tr', array(),
58 Html
::element( 'th', array(), '' ) .
59 Html
::element( 'th', array(), $this->msg( 'pageinfo-subjectpage' )->text() ) .
60 Html
::element( 'th', array(), $this->msg( 'pageinfo-talkpage' )->text() )
62 Html
::rawElement( 'tr', array(),
63 Html
::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-edits' )->text() )
65 Html
::rawElement( 'tr', array(),
66 Html
::element( 'td', array(), $this->msg( 'pageinfo-edits' )->text() ) .
67 Html
::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['edits'] ) ) .
68 Html
::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['edits'] ) )
70 Html
::rawElement( 'tr', array(),
71 Html
::element( 'td', array(), $this->msg( 'pageinfo-authors' )->text() ) .
72 Html
::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['authors'] ) ) .
73 Html
::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['authors'] ) )
75 ( !$this->getUser()->isAllowed( 'unwatchedpages' ) ?
'' :
76 Html
::rawElement( 'tr', array(),
77 Html
::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-watchlist' )->text() )
79 Html
::rawElement( 'tr', array(),
80 Html
::element( 'td', array(), $this->msg( 'pageinfo-watchers' )->text() ) .
81 Html
::element( 'td', array( 'colspan' => 2 ), $this->getLanguage()->formatNum( $pageInfo['watchers'] ) )
84 ( $wgDisableCounters ?
'' :
85 Html
::rawElement( 'tr', array(),
86 Html
::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-views' )->text() )
88 Html
::rawElement( 'tr', array(),
89 Html
::element( 'td', array(), $this->msg( 'pageinfo-views' )->text() ) .
90 Html
::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['views'] ) ) .
91 Html
::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['views'] ) )
93 Html
::rawElement( 'tr', array(),
94 Html
::element( 'td', array(), $this->msg( 'pageinfo-viewsperedit' )->text() ) .
95 Html
::element( 'td', array(), $this->getLanguage()->formatNum( sprintf( '%.2f', $pageInfo['edits'] ?
$pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) .
96 Html
::element( 'td', array(), $this->getLanguage()->formatNum( sprintf( '%.2f', $talkInfo['edits'] ?
$talkInfo['views'] / $talkInfo['edits'] : 0 ) ) )
103 * Return the total number of edits and number of unique editors
104 * on a given page. If page does not exist, returns false.
106 * @param $title Title object
107 * @return mixed array or boolean false
109 public static function pageCountInfo( $title ) {
110 $id = $title->getArticleID();
111 $dbr = wfGetDB( DB_SLAVE
);
113 $watchers = (int)$dbr->selectField(
117 'wl_title' => $title->getDBkey(),
118 'wl_namespace' => $title->getNamespace()
123 $edits = (int)$dbr->selectField(
126 array( 'rev_page' => $id ),
130 $authors = (int)$dbr->selectField(
132 'COUNT(DISTINCT rev_user_text)',
133 array( 'rev_page' => $id ),
137 $views = (int)$dbr->selectField(
140 array( 'page_id' => $id ),
144 return array( 'watchers' => $watchers, 'edits' => $edits,
145 'authors' => $authors, 'views' => $views );