00001 <?php
00019 class MostlinkedPage extends QueryPage {
00020
00021 function getName() { return 'Mostlinked'; }
00022 function isExpensive() { return true; }
00023 function isSyndicated() { return false; }
00024
00025 function getSQL() {
00026 global $wgMiserMode;
00027
00028 $dbr = wfGetDB( DB_SLAVE );
00029
00030 # In miser mode, reduce the query cost by adding a threshold for large wikis
00031 if ( $wgMiserMode ) {
00032 $numPages = SiteStats::pages();
00033 if ( $numPages > 10000 ) {
00034 $cutoff = 100;
00035 } elseif ( $numPages > 100 ) {
00036 $cutoff = intval( sqrt( $numPages ) );
00037 } else {
00038 $cutoff = 1;
00039 }
00040 } else {
00041 $cutoff = 1;
00042 }
00043
00044 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
00045 return
00046 "SELECT 'Mostlinked' AS type,
00047 pl_namespace AS namespace,
00048 pl_title AS title,
00049 COUNT(*) AS value
00050 FROM $pagelinks
00051 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
00052 GROUP BY pl_namespace, pl_title
00053 HAVING COUNT(*) > $cutoff";
00054 }
00055
00059 function preprocessResults( $db, $res ) {
00060 if( $db->numRows( $res ) > 0 ) {
00061 $linkBatch = new LinkBatch();
00062 while( $row = $db->fetchObject( $res ) )
00063 $linkBatch->add( $row->namespace, $row->title );
00064 $db->dataSeek( $res, 0 );
00065 $linkBatch->execute();
00066 }
00067 }
00068
00077 function makeWlhLink( &$title, $caption, &$skin ) {
00078 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
00079 return $skin->linkKnown( $wlh, $caption );
00080 }
00081
00089 function formatResult( $skin, $result ) {
00090 global $wgLang;
00091 $title = Title::makeTitleSafe( $result->namespace, $result->title );
00092 if ( !$title ) {
00093 return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
00094 }
00095 $link = $skin->link( $title );
00096 $wlh = $this->makeWlhLink( $title,
00097 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
00098 $wgLang->formatNum( $result->value ) ), $skin );
00099 return wfSpecialList( $link, $wlh );
00100 }
00101 }
00102
00106 function wfSpecialMostlinked() {
00107 list( $limit, $offset ) = wfCheckLimits();
00108
00109 $wpp = new MostlinkedPage();
00110
00111 $wpp->doQuery( $offset, $limit );
00112 }