<?php
-if ( !defined( 'MEDIAWIKI' ) )
- die( 1 );
-
/**
* Special handling for image description pages
*
*/
class ImagePage extends Article {
- /* private */ var $img; // Image object
+ /**
+ * @var File
+ */
+ /* private */ var $img;
+ /**
+ * @var File
+ */
/* private */ var $displayImg;
/* private */ var $repo;
/* private */ var $fileLoaded;
+
var $mExtraDescription = false;
var $dupes;
$this->dupes = null;
$this->repo = null;
}
-
+
+ /**
+ * @param $file File:
+ * @return void
+ */
public function setFile( $file ) {
$this->displayImg = $file;
$this->img = $file;
# Show shared description, if needed
if ( $this->mExtraDescription ) {
- $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
- if ( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
- $wgOut->addWikiText( $fol );
+ $fol = wfMessage( 'shareddescriptionfollows' );
+ if ( !$fol->isDisabled() ) {
+ $wgOut->addWikiText( $fol->plain() );
}
$wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
}
$wgOut->addHTML( $html );
if ( $showmeta ) {
- $expand = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-expand' ) ) );
- $collapse = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
$wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
$wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
$wgOut->addModules( array( 'mediawiki.legacy.metadata' ) );
- $wgOut->addHTML(
- "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
}
$css = $this->repo->getDescriptionStylesheetUrl();
}
return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
}
+
public function followRedirect() {
$this->loadFile();
if ( $this->img->isLocal() ) {
}
return Title::makeTitle( NS_FILE, $to );
}
+
public function isRedirect( $text = false ) {
$this->loadFile();
if ( $this->img->isLocal() )
return $this->dupes = $dupes;
}
-
/**
* Create the TOC
if ( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
return '';
}
- return Article::getContent();
+ return parent::getContent();
}
protected function openShowImage() {
$this->loadFile();
- $full_url = $this->displayImg->getURL();
$sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
if ( !isset( $wgImageLimits[$sizeSel] ) ) {
$sizeSel = User::getDefaultOption( 'imagesize' );
$height_orig = $this->displayImg->getHeight( $page );
$height = $height_orig;
- $showLink = false;
- $linkAttribs = array( 'href' => $full_url );
- $longDesc = $this->displayImg->getLongDesc();
+ $longDesc = wfMsg( 'parentheses', $this->displayImg->getLongDesc() );
wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$wgOut ) );
$thumbnail = $this->displayImg->transform( $params );
$showLink = true;
- if ( !$this->displayImg->mustRender() ) {
- $anchorclose = "<br />" . $msgsmall;
- }
+ $anchorclose = "<br />" . $msgsmall;
$isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
if ( $isMulti ) {
$wgOut->addHTML(
'</td><td><div class="multipageimagenavbox">' .
Xml::openElement( 'form', $formParams ) .
- Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
+ Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
Xml::submitButton( wfMsg( 'imgmultigo' ) ) .
Xml::closeElement( 'form' ) .
{
$nofile = 'filepage-nofile';
}
+ // Note, if there is an image description page, but
+ // no image, then this setRobotPolicy is overriden
+ // by Article::View().
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
+ if ( !$this->getID() ) {
+ // If there is no image, no shared image, and no description page,
+ // output a 404, to be consistent with articles.
+ $wgRequest->response()->header( "HTTP/1.x 404 Not Found" );
+ }
}
}
$descUrl = $this->img->getDescriptionUrl();
$descText = $this->img->getDescriptionText();
+ /* Add canonical to head if there is no local page for this shared file */
+ if( $descUrl && $this->getID() == 0 ) {
+ $wgOut->addLink( array( 'rel' => 'canonical', 'href' => $descUrl ) );
+ }
+
$wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
$repo = $this->img->getRepo()->getDisplayName();
protected function uploadLinksBox() {
global $wgUser, $wgOut, $wgEnableUploads, $wgUseExternalEditor;
- if ( !$wgEnableUploads ) { return; }
+ if ( !$wgEnableUploads ) {
+ return;
+ }
$this->loadFile();
if ( !$this->img->isLocal() )
$this->loadFile();
$pager = new ImageHistoryPseudoPager( $this );
$wgOut->addHTML( $pager->getBody() );
+ $wgOut->preventClickjacking( $pager->getPreventClickjacking() );
$this->img->resetHistory(); // free db resources
$sk = $wgUser->getSkin();
$count = 0;
$elements = array();
- while ( $s = $res->fetchObject() ) {
+ foreach ( $res as $s ) {
$count++;
if ( $count <= $limit ) {
// We have not yet reached the extra one that tells us there is more to fetch
$this->loadFile();
$dupes = $this->getDuplicates();
- if ( count( $dupes ) == 0 ) return;
+ if ( count( $dupes ) == 0 ) {
+ return;
+ }
$wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
$wgOut->addWikiMsg( 'duplicatesoffile',
$wgOut->addWikiText( $description );
}
-
/**
* Callback for usort() to do link sorts by (namespace, title)
* Function copied from Title::compare()
*/
class ImageHistoryList {
- protected $imagePage, $img, $skin, $title, $repo, $showThumb;
+ /**
+ * @var Title
+ */
+ protected $title;
+
+ /**
+ * @var File
+ */
+ protected $img;
+
+ /**
+ * @var ImagePage
+ */
+ protected $imagePage;
+
+ /**
+ * @var Skin
+ */
+ protected $skin;
+
+ protected $repo, $showThumb;
+ protected $preventClickjacking = false;
+ /**
+ * @param ImagePage $imagePage
+ */
public function __construct( $imagePage ) {
global $wgUser, $wgShowArchiveThumbnails;
$this->skin = $wgUser->getSkin();
return "</table>\n$navLinks\n</div>\n";
}
+ /**
+ * @param $iscur
+ * @param File $file
+ * @return string
+ */
public function imageHistoryLine( $iscur, $file ) {
global $wgUser, $wgLang;
# Don't link to unviewable files
$row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
} elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
+ $this->preventClickjacking();
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
# Make a link to review the image
$url = $this->skin->link(
}
$row .= '</td>';
+ $rowClass = null;
wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
$classAttr = $rowClass ? " class='$rowClass'" : "";
return "<tr{$classAttr}>{$row}</tr>\n";
}
+ /**
+ * @param File $file
+ * @return string
+ */
protected function getThumbForLine( $file ) {
global $wgLang;
return wfMsgHtml( 'filehist-nothumb' );
}
}
+
+ protected function preventClickjacking( $enable = true ) {
+ $this->preventClickjacking = $enable;
+ }
+
+ public function getPreventClickjacking() {
+ return $this->preventClickjacking;
+ }
}
class ImageHistoryPseudoPager extends ReverseChronologicalPager {
+ protected $preventClickjacking = false;
+
+ /**
+ * @var File
+ */
+ protected $mImg;
+
+ /**
+ * @var Title
+ */
+ protected $mTitle;
+
+ /**
+ * @param ImagePage $imagePage
+ */
function __construct( $imagePage ) {
parent::__construct();
$this->mImagePage = $imagePage;
$s .= $list->imageHistoryLine( !$file->isOld(), $file );
}
$s .= $list->endImageHistoryList( $navLink );
+
+ if ( $list->getPreventClickjacking() ) {
+ $this->preventClickjacking();
+ }
}
return $s;
}
}
$this->mQueryDone = true;
}
+
+ protected function preventClickjacking( $enable = true ) {
+ $this->preventClickjacking = $enable;
+ }
+
+ public function getPreventClickjacking() {
+ return $this->preventClickjacking;
+ }
+
}