Extension:RandomImagewithinCommons

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Random Image within Commons

Release status: beta

Implementation Tag, Parser function
Description Display a Random Image from the Wiki instanz with Commons that store by Commons
Author(s) Thiemo Schuff (StarwhooperTalk)
Last version 1.0 beta build 20110802
License cc-by-sa-de
Download No link
Example http://thwiki.schuff.eu
Tags
image random

Check usage (experimental)

Contents

[edit] What can this extension do?

It display a Randomize Image per view

[edit] History

released Version 1.0 beta on 2. August 2011

[edit] further versions

  • filter Namespace
  • fillup gallerys with random pictures (to create a picturewall)
  • repace all DB Querys with Mediawiki wfGetDB function
  • extension should be alble, to selfcreate thumbnail (at the moment it user the 200px files)
  • Use MediaWiki internal function to create thumbnails

[edit] Usage

Set tag <riwc />

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/RandomImagewithinCommons.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once("{$IP}/extensions/RandomImagewithinCommons.php");

[edit] Configuration parameters

see comments above

[edit] User rights

[edit] Code

<?php
//Website http://www.mediawiki.org/wiki/Extension:RandomImagewithinCommons
//cc-by-sa-de 3.0 by Thiemo Schuff
 
$wgExtensionCredits['parserhook'][] = array(
        'path'           => __FILE__,
        'name'           => 'RandomImagewithCommons',
        'description'    => 'Display Random Image with tag <tt>&lt;riwc /&gt;</tt> above your complete Wikimedia Instants with Commonused images.',
        'version'        => '1.0 beta build 20110802',
        'author'         => 'Thiemo Schuff',
        'url'            => 'http://www.mediawiki.org/wiki/Extension:RandomImagewithinCommons',
);
 
$wgExtensionFunctions[] = 'wfRandomImageFunction';
 
function wfRandomImageFunction() {
        global $wgParser;
        $wgParser->setHook('riwc', 'randomimagewithincommos');
}
 
function randomimagewithincommos($input, array $args, Parser $parser, PPFrame $frame) {
        $parser->disableCache();
        $output = NULL;
        $imagefound = false;
        while ($imagefound == false){
                $sql = 'SELECT DISTINCT(`il_to`) as `file`, `il_from` as `articleid` FROM `imagelinks` GROUP BY `il_to` ORDER BY RAND() LIMIT 1;'; 
                $image = mysql_fetch_assoc(mysql_query($sql));
 
                $sql = 'SELECT `page_title` as `title` FROM `page` WHERE `page_id` = '.$image['articleid'].' LIMIT 1;'; 
                $article = mysql_fetch_assoc(mysql_query($sql));
                $article['title'] = str_replace('_',' ',$article['title']);
 
                if (substr($image['file'],-4) == '.svg') $image['file'] .= '.png';
                $pfade[] = 'images/thumb/'.$image['file'].'/200px-'.$image['file'];
                $pfade[] = 'images/thumb/'.substr(md5($image['file']),0,1).'/'.substr(md5($image['file']),0,2).'/'.$image['file'].'/200px-'.$image['file'];
                foreach($pfade as $pfad){
                        if(file_exists($pfad)) {
 
                                $output .= '<div class="thumbinner" style="width: 202px;">';
                                $output .= '    <a href="/index.php?title=Datei:'.$image['file'].'" class="image">';
                                $output .= '            <img alt="" src="'.$pfad.'" class="thumbimage">';
                                $output .= '    </a>';
                                $output .= '    <div class="thumbcaption">';
                                $output .= '            <div class="magnify">';
                                $output .= '                    <a href="/index.php?title=Datei:'.$image['file'].'" class="internal" title="vergrößern">';
                                $output .= '                    <img src="/skins/common/images/magnify-clip.png" alt="" height="11" width="15">';
                                $output .= '                    </a>';
                                $output .= '            </div>';
                                $output .= '            Aus dem Artikel ';
                                $output .= '            <a href="/index.php?title='.$article['title'].'">';
                                $output .= $article['title'];
                                $output .= '            </a>';
                                $output .= '    </div>';
                                $output .= '</div>';
                                $imagefound = true;
                                continue;
                        }
                }
        }
        return  $output;
}
 
?>

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox