Open main menu

Extension:Mediawiki Coppermine Photo Gallery random photo

Wikimedia-logo-meta.png

This page was moved from MetaWiki.
It probably requires cleanup – please feel free to help out. In addition, some links on the page may be red; respective pages might be found at Meta. Remove this template once cleanup is complete.

This is the wiki page about Mediawiki Coppermine Photo Gallery random photo, an extension of Mediawiki. This extension can be downloaded from its home page and contains authoritative information about the project.

License: GNU GPL

Description: Shows random photo from Coppermine Gallery

Comments:

  • Need some cleaning (almost raw from dpLastPost),
  • Set your coding at the end of te code (return function).

Source codeEdit

<?php
# BASED on runphp Mediawiki Extension http://meta.wikimedia.org/wiki/Runphp
# BASED on dpLastPost from PostNuke

# To use extension type at your wiki: <galrand></galrand>

# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/galrand.php");

# Przemyslaw Stanislaw Knycz
# JID: djrzulf@kol.net.pl
# Written for http://czechowice.net/

$wgExtensionFunctions[] = "wfRunCoppermineRandom";

function wfRunCoppermineRandom() {
    global $wgParser;
    $wgParser->setHook( "galrand", "GCR" );
}


function GCR() {
        $ipb_path = "http://galeria.somewhere.at.net/";
        $ipb_table_prefix = "prefix";
        $ipb_dbhost = "localhost";
        $ipb_dbuser = "dbuser";
        $ipb_dbpass = "dbpass";
        $ipb_dbname = "dbname";

        $content = '';
        $db_link = mysql_connect($ipb_dbhost, $ipb_dbuser, $ipb_dbpass);
        $sql = "SELECT pid, aid, filepath, filename, hits, owner_id, owner_name, title FROM "
                . $ipb_table_prefix."_pictures WHERE approved='YES' ORDER BY RAND() DESC LIMIT 1";
        mysql_select_db( $ipb_dbname, $db_link );
        $result = mysql_db_query($ipb_dbname, $sql, $db_link);

        $content .= '<table align="center" width="100%" cellpadding="5" cellspacing="0" border="0">';
        while( $rows = mysql_fetch_object($result))
        {
                $filename = $rows->filename;
                $autor = $rows->owner_name;
                $autorid = $rows->owner_id;
                $title = $rows->title;

                $tid = $rows->pid;
                $replies = $rows->aid;

                $last_poster_id = $rows->owner_id;
                $forum_id = $rows->filepath;
                $last_post = $rows->aid;
                $views = $rows->hits;

                $content .= '<tr><td align="center" style="background-color: #F2ECE9; border: 1px solid  #FFFFFF;"><b>Fotka losowa</b><hr />'.$title.'<br /><br />';
                $linkthumb = $ipb_path.'albums/'.$forum_id.'thumb_'.rawurlencode($filename);
                $linknormal = $ipb_path.'displayimage.php?album=random&cat=0&pos=-'.$tid;
                $content .= '<a target="_BLANK" href="'.$linknormal.'"><img src="'.$linkthumb.'"></a><br />Dodał: <a href="http://gallery.somewhere.at.net/profile.php?uid='.$autorid.'">'.$autor.'</a><br />Obejrzeń: '.$views.'</td>';
                $content .= '</tr>';
        }
                        $content .= '</table>';

        return mb_convert_encoding($content,'UTF-8', 'ISO-8859-2');
}
?>


Virtualization BlogEdit

http://www.tricerat.com/blog If all computer networks were alike, triCerat wouldn’t exist to solve the mundane computer tasks that are necessary to keep today’s application delivery environments running. Virtualization Blog


I think this ist broken in a new mediawiki version. Info from another extension: At this stage it gets a bit tricky though due to the automatic caching of pages in MediaWiki. If you save a page with the source code above, the page will be created and placed in the cache with one of the lines in it. This will only change once the source code is changed again. To get around this, I invalidate every page that is older than one day (= 86400 seconds), this can be achieved by placing the following in LocalSettings.php:

require("includes/GlobalFunctions.php");
$wgCacheEpoch = wfTimestamp( TS_MW, time() - 86400 ); # 60*60*24 = 1 day

Of course it is possible to set this value to a lower number but keep in mind that this will have an impact on server load as pages are regenerated more often rather than pulled from cache.

PageEdit

http://www.czechowice.net/wiki/Mediawiki_Coppermine_Photo_Gallery_random_photo