Photo Album Scripts/SpecialSlideShow
From www.ChopStork.com
Sorry, this broke in the upgrade to 1.5.5. I may get to fixing if the weather goes bad; otherwise, I'm outside.
--Luke 23:51, 2 August 2006 (PDT)
<nowiki>
<?php
/**
*
* @package MediaWiki
* @subpackage SpecialPage
*/
/**
*
*/
require_once("QueryPage.php");
require_once("ImagePage.php");
/**
*
*/
function wfSpecialSlideShow() {
global $wgRequest;
$ss = new SlideShowPage($wgRequest);
return $ss->doQuery();
}
/**
*
* @package MediaWiki
* @subpackage SpecialPage
*/
class SlideShowPage extends QueryPage {
var $mLimit, $mOffset, $mCategory;
var $width, $height;
function SlideShowPage(&$request) {
#$this->mLimit = $request->getInt('limit',1);
$this->mLimit = 1;
$this->mOffset = $request->getInt('offset',0);
$this->mCategory = $request->getVal( 'cat', "" );
$this->width = $request->getInt('w',500);
$this->height = $request->getInt('h',500);
}
function getName() {
return "SlideShow";
}
function isExpensive() {
return false;
}
function isSyndicated() { return false; }
function getPageHeader($skin) {
if(strlen($this->mCategory)>0) {
$title = Title::makeTitle( NS_CATEGORY, $this->mCategory );
$link = $skin->makeKnownLinkObj( $title, str_replace ("_", " ", $this->mCategory) );
$header = "<p>Slide show of " . $link . ".</p>";
} else {
$header = "";
}
#return '<p>'.wfMsg('slideshowtext')."</p><br />\n";
return $header;
}
function getLink($skin, $text)
{
$options = "cat=" . str_replace (" ", "_", $this->mCategory);
$title = Title::makeTitle( NS_SPECIAL, $this->getName() );
return $skin->makeKnownLinkObj( $title, $text, $options );
}
function getOrder() {
if(strlen($this->mCategory)>0)
{
$order = " ORDER BY cl_to DESC , cl_sortkey ASC ";
} else {
$order = " ORDER BY cur_touched DESC, cl_to DESC , cl_sortkey ASC ";
}
return $order;
}
function getSQL() {
$dbr =& wfGetDB( DB_SLAVE );
$categorylinks = $dbr->tableName( 'categorylinks' );
# get table names for this installation
$cur = $dbr->tableName( 'cur' );
$catlinks = $dbr->tableName( 'categorylinks' );
$cond = "";
if(strlen($this->mCategory)>0)
{
$title = Title::makeTitle( NS_CATEGORY, $this->mCategory );
$cat = $dbr->addQuotes( $title->getDBKey() );
$cond = "cl_to LIKE $cat AND";
}
# db query statement
$sql = "SELECT * FROM $catlinks, $cur WHERE $cond cur_id = cl_from AND cur_namespace=" . NS_IMAGE . "";
return $sql;
}
function sortDescending() {
return true;
}
function formatResult( $skin, $result ) {
global $wgLang, $wgServer, $wgScript;
$fname = $this->getName();
$limit = $this->mLimit;
$offset = $this->mOffset;
$cat = $this->mCategory;
# Get image link
$imgTitle = Title::makeTitle( $result->cur_namespace, $result->cur_title );
$img = Image::newFromTitle( $imgTitle );
$thumb = $img->getThumbnail( $this->width, $this->height );
$imglink = $skin->makeKnownLinkObj( $imgTitle, $thumb->toHtml() );
# Get image edit link
$imgEditLink = $skin->makeKnownLinkObj( $imgTitle, "Add/Edit Comments", "action=edit" );
# Make sure a session has been started
@session_start();
# Set the redirect url
$localpage = "$wgScript?title=Special:$fname&limit=$limit&offset=$offset&cat=$cat";
$url = $wgServer . $localpage;
$_SESSION['redirectOnSave'][$result->cur_title] = $url;
# Get image content
$imgPage = new ImagePage( $imgTitle );
$content = $imgPage->getContent( true );
$content = $imgPage->getSection($content,0);
$content = wfParse($content);
if ( $thumb->width > $thumb->height )
{
$vpad = floor( ( $this->width + 20 - $thumb->width ) /2 ) - 2;
} else {
$vpad = floor( ( $this->height + 20 - $thumb->height ) /2 ) - 2;
}
#thumb tleft, floatnone
$s = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr>\n";
$s.= "<td width=\"50%\" valign=\"top\">\n";
$s.= " <div style=\"padding: .4em .9em .9em\">\n";
$s.= " <div class=\"floatnone\" style=\"padding: " . $vpad . "px; border: 1px solid #cccccc;\">";
$s.= " $imglink\n";
$s.= " </div>\n";
$s.= " </div>\n";
$s.= "</td>\n";
$s.= "<td width=\"50%\" valign=\"top\">\n";
$s.= " <p><b>$imgEditLink</b></p>\n";
$s.= " <div style=\"border: 1px solid #c6c9ff; color: #000; background-color: #f0f0ff; padding: .4em .9em .9em;\">\n";
$s.= " <p>$content</p>\n";
$s.= " </div>\n";
$s.= "</td>\n";
$s.= "</tr></table>\n";
return $s;
}
function doQuery() {
global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
global $wgMiserMode;
$offset = $this->mOffset;
$limit = $this->mLimit;
$sname = $this->getName();
$fname = get_class($this) . '::doQuery';
$sql = $this->getSQL();
$dbr =& wfGetDB( DB_SLAVE );
$wgOut->setSyndicated( $this->isSyndicated() );
#$wgOut->addWikiText( "<pre>". $sql . $this->getOrder() . $dbr->limitResult( $limit,$offset ) . "\n");
$res = $dbr->query( $sql . $this->getOrder(), $fname ); $total = $dbr->numRows($res);
$res = $dbr->query( $sql . $this->getOrder() . $dbr->limitResult( $limit,$offset ), $fname ); $num = $dbr->numRows($res);
$sk = $wgUser->getSkin( );
$wgOut->addHTML( $this->getPageHeader($sk) );
#$top = $this->wfShowingResults( $offset, $num);
#$wgOut->addHTML( "{$top}\n" );
# often disable 'next' link when we reach the end
if($num < $limit) { $atend = true; } else { $atend = false; }
$cat = str_replace (" ", "_", $this->mCategory);
$cond = "";
if(strlen($cat)>0) $cond = "cat=$cat";
$sl = $this->ViewPrevNext( $offset, $limit, $total, $wgContLang->specialPage( $sname ), $cond ,$atend );
$wgOut->addHTML( "
{$sl}
if ( $num > 0 ) {
$obj = $dbr->fetchObject( $res ); $format = $this->formatResult( $sk, $obj ); $s = ""; $s.=$format;
$wgOut->addHTML( $s );
$dbr->freeResult( $res );
}
$wgOut->addHTML( "
\n" );
{$sl}
\n" );}
function ViewPrevNext( $offset, $limit, $total, $link, $query = , $atend = false ) {
global $wgUser, $wgLang;
$fmtLimit = $wgLang->formatNum( $limit );
$prev = wfMsg( 'prevn', $fmtLimit );
$next = wfMsg( 'nextn', $fmtLimit );
if( is_object( $link ) ) { $title =& $link; } else { $title =& Title::newFromText( $link ); if( is_null( $title ) ) { return false; } }
$sk = $wgUser->getSkin(); if ( 0 != $offset ) { $po = $offset - $limit; if ( $po < 0 ) { $po = 0; } $q = "limit={$limit}&offset={$po}"; if ( != $query ) { $q .= '&'.$query; } $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$prev}</a>"; } else { $plink = $prev; }
$no = $offset + $limit; $q = 'limit='.$limit.'&offset='.$no; if ( != $query ) { $q .= '&'.$query; }
if ( $atend ) { $nlink = $next; } else { $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$next}</a>"; } #$nums = wfNumLink( $offset, 20, $title, $query ) . ' | ' . #wfNumLink( $offset, 50, $title, $query ) . ' | ' . #wfNumLink( $offset, 100, $title, $query ) . ' | ' . #wfNumLink( $offset, 250, $title, $query ) . ' | ' . #wfNumLink( $offset, 500, $title, $query );
$nums = "Image " . $offset+1 . " of $total";
return "View ($plink) ($nlink) ($nums)";
//return wfMsg( 'viewprevnext', $plink, $nlink, $nums ); }
}
?>
</nowiki></pre>

