00001 <?php
00018 class WantedTemplatesPage extends QueryPage {
00019
00020 function getName() {
00021 return 'Wantedtemplates';
00022 }
00023
00024 function isExpensive() {
00025 return true;
00026 }
00027
00028 function isSyndicated() {
00029 return false;
00030 }
00031
00032 function getSQL() {
00033 $dbr = wfGetDB( DB_SLAVE );
00034 list( $templatelinks, $page ) = $dbr->tableNamesN( 'templatelinks', 'page' );
00035 $name = $dbr->addQuotes( $this->getName() );
00036 return
00037 "
00038 SELECT $name as type,
00039 tl_namespace as namespace,
00040 tl_title as title,
00041 COUNT(*) as value
00042 FROM $templatelinks LEFT JOIN
00043 $page ON tl_title = page_title AND tl_namespace = page_namespace
00044 WHERE page_title IS NULL AND tl_namespace = ". NS_TEMPLATE ."
00045 GROUP BY tl_namespace, tl_title
00046 ";
00047 }
00048
00049 function sortDescending() { return true; }
00050
00054 function preprocessResults( $db, $res ) {
00055 $batch = new LinkBatch;
00056 while ( $row = $db->fetchObject( $res ) )
00057 $batch->add( $row->namespace, $row->title );
00058 $batch->execute();
00059
00060
00061 if ( $db->numRows( $res ) > 0 )
00062
00063 $db->dataSeek( $res, 0 );
00064 }
00065
00066 function formatResult( $skin, $result ) {
00067 global $wgLang, $wgContLang;
00068
00069 $nt = Title::makeTitle( $result->namespace, $result->title );
00070 $text = $wgContLang->convert( $nt->getText() );
00071
00072 $plink = $this->isCached() ?
00073 $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) :
00074 $skin->makeBrokenLinkObj( $nt, htmlspecialchars( $text ) );
00075
00076 return wfSpecialList(
00077 $plink,
00078 $this->makeWlhLink( $nt, $skin, $result )
00079 );
00080 }
00081
00090 private function makeWlhLink( $title, $skin, $result ) {
00091 global $wgLang;
00092 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
00093 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
00094 $wgLang->formatNum( $result->value ) );
00095 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
00096 }
00097 }
00098
00102 function wfSpecialWantedTemplates() {
00103 list( $limit, $offset ) = wfCheckLimits();
00104
00105 $wpp = new WantedTemplatesPage();
00106
00107 $wpp->doQuery( $offset, $limit );
00108 }