MediaWiki  REL1_21
SpecialMostlinked.php
Go to the documentation of this file.
00001 <?php
00033 class MostlinkedPage extends QueryPage {
00034 
00035         function __construct( $name = 'Mostlinked' ) {
00036                 parent::__construct( $name );
00037         }
00038 
00039         function isExpensive() {
00040                 return true;
00041         }
00042 
00043         function isSyndicated() {
00044                 return false;
00045         }
00046 
00047         function getQueryInfo() {
00048                 return array (
00049                         'tables' => array ( 'pagelinks', 'page' ),
00050                         'fields' => array ( 'namespace' => 'pl_namespace',
00051                                         'title' => 'pl_title',
00052                                         'value' => 'COUNT(*)',
00053                                         'page_namespace' ),
00054                         'options' => array ( 'HAVING' => 'COUNT(*) > 1',
00055                                 'GROUP BY' => array( 'pl_namespace', 'pl_title',
00056                                                 'page_namespace' ) ),
00057                         'join_conds' => array ( 'page' => array ( 'LEFT JOIN',
00058                                         array ( 'page_namespace = pl_namespace',
00059                                                 'page_title = pl_title' ) ) )
00060                 );
00061         }
00062 
00069         function preprocessResults( $db, $res ) {
00070                 if ( $res->numRows() > 0 ) {
00071                         $linkBatch = new LinkBatch();
00072                         foreach ( $res as $row ) {
00073                                 $linkBatch->add( $row->namespace, $row->title );
00074                         }
00075                         $res->seek( 0 );
00076                         $linkBatch->execute();
00077                 }
00078         }
00079 
00087         function makeWlhLink( $title, $caption ) {
00088                 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
00089                 return Linker::linkKnown( $wlh, $caption );
00090         }
00091 
00099         function formatResult( $skin, $result ) {
00100                 $title = Title::makeTitleSafe( $result->namespace, $result->title );
00101                 if ( !$title ) {
00102                         return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
00103                                 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
00104                 }
00105                 $link = Linker::link( $title );
00106                 $wlh = $this->makeWlhLink( $title,
00107                         $this->msg( 'nlinks' )->numParams( $result->value )->escaped() );
00108                 return $this->getLanguage()->specialList( $link, $wlh );
00109         }
00110 
00111         protected function getGroupName() {
00112                 return 'highuse';
00113         }
00114 }