00001 <?php
00011 class WantedPagesPage extends QueryPage {
00012 var $nlinks;
00013
00014 function WantedPagesPage( $inc = false, $nlinks = true ) {
00015 $this->setListoutput( $inc );
00016 $this->nlinks = $nlinks;
00017 }
00018
00019 function getName() {
00020 return 'Wantedpages';
00021 }
00022
00023 function isExpensive() {
00024 return true;
00025 }
00026 function isSyndicated() { return false; }
00027
00028 function getSQL() {
00029 global $wgWantedPagesThreshold;
00030 $count = $wgWantedPagesThreshold - 1;
00031 $dbr = wfGetDB( DB_SLAVE );
00032 $pagelinks = $dbr->tableName( 'pagelinks' );
00033 $page = $dbr->tableName( 'page' );
00034 $sql = "SELECT 'Wantedpages' AS type,
00035 pl_namespace AS namespace,
00036 pl_title AS title,
00037 COUNT(*) AS value
00038 FROM $pagelinks
00039 LEFT JOIN $page AS pg1
00040 ON pl_namespace = pg1.page_namespace AND pl_title = pg1.page_title
00041 LEFT JOIN $page AS pg2
00042 ON pl_from = pg2.page_id
00043 WHERE pg1.page_namespace IS NULL
00044 AND pl_namespace NOT IN ( 2, 3 )
00045 AND pg2.page_namespace != 8
00046 GROUP BY pl_namespace, pl_title
00047 HAVING COUNT(*) > $count";
00048
00049 wfRunHooks( 'WantedPages::getSQL', array( &$this, &$sql ) );
00050 return $sql;
00051 }
00052
00056 function preprocessResults( $db, $res ) {
00057 $batch = new LinkBatch;
00058 while ( $row = $db->fetchObject( $res ) )
00059 $batch->add( $row->namespace, $row->title );
00060 $batch->execute();
00061
00062
00063 if ( $db->numRows( $res ) > 0 )
00064
00065 $db->dataSeek( $res, 0 );
00066 }
00067
00075 public function formatResult( $skin, $result ) {
00076 $title = Title::makeTitleSafe( $result->namespace, $result->title );
00077 if( $title instanceof Title ) {
00078 if( $this->isCached() ) {
00079 $pageLink = $title->exists()
00080 ? '<s>' . $skin->makeLinkObj( $title ) . '</s>'
00081 : $skin->makeBrokenLinkObj( $title );
00082 } else {
00083 $pageLink = $skin->makeBrokenLinkObj( $title );
00084 }
00085 return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) );
00086 } else {
00087 $tsafe = htmlspecialchars( $result->title );
00088 return wfMsg( 'wantedpages-badtitle', $tsafe );
00089 }
00090 }
00091
00100 private function makeWlhLink( $title, $skin, $result ) {
00101 global $wgLang;
00102 if( $this->nlinks ) {
00103 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
00104 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
00105 $wgLang->formatNum( $result->value ) );
00106 return $skin->makeKnownLinkObj( $wlh, $label, 'target=' . $title->getPrefixedUrl() );
00107 } else {
00108 return null;
00109 }
00110 }
00111
00112 }
00113
00117 function wfSpecialWantedpages( $par = null, $specialPage ) {
00118 $inc = $specialPage->including();
00119
00120 if ( $inc ) {
00121 @list( $limit, $nlinks ) = explode( '/', $par, 2 );
00122 $limit = (int)$limit;
00123 $nlinks = $nlinks === 'nlinks';
00124 $offset = 0;
00125 } else {
00126 list( $limit, $offset ) = wfCheckLimits();
00127 $nlinks = true;
00128 }
00129
00130 $wpp = new WantedPagesPage( $inc, $nlinks );
00131
00132 $wpp->doQuery( $offset, $limit, !$inc );
00133 }