MediaWiki  REL1_19
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() { return true; }
00040         function isSyndicated() { return false; }
00041 
00042         function getQueryInfo() {
00043                 return array (
00044                         'tables' => array ( 'pagelinks', 'page' ),
00045                         'fields' => array ( 'pl_namespace AS namespace',
00046                                         'pl_title AS title',
00047                                         'COUNT(*) AS value',
00048                                         'page_namespace' ),
00049                         'options' => array ( 'HAVING' => 'COUNT(*) > 1',
00050                                 'GROUP BY' => 'pl_namespace, pl_title, '.
00051                                                 'page_namespace' ),
00052                         'join_conds' => array ( 'page' => array ( 'LEFT JOIN',
00053                                         array ( 'page_namespace = pl_namespace',
00054                                                 'page_title = pl_title' ) ) )
00055                 );
00056         }
00057 
00064         function preprocessResults( $db, $res ) {
00065                 if( $db->numRows( $res ) > 0 ) {
00066                         $linkBatch = new LinkBatch();
00067                         foreach ( $res as $row ) {
00068                                 $linkBatch->add( $row->namespace, $row->title );
00069                         }
00070                         $db->dataSeek( $res, 0 );
00071                         $linkBatch->execute();
00072                 }
00073         }
00074 
00082         function makeWlhLink( $title, $caption ) {
00083                 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
00084                 return Linker::linkKnown( $wlh, $caption );
00085         }
00086 
00094         function formatResult( $skin, $result ) {
00095                 $title = Title::makeTitleSafe( $result->namespace, $result->title );
00096                 if ( !$title ) {
00097                         return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
00098                 }
00099                 $link = Linker::link( $title );
00100                 $wlh = $this->makeWlhLink( $title,
00101                         $this->msg( 'nlinks' )->numParams( $result->value )->escaped() );
00102                 return $this->getLanguage()->specialList( $link, $wlh );
00103         }
00104 }