Doing this worked fine for me :
*in localsettings.php :*
require_once( 'extensions/SpecialWantedimages.php' );
-----------------------------------------------------------------------------------------------------------------------------------------
*new extension (in extensions/SpecialWantedimages.php):*
<?php
$wgExtensionFunctions[] = "wfExtensionSpecialWantedimages";
function wfExtensionSpecialWantedimages() {
global $wgMessageCache;
$wgMessageCache->addMessages(array('wantedimages' => 'Wanted
images')); //will expand
// the name 'wantedimages' above should NOT have any capital letter.
SpecialPage::addPage( new SpecialPage( 'Wantedimages' ) );
}
require_once 'Hooks.php';
require_once 'QueryPage.php';
/**
*
* @package MediaWiki
* @subpackage SpecialPage
*/
class WantedImagesPage extends QueryPage {
var $nlinks;
function WantedImagesPage( $inc = false, $nlinks = true ) {
$this->setListoutput( $inc );
$this->nlinks = $nlinks;
}
function getName() {
return 'Wantedimages';
}
function isExpensive() {
return true;
}
function isSyndicated() { return false; }
function getSQL() {
global $wgWantedPagesThreshold;
$count = $wgWantedPagesThreshold - 1;
$dbr =& wfGetDB( DB_SLAVE );
$pagelinks = $dbr->tableName( 'imagelinks' );
$page = $dbr->tableName( 'image' );
return
"SELECT 'Wantedpages' AS type,
6 AS namespace,
il_to AS title,
COUNT(*) AS value
FROM $pagelinks
WHERE il_to <> ALL(SELECT img_name FROM $page)
GROUP BY il_to
HAVING COUNT(*) > $count";
}
/**
* Fetch user page links and cache their existence
*/
function preprocessResults( &$db, &$res ) {
$batch = new LinkBatch;
while ( $row = $db->fetchObject( $res ) )
$batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
$batch->execute();
// Back to start for display
if ( $db->numRows( $res ) > 0 )
// If there are no rows we get an error seeking.
$db->dataSeek( $res, 0 );
}
function formatResult( $skin, $result ) {
global $wgContLang;
$nt = Title::makeTitle( $result->namespace, $result->title );
$text = $wgContLang->convert( $nt->getPrefixedText() );
$plink = $this->isCached() ?
$skin->makeLinkObj( $nt, $text ) :
$skin->makeBrokenLink( $nt->getPrefixedText(), $text );
$nl = wfMsg( 'nlinks', $result->value );
$nlink = $skin->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere'
), $nl, 'target=' . $nt->getPrefixedURL() );
return $this->nlinks ? "$plink ($nlink)" : $plink;
}
}
/**
* constructor
*/
function wfSpecialWantedimages( $par = null, $specialPage ) {
$inc = $specialPage->including();
if ( $inc ) {
@list( $limit, $nlinks ) = explode( '/', $par, 2 );
$limit = (int)$limit;
$nlinks = $nlinks === 'nlinks';
$offset = 0;
} else {
list( $limit, $offset ) = wfCheckLimits();
$nlinks = true;
}
$wpp = new WantedImagesPage( $inc, $nlinks );
$wpp->doQuery( $offset, $limit, !$inc );
}
?>
-----------------------------------------------------------------------------------------------------------------------------------------
*in includes/specialwhatlinkshere.php* :
$dbr =& wfGetDB( DB_READ );
/*------------------------------------------------------------------------------*/
/*CHANGE THIS*/
extract( $dbr->tableNames( 'imagelinks', 'pagelinks',
'templatelinks', 'page' ) );
/*------*/
// Some extra validation
$from = intval( $from );
if ( !$from && $dir == 'prev' ) {
// Before start? No make sense
$dir = 'next';
}
// Make the query
/*ADD THIS*/
$ilConds = array(
'page_id=il_from',
'il_to' => $target->getDBkey(),
);
/*-------*/
$plConds = array(
'page_id=pl_from',
'pl_namespace' => $target->getNamespace(),
'pl_title' => $target->getDBkey(),
);
$tlConds = array(
'page_id=tl_from',
'tl_namespace' => $target->getNamespace(),
'tl_title' => $target->getDBkey(),
);
if ( $from ) {
if ( 'prev' == $dir ) {
$offsetCond = "page_id < $from";
$options = array( 'ORDER BY page_id DESC' );
} else {
$offsetCond = "page_id >= $from";
$options = array( 'ORDER BY page_id' );
}
} else {
$offsetCond = false;
$options = array( 'ORDER BY page_id,is_template DESC' );
}
// Read an extra row as an at-end check
$queryLimit = $limit + 1;
$options['LIMIT'] = $queryLimit;
if ( $offsetCond ) {
$tlConds[] = $offsetCond;
$plConds[] = $offsetCond;
}
$fields = array( 'page_id', 'page_namespace', 'page_title',
'page_is_redirect' );
/*ADD THIS*/
$ilRes = $dbr->select( array( 'imagelinks', 'page' ), $fields,
$ilConds, $fname, $options );
/*------*/
$plRes = $dbr->select( array( 'pagelinks', 'page' ), $fields,
$plConds, $fname, $options );
$tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields,
$tlConds, $fname, $options );
if ( !$dbr->numRows( $plRes ) && !$dbr->numRows( $tlRes ) &&
/*ALEXIS*/!$dbr->numRows( $ilRes )/*------*/ ) {
if ( 0 == $level ) {
$wgOut->addWikiText( wfMsg( 'nolinkshere' ) );
}
return;
}
// Read the rows into an array and remove duplicates
// templatelinks comes second so that the templatelinks row overwrites the
// pagelinks row, so we get (inclusion) rather than nothing
/*ADD THIS*/
while ( $row = $dbr->fetchObject( $ilRes ) ) {
$row->is_template = 0;
$rows[$row->page_id] = $row;
}
$dbr->freeResult( $ilRes );
/*------*/
while ( $row = $dbr->fetchObject( $plRes ) ) {
$row->is_template = 0;
$rows[$row->page_id] = $row;
}
$dbr->freeResult( $plRes );
while ( $row = $dbr->fetchObject( $tlRes ) ) {
$row->is_template = 1;
$rows[$row->page_id] = $row;
}
$dbr->freeResult( $tlRes );
/*------------------------------------------------------------------------------*/
// Sort by key and then change the keys to 0-based indices
ksort( $rows );