How to find "Wanted Images"

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to find "Wanted Images"

Ken McDonald-2
I just realize that "Wanted Pages" doesn't show info on needed images,
and none of the other special pages has any obvious relation to such a
function. Is there a way to do this easily?

Thanks,
Ken
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: How to find "Wanted Images"

Alexis Moinet
I don't know if it helps, but if you type [[:Image:name.ext]] instead of [[Image:name.ext]] it will appear in the wantedpages list

Ken McDonald a écrit :
> I just realize that "Wanted Pages" doesn't show info on needed images,
> and none of the other special pages has any obvious relation to such a
> function. Is there a way to do this easily?

_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: How to find "Wanted Images"

Alexis Moinet
In reply to this post by Ken McDonald-2
I tested this and it *seems* to work pretty well :

in includes/specialwantedpages.php, I replaced

                $pagelinks = $dbr->tableName( 'pagelinks' );
                $page      = $dbr->tableName( 'page' );
                return
                        "SELECT 'Wantedpages' AS type,
                                pl_namespace AS namespace,
                                pl_title AS title,
                                COUNT(*) AS value
                         FROM $pagelinks
                         LEFT JOIN $page AS pg1
                         ON pl_namespace = pg1.page_namespace AND pl_title = pg1.page_title
                         LEFT JOIN $page AS pg2
                         ON pl_from = pg2.page_id
                         WHERE pg1.page_namespace IS NULL
                         AND pg2.page_namespace != 8
                         GROUP BY pl_namespace, pl_title
                         HAVING COUNT(*) > $count";

with

                $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";

HOWEVER,
1. I don't know a lot about mysql, I did this with kind of a "I'm-lucky-and-I-have-a-good-feeling-about-this" method. Any MySQL
professional may say this is evil (though I hope it's not)
2. it seems to work properly BUT the "(n links)" link beside of the wanted image name doesn't work properly, guess you've got to
change something in the SpecialWhatlinkshere.php file, but don't know what.
3. I suggest you to create a new special page SpecialWantedimages.php instead of modifying the wanted pages one's. (this was
just for demo) (see "create a new special page" on mediawiki.org though it seems a little bit outdated)

Ken McDonald a écrit :
> I just realize that "Wanted Pages" doesn't show info on needed images,
> and none of the other special pages has any obvious relation to such a
> function. Is there a way to do this easily?
>
> Thanks,
> Ken

_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: How to find "Wanted Images"

Rob Church
On 03/06/06, Alexis Moinet <[hidden email]> wrote:
> Ken McDonald a écrit :
> > I just realize that "Wanted Pages" doesn't show info on needed images,
> > and none of the other special pages has any obvious relation to such a
> > function. Is there a way to do this easily?

It wouldn't be too difficult to add this as a special page similar to
Special:Wantedpages, for inclusion in MediaWiki 1.7alpha.


Rob Church
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: How to find "Wanted Images"

Alexis Moinet
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 );

_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l