MediaWiki  REL1_22
SpecialMostlinked.php
Go to the documentation of this file.
00001 <?php
00033 class MostlinkedPage extends QueryPage {
00034     function __construct( $name = 'Mostlinked' ) {
00035         parent::__construct( $name );
00036     }
00037 
00038     function isExpensive() {
00039         return true;
00040     }
00041 
00042     function isSyndicated() {
00043         return false;
00044     }
00045 
00046     function getQueryInfo() {
00047         return array(
00048             'tables' => array( 'pagelinks', 'page' ),
00049             'fields' => array(
00050                 'namespace' => 'pl_namespace',
00051                 'title' => 'pl_title',
00052                 'value' => 'COUNT(*)',
00053                 'page_namespace'
00054             ),
00055             'options' => array(
00056                 'HAVING' => 'COUNT(*) > 1',
00057                 'GROUP BY' => array(
00058                     'pl_namespace', 'pl_title',
00059                     'page_namespace'
00060                 )
00061             ),
00062             'join_conds' => array(
00063                 'page' => array(
00064                     'LEFT JOIN',
00065                     array(
00066                         'page_namespace = pl_namespace',
00067                         'page_title = pl_title'
00068                     )
00069                 )
00070             )
00071         );
00072     }
00073 
00080     function preprocessResults( $db, $res ) {
00081         if ( $res->numRows() > 0 ) {
00082             $linkBatch = new LinkBatch();
00083 
00084             foreach ( $res as $row ) {
00085                 $linkBatch->add( $row->namespace, $row->title );
00086             }
00087 
00088             $res->seek( 0 );
00089             $linkBatch->execute();
00090         }
00091     }
00092 
00100     function makeWlhLink( $title, $caption ) {
00101         $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
00102 
00103         return Linker::linkKnown( $wlh, $caption );
00104     }
00105 
00114     function formatResult( $skin, $result ) {
00115         $title = Title::makeTitleSafe( $result->namespace, $result->title );
00116         if ( !$title ) {
00117             return Html::element(
00118                 'span',
00119                 array( 'class' => 'mw-invalidtitle' ),
00120                 Linker::getInvalidTitleDescription(
00121                     $this->getContext(),
00122                     $result->namespace,
00123                     $result->title )
00124             );
00125         }
00126 
00127         $link = Linker::link( $title );
00128         $wlh = $this->makeWlhLink(
00129             $title,
00130             $this->msg( 'nlinks' )->numParams( $result->value )->escaped()
00131         );
00132 
00133         return $this->getLanguage()->specialList( $link, $wlh );
00134     }
00135 
00136     protected function getGroupName() {
00137         return 'highuse';
00138     }
00139 }