MediaWiki  REL1_19
InfoAction.php
Go to the documentation of this file.
00001 <?php
00026 class InfoAction extends FormlessAction {
00027 
00028         public function getName() {
00029                 return 'info';
00030         }
00031 
00032         protected function getDescription() {
00033                 return '';
00034         }
00035 
00036         public function requiresWrite() {
00037                 return false;
00038         }
00039 
00040         public function requiresUnblock() {
00041                 return false;
00042         }
00043 
00044         protected function getPageTitle() {
00045                 return $this->msg( 'pageinfo-title', $this->getTitle()->getSubjectPage()->getPrefixedText() )->text();
00046         }
00047 
00048         public function onView() {
00049                 global $wgDisableCounters;
00050 
00051                 $title = $this->getTitle()->getSubjectPage();
00052 
00053                 $pageInfo = self::pageCountInfo( $title );
00054                 $talkInfo = self::pageCountInfo( $title->getTalkPage() );
00055 
00056                 return Html::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ),
00057                         Html::rawElement( 'tr', array(),
00058                                 Html::element( 'th', array(), '' ) .
00059                                 Html::element( 'th', array(), $this->msg( 'pageinfo-subjectpage' )->text() ) .
00060                                 Html::element( 'th', array(), $this->msg( 'pageinfo-talkpage' )->text() )
00061                         ) .
00062                         Html::rawElement( 'tr', array(),
00063                                 Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-edits' )->text() )
00064                         ) .
00065                         Html::rawElement( 'tr', array(),
00066                                 Html::element( 'td', array(), $this->msg( 'pageinfo-edits' )->text() ) .
00067                                 Html::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['edits'] ) ) .
00068                                 Html::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['edits'] ) )
00069                         ) .
00070                         Html::rawElement( 'tr', array(),
00071                                 Html::element( 'td', array(), $this->msg( 'pageinfo-authors' )->text() ) .
00072                                 Html::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['authors'] ) ) .
00073                                 Html::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['authors'] ) )
00074                         ) .
00075                         ( !$this->getUser()->isAllowed( 'unwatchedpages' ) ? '' :
00076                                 Html::rawElement( 'tr', array(),
00077                                         Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-watchlist' )->text() )
00078                                 ) .
00079                                 Html::rawElement( 'tr', array(),
00080                                         Html::element( 'td', array(), $this->msg( 'pageinfo-watchers' )->text() ) .
00081                                         Html::element( 'td', array( 'colspan' => 2 ), $this->getLanguage()->formatNum( $pageInfo['watchers'] ) )
00082                                 )
00083                         ).
00084                         ( $wgDisableCounters ? '' :
00085                                 Html::rawElement( 'tr', array(),
00086                                         Html::element( 'th', array( 'colspan' => 3 ), $this->msg( 'pageinfo-header-views' )->text() )
00087                                 ) .
00088                                 Html::rawElement( 'tr', array(),
00089                                         Html::element( 'td', array(), $this->msg( 'pageinfo-views' )->text() ) .
00090                                         Html::element( 'td', array(), $this->getLanguage()->formatNum( $pageInfo['views'] ) ) .
00091                                         Html::element( 'td', array(), $this->getLanguage()->formatNum( $talkInfo['views'] ) )
00092                                 ) .
00093                                 Html::rawElement( 'tr', array(),
00094                                         Html::element( 'td', array(), $this->msg( 'pageinfo-viewsperedit' )->text() ) .
00095                                         Html::element( 'td', array(), $this->getLanguage()->formatNum( sprintf( '%.2f', $pageInfo['edits'] ? $pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) .
00096                                         Html::element( 'td', array(), $this->getLanguage()->formatNum( sprintf( '%.2f', $talkInfo['edits'] ? $talkInfo['views'] / $talkInfo['edits'] : 0 ) ) )
00097                                 )
00098                         )
00099                 );
00100         }
00101 
00109         public static function pageCountInfo( $title ) {
00110                 $id = $title->getArticleId();
00111                 $dbr = wfGetDB( DB_SLAVE );
00112 
00113                 $watchers = (int)$dbr->selectField(
00114                         'watchlist',
00115                         'COUNT(*)',
00116                         array(
00117                                 'wl_title'     => $title->getDBkey(),
00118                                 'wl_namespace' => $title->getNamespace()
00119                         ),
00120                         __METHOD__
00121                 );
00122 
00123                 $edits = (int)$dbr->selectField(
00124                         'revision',
00125                         'COUNT(rev_page)',
00126                         array( 'rev_page' => $id ),
00127                         __METHOD__
00128                 );
00129 
00130                 $authors = (int)$dbr->selectField(
00131                         'revision',
00132                         'COUNT(DISTINCT rev_user_text)',
00133                         array( 'rev_page' => $id ),
00134                         __METHOD__
00135                 );
00136 
00137                 $views = (int)$dbr->selectField(
00138                         'page',
00139                         'page_counter',
00140                         array( 'page_id' => $id ),
00141                         __METHOD__
00142                 );
00143 
00144                 return array( 'watchers' => $watchers, 'edits' => $edits,
00145                         'authors' => $authors, 'views' => $views );
00146         }
00147 }