2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2012-05-12 20:33:02 +00:00
|
|
|
/**
|
|
|
|
|
* Special handling for file description pages.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2017-02-19 05:03:13 +00:00
|
|
|
use Wikimedia\Rdbms\ResultWrapper;
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2011-06-29 22:09:51 +00:00
|
|
|
* Class for viewing MediaWiki file description pages
|
2007-04-24 06:53:31 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Media
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-09-01 09:59:53 +00:00
|
|
|
class ImagePage extends Article {
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var File */
|
2011-04-18 19:03:14 +00:00
|
|
|
private $displayImg;
|
2014-05-12 14:42:51 +00:00
|
|
|
|
|
|
|
|
/** @var FileRepo */
|
2011-04-18 19:03:14 +00:00
|
|
|
private $repo;
|
2014-05-12 14:42:51 +00:00
|
|
|
|
|
|
|
|
/** @var bool */
|
2011-04-18 19:03:14 +00:00
|
|
|
private $fileLoaded;
|
2011-03-05 17:01:33 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var bool */
|
|
|
|
|
protected $mExtraDescription = false;
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2016-02-02 16:48:20 +00:00
|
|
|
/**
|
|
|
|
|
* @var WikiFilePage
|
|
|
|
|
*/
|
|
|
|
|
protected $mPage;
|
|
|
|
|
|
2011-10-26 03:44:47 +00:00
|
|
|
/**
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param Title $title
|
2011-10-26 03:44:47 +00:00
|
|
|
* @return WikiFilePage
|
|
|
|
|
*/
|
2011-06-29 22:09:51 +00:00
|
|
|
protected function newPage( Title $title ) {
|
|
|
|
|
// Overload mPage with a file-specific page
|
|
|
|
|
return new WikiFilePage( $title );
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-15 15:49:52 +00:00
|
|
|
/**
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param File $file
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2010-11-15 15:49:52 +00:00
|
|
|
*/
|
2008-12-15 23:51:28 +00:00
|
|
|
public function setFile( $file ) {
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->mPage->setFile( $file );
|
2008-12-15 23:51:28 +00:00
|
|
|
$this->displayImg = $file;
|
|
|
|
|
$this->fileLoaded = true;
|
|
|
|
|
}
|
2008-05-23 09:03:49 +00:00
|
|
|
|
2008-05-20 03:26:59 +00:00
|
|
|
protected function loadFile() {
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $this->fileLoaded ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
return;
|
2008-05-20 03:26:59 +00:00
|
|
|
}
|
2008-05-23 09:03:49 +00:00
|
|
|
$this->fileLoaded = true;
|
|
|
|
|
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->displayImg = $img = false;
|
2016-12-25 23:55:27 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] );
|
2011-06-29 22:09:51 +00:00
|
|
|
if ( !$img ) { // not set by hook?
|
|
|
|
|
$img = wfFindFile( $this->getTitle() );
|
|
|
|
|
if ( !$img ) {
|
|
|
|
|
$img = wfLocalFile( $this->getTitle() );
|
2008-05-21 22:20:07 +00:00
|
|
|
}
|
2008-05-23 09:03:49 +00:00
|
|
|
}
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->mPage->setFile( $img );
|
|
|
|
|
if ( !$this->displayImg ) { // not set by hook?
|
|
|
|
|
$this->displayImg = $img;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->repo = $img->getRepo();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-13 00:29:20 +00:00
|
|
|
/**
|
|
|
|
|
* Handler for action=render
|
|
|
|
|
* Include body text only; none of the image extras
|
|
|
|
|
*/
|
2008-11-28 14:29:25 +00:00
|
|
|
public function render() {
|
2012-09-05 19:22:14 +00:00
|
|
|
$this->getContext()->getOutput()->setArticleBodyOnly( true );
|
|
|
|
|
parent::view();
|
2005-07-03 04:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-28 14:29:25 +00:00
|
|
|
public function view() {
|
2012-04-30 14:43:03 +00:00
|
|
|
global $wgShowEXIF;
|
2010-06-09 21:09:13 +00:00
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
|
|
|
|
$request = $this->getContext()->getRequest();
|
|
|
|
|
$diff = $request->getVal( 'diff' );
|
2014-05-12 14:42:51 +00:00
|
|
|
$diffOnly = $request->getBool(
|
|
|
|
|
'diffonly',
|
|
|
|
|
$this->getContext()->getUser()->getOption( 'diffonly' )
|
|
|
|
|
);
|
2010-06-09 21:09:13 +00:00
|
|
|
|
2013-03-10 15:23:46 +00:00
|
|
|
if ( $this->getTitle()->getNamespace() != NS_FILE || ( $diff !== null && $diffOnly ) ) {
|
2012-04-27 15:40:14 +00:00
|
|
|
parent::view();
|
|
|
|
|
return;
|
2010-06-09 21:09:13 +00:00
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2004-01-12 00:55:01 +00:00
|
|
|
|
2011-06-29 22:09:51 +00:00
|
|
|
if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) {
|
2013-03-10 15:23:46 +00:00
|
|
|
if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || $diff !== null ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$request->setVal( 'diffonly', 'true' );
|
2008-05-11 19:49:08 +00:00
|
|
|
}
|
2017-01-26 13:43:19 +00:00
|
|
|
|
|
|
|
|
parent::view();
|
|
|
|
|
return;
|
2008-05-11 19:49:08 +00:00
|
|
|
}
|
2008-05-08 20:55:13 +00:00
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $wgShowEXIF && $this->displayImg->exists() ) {
|
2011-05-17 22:03:20 +00:00
|
|
|
// @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
|
2014-12-28 20:31:34 +00:00
|
|
|
$formattedMetadata = $this->displayImg->formatMetadata( $this->getContext() );
|
2007-07-28 01:15:35 +00:00
|
|
|
$showmeta = $formattedMetadata !== false;
|
2007-01-17 05:01:54 +00:00
|
|
|
} else {
|
|
|
|
|
$showmeta = false;
|
|
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2011-04-02 14:50:31 +00:00
|
|
|
if ( !$diff && $this->displayImg->exists() ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( $this->showTOC( $showmeta ) );
|
2011-04-02 14:50:31 +00:00
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2011-04-02 14:50:31 +00:00
|
|
|
if ( !$diff ) {
|
2009-01-02 19:11:34 +00:00
|
|
|
$this->openShowImage();
|
2011-04-02 14:50:31 +00:00
|
|
|
}
|
2005-07-04 02:59:23 +00:00
|
|
|
|
2007-01-17 05:01:54 +00:00
|
|
|
# No need to display noarticletext, we use our own message, output in openShowImage()
|
2016-03-19 00:08:06 +00:00
|
|
|
if ( $this->mPage->getId() ) {
|
2011-07-06 02:26:06 +00:00
|
|
|
# NS_FILE is in the user language, but this section (the actual wikitext)
|
|
|
|
|
# should be in page content language
|
2012-09-05 15:50:13 +00:00
|
|
|
$pageLang = $this->getTitle()->getPageViewLanguage();
|
2016-02-17 09:09:32 +00:00
|
|
|
$out->addHTML( Xml::openElement( 'div', [ 'id' => 'mw-imagepage-content',
|
2012-06-02 18:46:21 +00:00
|
|
|
'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
|
2016-02-17 09:09:32 +00:00
|
|
|
'class' => 'mw-content-' . $pageLang->getDir() ] ) );
|
2012-03-30 12:47:05 +00:00
|
|
|
|
2012-06-12 09:11:37 +00:00
|
|
|
parent::view();
|
2012-03-30 12:47:05 +00:00
|
|
|
|
2012-06-12 09:11:37 +00:00
|
|
|
$out->addHTML( Xml::closeElement( 'div' ) );
|
2007-01-17 05:01:54 +00:00
|
|
|
} else {
|
|
|
|
|
# Just need to set the right headers
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->setArticleFlag( true );
|
|
|
|
|
$out->setPageTitle( $this->getTitle()->getPrefixedText() );
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
$this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() );
|
2007-01-17 05:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Show shared description, if needed
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $this->mExtraDescription ) {
|
2014-12-17 22:49:11 +00:00
|
|
|
$fol = $this->getContext()->msg( 'shareddescriptionfollows' );
|
2011-01-14 10:51:05 +00:00
|
|
|
if ( !$fol->isDisabled() ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addWikiText( $fol->plain() );
|
2007-01-17 05:01:54 +00:00
|
|
|
}
|
2012-09-05 19:22:14 +00:00
|
|
|
$out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
|
2007-01-17 05:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->closeShowImage();
|
|
|
|
|
$this->imageHistory();
|
2008-05-14 15:11:48 +00:00
|
|
|
// TODO: Cleanup the following
|
2010-03-20 22:58:48 +00:00
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( Xml::element( 'h2',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'filelinks' ],
|
2014-12-17 22:49:11 +00:00
|
|
|
$this->getContext()->msg( 'imagelinks' )->text() ) . "\n" );
|
2008-05-14 15:11:48 +00:00
|
|
|
$this->imageDupes();
|
2011-05-17 22:03:20 +00:00
|
|
|
# @todo FIXME: For some freaky reason, we can't redirect to foreign images.
|
2009-02-25 22:18:44 +00:00
|
|
|
# Yet we return metadata about the target. Definitely an issue in the FileRepo
|
2008-05-15 19:17:21 +00:00
|
|
|
$this->imageLinks();
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2009-11-07 09:31:16 +00:00
|
|
|
# Allow extensions to add something after the image links
|
|
|
|
|
$html = '';
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'ImagePageAfterImageLinks', [ $this, &$html ] );
|
2011-04-02 14:50:31 +00:00
|
|
|
if ( $html ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( $html );
|
2011-04-02 14:50:31 +00:00
|
|
|
}
|
2007-01-17 05:01:54 +00:00
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $showmeta ) {
|
2012-08-29 08:07:10 +00:00
|
|
|
$out->addHTML( Xml::element(
|
|
|
|
|
'h2',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'metadata' ],
|
2014-12-17 22:49:11 +00:00
|
|
|
$this->getContext()->msg( 'metadata' )->text() ) . "\n" );
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$out->addModules( [ 'mediawiki.action.view.metadata' ] );
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2011-06-29 00:08:25 +00:00
|
|
|
|
|
|
|
|
// Add remote Filepage.css
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$this->repo->isLocal() ) {
|
2011-06-29 00:08:25 +00:00
|
|
|
$css = $this->repo->getDescriptionStylesheetUrl();
|
|
|
|
|
if ( $css ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addStyle( $css );
|
2011-06-29 00:08:25 +00:00
|
|
|
}
|
2010-07-02 19:54:46 +00:00
|
|
|
}
|
2015-09-02 16:21:06 +00:00
|
|
|
|
2016-07-07 05:22:14 +00:00
|
|
|
$out->addModuleStyles( [
|
2017-02-20 22:44:19 +00:00
|
|
|
'filepage', // always show the local local Filepage.css, T31277
|
2016-07-07 05:22:14 +00:00
|
|
|
'mediawiki.action.view.filepage', // Add MediaWiki styles for a file page
|
|
|
|
|
] );
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2011-03-05 17:01:33 +00:00
|
|
|
|
2011-10-29 01:53:28 +00:00
|
|
|
/**
|
|
|
|
|
* @return File
|
|
|
|
|
*/
|
2008-05-21 21:33:58 +00:00
|
|
|
public function getDisplayedFile() {
|
|
|
|
|
$this->loadFile();
|
|
|
|
|
return $this->displayImg;
|
|
|
|
|
}
|
2005-04-29 19:45:49 +00:00
|
|
|
|
2005-05-05 02:39:21 +00:00
|
|
|
/**
|
|
|
|
|
* Create the TOC
|
|
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param bool $metadata Whether or not to show the metadata link
|
|
|
|
|
* @return string
|
2005-05-05 02:39:21 +00:00
|
|
|
*/
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function showTOC( $metadata ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$r = [
|
2014-12-17 22:49:11 +00:00
|
|
|
'<li><a href="#file">' . $this->getContext()->msg( 'file-anchor-link' )->escaped() . '</a></li>',
|
|
|
|
|
'<li><a href="#filehistory">' . $this->getContext()->msg( 'filehist' )->escaped() . '</a></li>',
|
|
|
|
|
'<li><a href="#filelinks">' . $this->getContext()->msg( 'imagelinks' )->escaped() . '</a></li>',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-12-29 15:02:45 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'ImagePageShowTOC', [ $this, &$r ] );
|
2014-12-29 15:02:45 +00:00
|
|
|
|
2009-11-08 11:09:20 +00:00
|
|
|
if ( $metadata ) {
|
2015-09-26 09:58:36 +00:00
|
|
|
$r[] = '<li><a href="#metadata">' .
|
|
|
|
|
$this->getContext()->msg( 'metadata' )->escaped() .
|
|
|
|
|
'</a></li>';
|
2009-11-08 11:09:20 +00:00
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2009-11-08 11:09:20 +00:00
|
|
|
return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
|
2005-04-29 19:45:49 +00:00
|
|
|
}
|
2005-04-21 11:28:56 +00:00
|
|
|
|
2005-05-05 02:39:21 +00:00
|
|
|
/**
|
|
|
|
|
* Make a table with metadata to be shown in the output page.
|
|
|
|
|
*
|
2011-05-17 22:03:20 +00:00
|
|
|
* @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param array $metadata The array containing the Exif data
|
|
|
|
|
* @return string The metadata table. This is treated as Wikitext (!)
|
2005-05-05 02:39:21 +00:00
|
|
|
*/
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function makeMetadataTable( $metadata ) {
|
2009-05-25 14:02:54 +00:00
|
|
|
$r = "<div class=\"mw-imagepage-section-metadata\">";
|
2014-12-17 22:49:11 +00:00
|
|
|
$r .= $this->getContext()->msg( 'metadata-help' )->plain();
|
2009-03-28 16:41:00 +00:00
|
|
|
$r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
|
2007-07-28 01:15:35 +00:00
|
|
|
foreach ( $metadata as $type => $stuff ) {
|
2007-08-21 03:57:54 +00:00
|
|
|
foreach ( $stuff as $v ) {
|
2017-06-30 00:13:12 +00:00
|
|
|
$class = str_replace( ' ', '_', $v['id'] );
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $type == 'collapsed' ) {
|
2014-08-28 17:50:59 +00:00
|
|
|
// Handled by mediawiki.action.view.metadata module.
|
2013-12-06 21:36:26 +00:00
|
|
|
$class .= ' collapsable';
|
2007-07-28 01:15:35 +00:00
|
|
|
}
|
2017-06-30 00:13:12 +00:00
|
|
|
$r .= Html::rawElement( 'tr',
|
|
|
|
|
[ 'class' => $class ],
|
|
|
|
|
Html::rawElement( 'th', [], $v['name'] )
|
|
|
|
|
. Html::rawElement( 'td', [], $v['value'] )
|
|
|
|
|
);
|
2005-11-28 23:56:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-03-28 16:41:00 +00:00
|
|
|
$r .= "</table>\n</div>\n";
|
2005-11-28 23:56:35 +00:00
|
|
|
return $r;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2012-06-19 01:28:05 +00:00
|
|
|
/**
|
|
|
|
|
* Overloading Article's getContentObject method.
|
|
|
|
|
*
|
|
|
|
|
* Omit noarticletext if sharedupload; text will be fetched from the
|
|
|
|
|
* shared upload server if possible.
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getContentObject() {
|
|
|
|
|
$this->loadFile();
|
2016-03-19 00:08:06 +00:00
|
|
|
if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getId() ) {
|
2012-06-19 01:28:05 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return parent::getContentObject();
|
|
|
|
|
}
|
2005-05-20 22:41:17 +00:00
|
|
|
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function openShowImage() {
|
2015-07-19 11:26:58 +00:00
|
|
|
global $wgEnableUploads, $wgSend404Code, $wgSVGMaxSize;
|
2005-12-04 18:27:59 +00:00
|
|
|
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
|
|
|
|
$user = $this->getContext()->getUser();
|
|
|
|
|
$lang = $this->getContext()->getLanguage();
|
|
|
|
|
$dirmark = $lang->getDirMarkEntity();
|
|
|
|
|
$request = $this->getContext()->getRequest();
|
2008-05-20 03:26:59 +00:00
|
|
|
|
2013-02-02 13:48:33 +00:00
|
|
|
$max = $this->getImageLimitsFromOption( $user, 'imagesize' );
|
2004-12-21 03:21:41 +00:00
|
|
|
$maxWidth = $max[0];
|
|
|
|
|
$maxHeight = $max[1];
|
2004-01-12 00:55:01 +00:00
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $this->displayImg->exists() ) {
|
2005-05-21 07:46:17 +00:00
|
|
|
# image
|
2012-04-30 14:43:03 +00:00
|
|
|
$page = $request->getIntOrNull( 'page' );
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( is_null( $page ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [];
|
2006-08-13 17:34:48 +00:00
|
|
|
$page = 1;
|
2007-04-20 12:31:36 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [ 'page' => $page ];
|
2006-08-13 17:34:48 +00:00
|
|
|
}
|
2013-05-24 12:56:06 +00:00
|
|
|
|
|
|
|
|
$renderLang = $request->getVal( 'lang' );
|
|
|
|
|
if ( !is_null( $renderLang ) ) {
|
2013-12-14 18:48:46 +00:00
|
|
|
$handler = $this->displayImg->getHandler();
|
|
|
|
|
if ( $handler && $handler->validateParam( 'lang', $renderLang ) ) {
|
|
|
|
|
$params['lang'] = $renderLang;
|
|
|
|
|
} else {
|
|
|
|
|
$renderLang = null;
|
|
|
|
|
}
|
2013-05-24 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 14:35:20 +00:00
|
|
|
$width_orig = $this->displayImg->getWidth( $page );
|
2007-02-27 18:27:11 +00:00
|
|
|
$width = $width_orig;
|
2010-07-19 14:35:20 +00:00
|
|
|
$height_orig = $this->displayImg->getHeight( $page );
|
2007-02-27 18:27:11 +00:00
|
|
|
$height = $height_orig;
|
2010-10-14 20:53:04 +00:00
|
|
|
|
2012-11-12 19:52:27 +00:00
|
|
|
$filename = wfEscapeWikiText( $this->displayImg->getName() );
|
|
|
|
|
$linktext = $filename;
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2017-02-01 04:01:54 +00:00
|
|
|
// Avoid PHP 7.1 warning from passing $this by reference
|
2016-12-25 23:55:27 +00:00
|
|
|
$imagePage = $this;
|
|
|
|
|
|
|
|
|
|
Hooks::run( 'ImageOpenShowImageInlineBefore', [ &$imagePage, &$out ] );
|
2007-05-16 19:52:22 +00:00
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $this->displayImg->allowInlineDisplay() ) {
|
2004-01-16 18:11:47 +00:00
|
|
|
# image
|
2005-04-29 19:45:49 +00:00
|
|
|
# "Download high res version" link below the image
|
2014-12-17 22:49:11 +00:00
|
|
|
# $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
|
2014-05-12 14:42:51 +00:00
|
|
|
# Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
|
2005-12-04 08:52:01 +00:00
|
|
|
# We'll show a thumbnail of this image
|
2014-05-22 17:44:43 +00:00
|
|
|
if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
|
|
|
|
|
list( $width, $height ) = $this->getDisplayWidthHeight(
|
|
|
|
|
$maxWidth, $maxHeight, $width, $height
|
|
|
|
|
);
|
2014-12-17 22:49:11 +00:00
|
|
|
$linktext = $this->getContext()->msg( 'show-big-image' )->escaped();
|
2014-05-22 17:44:43 +00:00
|
|
|
|
2015-07-19 11:26:58 +00:00
|
|
|
$thumbSizes = $this->getThumbSizes( $width_orig, $height_orig );
|
2012-05-20 05:07:09 +00:00
|
|
|
# Generate thumbnails or thumbnail links as needed...
|
2016-02-17 09:09:32 +00:00
|
|
|
$otherSizes = [];
|
2012-05-20 05:07:09 +00:00
|
|
|
foreach ( $thumbSizes as $size ) {
|
2013-09-28 18:53:20 +00:00
|
|
|
// We include a thumbnail size in the list, if it is
|
|
|
|
|
// less than or equal to the original size of the image
|
|
|
|
|
// asset ($width_orig/$height_orig). We also exclude
|
|
|
|
|
// the current thumbnail's size ($width/$height)
|
|
|
|
|
// since that is added to the message separately, so
|
|
|
|
|
// it can be denoted as the current size being shown.
|
2015-07-19 11:26:58 +00:00
|
|
|
// Vectorized images are limited by $wgSVGMaxSize big,
|
|
|
|
|
// so all thumbs less than or equal that are shown.
|
2014-07-19 21:12:10 +00:00
|
|
|
if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
|
2015-07-19 11:26:58 +00:00
|
|
|
|| ( $this->displayImg->isVectorized()
|
|
|
|
|
&& max( $size[0], $size[1] ) <= $wgSVGMaxSize )
|
|
|
|
|
)
|
2013-12-01 20:39:00 +00:00
|
|
|
&& $size[0] != $width && $size[1] != $height
|
|
|
|
|
) {
|
2013-02-02 11:29:49 +00:00
|
|
|
$sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
|
|
|
|
|
if ( $sizeLink ) {
|
|
|
|
|
$otherSizes[] = $sizeLink;
|
|
|
|
|
}
|
2011-10-15 21:40:30 +00:00
|
|
|
}
|
2011-03-12 22:49:31 +00:00
|
|
|
}
|
2013-09-28 18:53:20 +00:00
|
|
|
$otherSizes = array_unique( $otherSizes );
|
2014-05-22 17:44:43 +00:00
|
|
|
|
2013-02-02 11:29:49 +00:00
|
|
|
$sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
|
2015-07-19 08:16:23 +00:00
|
|
|
$msgsmall = $this->getThumbPrevText( $params, $sizeLinkBigImagePreview );
|
2012-05-20 05:07:09 +00:00
|
|
|
if ( count( $otherSizes ) ) {
|
2012-01-27 22:44:46 +00:00
|
|
|
$msgsmall .= ' ' .
|
2015-09-26 09:58:36 +00:00
|
|
|
Html::rawElement(
|
|
|
|
|
'span',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-filepage-other-resolutions' ],
|
2015-09-26 09:58:36 +00:00
|
|
|
$this->getContext()->msg( 'show-big-image-other' )
|
|
|
|
|
->rawParams( $lang->pipeList( $otherSizes ) )
|
|
|
|
|
->params( count( $otherSizes ) )
|
|
|
|
|
->parse()
|
2011-09-12 12:46:20 +00:00
|
|
|
);
|
2012-01-27 22:44:46 +00:00
|
|
|
}
|
2013-01-26 18:32:03 +00:00
|
|
|
} elseif ( $width == 0 && $height == 0 ) {
|
2011-11-11 15:59:40 +00:00
|
|
|
# Some sort of audio file that doesn't have dimensions
|
|
|
|
|
# Don't output a no hi res message for such a file
|
|
|
|
|
$msgsmall = '';
|
2007-04-27 22:04:01 +00:00
|
|
|
} else {
|
|
|
|
|
# Image is small enough to show full size on image page
|
2014-12-17 22:49:11 +00:00
|
|
|
$msgsmall = $this->getContext()->msg( 'file-nohires' )->parse();
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
2007-04-27 22:04:01 +00:00
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
$params['width'] = $width;
|
2011-03-12 22:49:31 +00:00
|
|
|
$params['height'] = $height;
|
2008-05-21 21:33:58 +00:00
|
|
|
$thumbnail = $this->displayImg->transform( $params );
|
2013-11-20 02:48:58 +00:00
|
|
|
Linker::processResponsiveImages( $this->displayImg, $thumbnail, $params );
|
2005-12-04 08:52:01 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
$anchorclose = Html::rawElement(
|
|
|
|
|
'div',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-filepage-resolutioninfo' ],
|
2014-05-12 14:42:51 +00:00
|
|
|
$msgsmall
|
|
|
|
|
);
|
2006-08-13 17:34:48 +00:00
|
|
|
|
2009-12-04 11:33:50 +00:00
|
|
|
$isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $isMulti ) {
|
2013-05-02 17:41:40 +00:00
|
|
|
$out->addModules( 'mediawiki.page.image.pagination' );
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( '<table class="multipageimage"><tr><td>' );
|
2006-08-13 17:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $thumbnail ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$options = [
|
2008-05-21 21:33:58 +00:00
|
|
|
'alt' => $this->displayImg->getTitle()->getPrefixedText(),
|
2011-10-15 21:40:30 +00:00
|
|
|
'file-link' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( '<div class="fullImageLink" id="file">' .
|
2007-08-31 02:51:23 +00:00
|
|
|
$thumbnail->toHtml( $options ) .
|
2009-03-28 16:41:00 +00:00
|
|
|
$anchorclose . "</div>\n" );
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
2006-08-13 17:34:48 +00:00
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $isMulti ) {
|
2008-05-21 21:33:58 +00:00
|
|
|
$count = $this->displayImg->pageCount();
|
2007-01-26 12:00:04 +00:00
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $page > 1 ) {
|
2017-05-29 13:22:03 +00:00
|
|
|
$label = $this->getContext()->msg( 'imgmultipageprev' )->text();
|
2014-06-27 00:15:03 +00:00
|
|
|
// on the client side, this link is generated in ajaxifyPageNavigation()
|
|
|
|
|
// in the mediawiki.page.image.pagination module
|
2012-07-11 07:18:07 +00:00
|
|
|
$link = Linker::linkKnown(
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->getTitle(),
|
2009-06-06 22:42:48 +00:00
|
|
|
$label,
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'page' => $page - 1 ]
|
2009-06-06 22:42:48 +00:00
|
|
|
);
|
2014-05-12 14:42:51 +00:00
|
|
|
$thumb1 = Linker::makeThumbLinkObj(
|
|
|
|
|
$this->getTitle(),
|
|
|
|
|
$this->displayImg,
|
|
|
|
|
$link,
|
|
|
|
|
$label,
|
|
|
|
|
'none',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page' => $page - 1 ]
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2007-01-26 12:00:04 +00:00
|
|
|
} else {
|
|
|
|
|
$thumb1 = '';
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $page < $count ) {
|
2014-12-17 22:49:11 +00:00
|
|
|
$label = $this->getContext()->msg( 'imgmultipagenext' )->text();
|
2012-07-11 07:18:07 +00:00
|
|
|
$link = Linker::linkKnown(
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->getTitle(),
|
2009-06-06 22:42:48 +00:00
|
|
|
$label,
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'page' => $page + 1 ]
|
2009-06-06 22:42:48 +00:00
|
|
|
);
|
2014-05-12 14:42:51 +00:00
|
|
|
$thumb2 = Linker::makeThumbLinkObj(
|
|
|
|
|
$this->getTitle(),
|
|
|
|
|
$this->displayImg,
|
|
|
|
|
$link,
|
|
|
|
|
$label,
|
|
|
|
|
'none',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page' => $page + 1 ]
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2007-01-26 12:00:04 +00:00
|
|
|
} else {
|
|
|
|
|
$thumb2 = '';
|
2006-08-13 17:34:48 +00:00
|
|
|
}
|
2007-01-26 12:00:04 +00:00
|
|
|
|
2007-01-26 12:10:06 +00:00
|
|
|
global $wgScript;
|
2008-05-10 11:56:02 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$formParams = [
|
2008-05-10 11:56:02 +00:00
|
|
|
'name' => 'pageselector',
|
|
|
|
|
'action' => $wgScript,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
|
|
|
|
$options = [];
|
2010-03-20 22:58:48 +00:00
|
|
|
for ( $i = 1; $i <= $count; $i++ ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
|
2007-01-26 12:00:04 +00:00
|
|
|
}
|
2008-05-10 11:56:02 +00:00
|
|
|
$select = Xml::tags( 'select',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'pageselector', 'name' => 'page' ],
|
2008-05-10 11:56:02 +00:00
|
|
|
implode( "\n", $options ) );
|
|
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML(
|
2008-05-10 11:56:02 +00:00
|
|
|
'</td><td><div class="multipageimagenavbox">' .
|
|
|
|
|
Xml::openElement( 'form', $formParams ) .
|
2011-04-02 14:50:31 +00:00
|
|
|
Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
|
2014-12-17 22:49:11 +00:00
|
|
|
$this->getContext()->msg( 'imgmultigoto' )->rawParams( $select )->parse() .
|
2017-04-25 14:41:51 +00:00
|
|
|
$this->getContext()->msg( 'word-separator' )->escaped() .
|
2014-12-17 22:49:11 +00:00
|
|
|
Xml::submitButton( $this->getContext()->msg( 'imgmultigo' )->text() ) .
|
2008-05-10 11:56:02 +00:00
|
|
|
Xml::closeElement( 'form' ) .
|
2011-11-20 18:57:59 +00:00
|
|
|
"<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
|
2008-05-10 11:56:02 +00:00
|
|
|
);
|
2006-08-13 17:34:48 +00:00
|
|
|
}
|
2012-11-12 19:52:27 +00:00
|
|
|
} elseif ( $this->displayImg->isSafeFile() ) {
|
2010-03-20 22:58:48 +00:00
|
|
|
# if direct link is allowed but it's not a renderable image, show an icon.
|
2012-11-12 19:52:27 +00:00
|
|
|
$icon = $this->displayImg->iconThumb();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2012-11-12 19:52:27 +00:00
|
|
|
$out->addHTML( '<div class="fullImageLink" id="file">' .
|
2016-02-17 09:09:32 +00:00
|
|
|
$icon->toHtml( [ 'file-link' => true ] ) .
|
2012-11-12 19:52:27 +00:00
|
|
|
"</div>\n" );
|
2004-01-16 18:11:47 +00:00
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2014-12-17 22:49:11 +00:00
|
|
|
$longDesc = $this->getContext()->msg( 'parentheses', $this->displayImg->getLongDesc() )->text();
|
2012-11-12 19:52:27 +00:00
|
|
|
|
2015-03-05 18:52:11 +00:00
|
|
|
$handler = $this->displayImg->getHandler();
|
|
|
|
|
|
|
|
|
|
// If this is a filetype with potential issues, warn the user.
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
$warningConfig = $handler->getWarningConfig( $this->displayImg );
|
|
|
|
|
|
|
|
|
|
if ( $warningConfig !== null ) {
|
|
|
|
|
// The warning will be displayed via CSS and JavaScript.
|
|
|
|
|
// We just need to tell the client side what message to use.
|
|
|
|
|
$output = $this->getContext()->getOutput();
|
|
|
|
|
$output->addJsConfigVars( 'wgFileWarning', $warningConfig );
|
|
|
|
|
$output->addModules( $warningConfig['module'] );
|
|
|
|
|
$output->addModules( 'mediawiki.filewarning' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-12 19:52:27 +00:00
|
|
|
$medialink = "[[Media:$filename|$linktext]]";
|
|
|
|
|
|
|
|
|
|
if ( !$this->displayImg->isSafeFile() ) {
|
2014-12-17 22:49:11 +00:00
|
|
|
$warning = $this->getContext()->msg( 'mediawarning' )->plain();
|
2012-11-12 19:52:27 +00:00
|
|
|
// dirmark is needed here to separate the file name, which
|
|
|
|
|
// most likely ends in Latin characters, from the description,
|
|
|
|
|
// which may begin with the file type. In RTL environment
|
|
|
|
|
// this will get messy.
|
|
|
|
|
// The dirmark, however, must not be immediately adjacent
|
|
|
|
|
// to the filename, because it can get copied with it.
|
2017-02-20 22:44:19 +00:00
|
|
|
// See T27277.
|
2014-05-12 14:42:51 +00:00
|
|
|
// @codingStandardsIgnoreStart Ignore long line
|
2012-11-12 19:52:27 +00:00
|
|
|
$out->addWikiText( <<<EOT
|
2012-03-29 19:17:06 +00:00
|
|
|
<div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
|
2005-08-12 04:44:43 +00:00
|
|
|
<div class="mediaWarning">$warning</div>
|
2007-05-30 21:02:32 +00:00
|
|
|
EOT
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
|
|
|
|
// @codingStandardsIgnoreEnd
|
2012-11-12 19:52:27 +00:00
|
|
|
} else {
|
|
|
|
|
$out->addWikiText( <<<EOT
|
2012-03-29 19:17:06 +00:00
|
|
|
<div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
|
2005-08-12 04:44:43 +00:00
|
|
|
</div>
|
2007-05-30 21:02:32 +00:00
|
|
|
EOT
|
2012-11-12 19:52:27 +00:00
|
|
|
);
|
2005-05-21 07:46:17 +00:00
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2013-11-16 01:47:51 +00:00
|
|
|
$renderLangOptions = $this->displayImg->getAvailableLanguages();
|
|
|
|
|
if ( count( $renderLangOptions ) >= 1 ) {
|
|
|
|
|
$currentLanguage = $renderLang;
|
|
|
|
|
$defaultLang = $this->displayImg->getDefaultRenderLanguage();
|
|
|
|
|
if ( is_null( $currentLanguage ) ) {
|
|
|
|
|
$currentLanguage = $defaultLang;
|
|
|
|
|
}
|
2016-03-19 00:08:06 +00:00
|
|
|
$out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) );
|
2013-11-16 01:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-29 08:07:10 +00:00
|
|
|
// Add cannot animate thumbnail warning
|
|
|
|
|
if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
|
|
|
|
|
// Include the extension so wiki admins can
|
|
|
|
|
// customize it on a per file-type basis
|
|
|
|
|
// (aka say things like use format X instead).
|
|
|
|
|
// additionally have a specific message for
|
|
|
|
|
// file-no-thumb-animation-gif
|
|
|
|
|
$ext = $this->displayImg->getExtension();
|
|
|
|
|
$noAnimMesg = wfMessageFallback(
|
|
|
|
|
'file-no-thumb-animation-' . $ext,
|
|
|
|
|
'file-no-thumb-animation'
|
|
|
|
|
)->plain();
|
|
|
|
|
|
|
|
|
|
$out->addWikiText( <<<EOT
|
|
|
|
|
<div class="mw-noanimatethumb">{$noAnimMesg}</div>
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( !$this->displayImg->isLocal() ) {
|
2005-07-03 04:40:07 +00:00
|
|
|
$this->printSharedImageText();
|
2004-10-21 05:04:14 +00:00
|
|
|
}
|
2005-04-17 08:30:15 +00:00
|
|
|
} else {
|
|
|
|
|
# Image does not exist
|
2016-03-19 00:08:06 +00:00
|
|
|
if ( !$this->getId() ) {
|
2017-02-22 17:55:56 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
|
|
2012-03-02 01:02:41 +00:00
|
|
|
# No article exists either
|
|
|
|
|
# Show deletion log to be consistent with normal articles
|
|
|
|
|
LogEventsList::showLogExtract(
|
2012-04-30 14:43:03 +00:00
|
|
|
$out,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'delete', 'move' ],
|
2012-03-02 01:02:41 +00:00
|
|
|
$this->getTitle()->getPrefixedText(),
|
|
|
|
|
'',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'lim' => 10,
|
2017-02-22 17:55:56 +00:00
|
|
|
'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
|
2012-03-02 01:02:41 +00:00
|
|
|
'showIfEmpty' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'msgKey' => [ 'moveddeleted-notice' ]
|
|
|
|
|
]
|
2012-03-02 01:02:41 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
|
2009-05-24 20:45:31 +00:00
|
|
|
// Only show an upload link if the user can upload
|
2009-05-25 13:53:48 +00:00
|
|
|
$uploadTitle = SpecialPage::getTitleFor( 'Upload' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$nofile = [
|
2009-05-25 13:53:48 +00:00
|
|
|
'filepage-nofile-link',
|
2016-02-17 09:09:32 +00:00
|
|
|
$uploadTitle->getFullURL( [ 'wpDestFile' => $this->mPage->getFile()->getName() ] )
|
|
|
|
|
];
|
2011-04-02 14:50:31 +00:00
|
|
|
} else {
|
2009-06-15 13:20:40 +00:00
|
|
|
$nofile = 'filepage-nofile';
|
2009-05-24 20:45:31 +00:00
|
|
|
}
|
2011-01-16 00:43:56 +00:00
|
|
|
// Note, if there is an image description page, but
|
2013-03-13 07:42:41 +00:00
|
|
|
// no image, then this setRobotPolicy is overridden
|
2011-01-16 00:43:56 +00:00
|
|
|
// by Article::View().
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->setRobotPolicy( 'noindex,nofollow' );
|
|
|
|
|
$out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
|
2016-03-19 00:08:06 +00:00
|
|
|
if ( !$this->getId() && $wgSend404Code ) {
|
2011-01-16 00:43:56 +00:00
|
|
|
// If there is no image, no shared image, and no description page,
|
2015-05-24 12:31:11 +00:00
|
|
|
// output a 404, to be consistent with Article::showMissingArticle.
|
|
|
|
|
$request->response()->statusHeader( 404 );
|
2011-01-16 00:43:56 +00:00
|
|
|
}
|
2004-01-12 00:55:01 +00:00
|
|
|
}
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->setFileVersion( $this->displayImg );
|
2004-01-12 00:55:01 +00:00
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2015-07-19 08:16:23 +00:00
|
|
|
/**
|
|
|
|
|
* Make the text under the image to say what size preview
|
|
|
|
|
*
|
2016-03-19 00:08:06 +00:00
|
|
|
* @param $params array parameters for thumbnail
|
2015-07-19 08:16:23 +00:00
|
|
|
* @param $sizeLinkBigImagePreview HTML for the current size
|
|
|
|
|
* @return string HTML output
|
|
|
|
|
*/
|
|
|
|
|
private function getThumbPrevText( $params, $sizeLinkBigImagePreview ) {
|
|
|
|
|
if ( $sizeLinkBigImagePreview ) {
|
|
|
|
|
// Show a different message of preview is different format from original.
|
|
|
|
|
$previewTypeDiffers = false;
|
|
|
|
|
$origExt = $thumbExt = $this->displayImg->getExtension();
|
|
|
|
|
if ( $this->displayImg->getHandler() ) {
|
|
|
|
|
$origMime = $this->displayImg->getMimeType();
|
|
|
|
|
$typeParams = $params;
|
|
|
|
|
$this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
|
|
|
|
|
list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
|
|
|
|
|
$origExt, $origMime, $typeParams );
|
|
|
|
|
if ( $thumbMime !== $origMime ) {
|
|
|
|
|
$previewTypeDiffers = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $previewTypeDiffers ) {
|
|
|
|
|
return $this->getContext()->msg( 'show-big-image-preview-differ' )->
|
|
|
|
|
rawParams( $sizeLinkBigImagePreview )->
|
|
|
|
|
params( strtoupper( $origExt ) )->
|
|
|
|
|
params( strtoupper( $thumbExt ) )->
|
|
|
|
|
parse();
|
|
|
|
|
} else {
|
|
|
|
|
return $this->getContext()->msg( 'show-big-image-preview' )->
|
|
|
|
|
rawParams( $sizeLinkBigImagePreview )->
|
|
|
|
|
parse();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:49:31 +00:00
|
|
|
/**
|
2011-06-30 01:24:54 +00:00
|
|
|
* Creates an thumbnail of specified size and returns an HTML link to it
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $params Scaler parameters
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param int $width
|
|
|
|
|
* @param int $height
|
2011-10-29 01:53:28 +00:00
|
|
|
* @return string
|
2011-03-12 22:49:31 +00:00
|
|
|
*/
|
2011-10-15 21:40:30 +00:00
|
|
|
private function makeSizeLink( $params, $width, $height ) {
|
2011-03-12 22:49:31 +00:00
|
|
|
$params['width'] = $width;
|
|
|
|
|
$params['height'] = $height;
|
|
|
|
|
$thumbnail = $this->displayImg->transform( $params );
|
|
|
|
|
if ( $thumbnail && !$thumbnail->isError() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return Html::rawElement( 'a', [
|
2011-03-12 22:49:31 +00:00
|
|
|
'href' => $thumbnail->getUrl(),
|
|
|
|
|
'class' => 'mw-thumbnail-link'
|
2016-02-17 09:09:32 +00:00
|
|
|
], $this->getContext()->msg( 'show-big-image-size' )->numParams(
|
2011-06-30 01:24:54 +00:00
|
|
|
$thumbnail->getWidth(), $thumbnail->getHeight()
|
2011-03-12 22:49:31 +00:00
|
|
|
)->parse() );
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2008-02-19 16:29:28 +00:00
|
|
|
/**
|
|
|
|
|
* Show a notice that the file is from a shared repository
|
|
|
|
|
*/
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function printSharedImageText() {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
|
|
|
|
|
2011-06-29 22:09:51 +00:00
|
|
|
$descUrl = $this->mPage->getFile()->getDescriptionUrl();
|
2013-10-23 18:36:52 +00:00
|
|
|
$descText = $this->mPage->getFile()->getDescriptionText( $this->getContext()->getLanguage() );
|
2009-03-28 08:21:29 +00:00
|
|
|
|
2010-11-19 01:40:56 +00:00
|
|
|
/* Add canonical to head if there is no local page for this shared file */
|
2016-03-19 00:08:06 +00:00
|
|
|
if ( $descUrl && $this->mPage->getId() == 0 ) {
|
2012-12-31 01:11:43 +00:00
|
|
|
$out->setCanonicalUrl( $descUrl );
|
2010-11-17 00:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-28 16:41:00 +00:00
|
|
|
$wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
|
2011-06-29 22:09:51 +00:00
|
|
|
$repo = $this->mPage->getFile()->getRepo()->getDisplayName();
|
2009-03-28 08:21:29 +00:00
|
|
|
|
2015-09-26 09:58:36 +00:00
|
|
|
if ( $descUrl &&
|
|
|
|
|
$descText &&
|
|
|
|
|
$this->getContext()->msg( 'sharedupload-desc-here' )->plain() !== '-'
|
|
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-here', $repo, $descUrl ] );
|
2015-09-26 09:58:36 +00:00
|
|
|
} elseif ( $descUrl &&
|
|
|
|
|
$this->getContext()->msg( 'sharedupload-desc-there' )->plain() !== '-'
|
|
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-there', $repo, $descUrl ] );
|
2009-03-28 08:21:29 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$out->wrapWikiMsg( $wrap, [ 'sharedupload', $repo ], ''/*BACKCOMPAT*/ );
|
2005-07-03 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $descText ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->mExtraDescription = $descText;
|
2005-07-03 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 14:29:25 +00:00
|
|
|
public function getUploadUrl() {
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2006-10-30 06:25:31 +00:00
|
|
|
$uploadTitle = SpecialPage::getTitleFor( 'Upload' );
|
2016-02-17 09:09:32 +00:00
|
|
|
return $uploadTitle->getFullURL( [
|
2011-06-29 22:09:51 +00:00
|
|
|
'wpDestFile' => $this->mPage->getFile()->getName(),
|
2009-05-25 13:53:48 +00:00
|
|
|
'wpForReUpload' => 1
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2005-04-17 08:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-22 09:28:03 +00:00
|
|
|
/**
|
|
|
|
|
* Print out the various links at the bottom of the image page, e.g. reupload,
|
|
|
|
|
* external editing (and instructions link) etc.
|
|
|
|
|
*/
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function uploadLinksBox() {
|
2013-04-11 13:20:36 +00:00
|
|
|
global $wgEnableUploads;
|
2009-05-24 20:45:31 +00:00
|
|
|
|
2011-03-05 17:01:33 +00:00
|
|
|
if ( !$wgEnableUploads ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-07-03 05:21:06 +00:00
|
|
|
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2011-06-29 22:09:51 +00:00
|
|
|
if ( !$this->mPage->getFile()->isLocal() ) {
|
2005-07-03 05:21:06 +00:00
|
|
|
return;
|
2011-04-02 14:50:31 +00:00
|
|
|
}
|
2005-07-03 05:21:06 +00:00
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
2012-08-29 08:07:10 +00:00
|
|
|
$out->addHTML( "<ul>\n" );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-05-22 09:28:03 +00:00
|
|
|
# "Upload a new version of this file" link
|
2015-09-11 00:57:29 +00:00
|
|
|
$canUpload = $this->getTitle()->quickUserCan( 'upload', $this->getContext()->getUser() );
|
2014-05-12 14:42:51 +00:00
|
|
|
if ( $canUpload && UploadBase::userCanReUpload(
|
|
|
|
|
$this->getContext()->getUser(),
|
2015-09-10 22:47:54 +00:00
|
|
|
$this->mPage->getFile() )
|
2014-05-12 14:42:51 +00:00
|
|
|
) {
|
|
|
|
|
$ulink = Linker::makeExternalLink(
|
|
|
|
|
$this->getUploadUrl(),
|
2014-12-17 22:49:11 +00:00
|
|
|
$this->getContext()->msg( 'uploadnewversion-linktext' )->text()
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
|
|
|
|
$out->addHTML( "<li id=\"mw-imagepage-reupload-link\">"
|
|
|
|
|
. "<div class=\"plainlinks\">{$ulink}</div></li>\n" );
|
2012-08-29 08:07:10 +00:00
|
|
|
} else {
|
2014-05-12 14:42:51 +00:00
|
|
|
$out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">"
|
|
|
|
|
. $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
|
2005-09-05 06:16:48 +00:00
|
|
|
}
|
2008-03-19 16:58:56 +00:00
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( "</ul>\n" );
|
2005-03-24 13:30:09 +00:00
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/**
|
|
|
|
|
* For overloading
|
|
|
|
|
*/
|
|
|
|
|
protected function closeShowImage() {
|
|
|
|
|
}
|
2004-01-12 00:55:01 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* If the page we've just displayed is in the "Image" namespace,
|
|
|
|
|
* we follow it with an upload history of the image and its usage.
|
|
|
|
|
*/
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function imageHistory() {
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
2008-12-14 07:10:42 +00:00
|
|
|
$pager = new ImageHistoryPseudoPager( $this );
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( $pager->getBody() );
|
|
|
|
|
$out->preventClickjacking( $pager->getPreventClickjacking() );
|
2005-04-30 01:59:51 +00:00
|
|
|
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->mPage->getFile()->resetHistory(); // free db resources
|
2007-07-07 03:04:20 +00:00
|
|
|
|
2005-04-30 02:37:16 +00:00
|
|
|
# Exist check because we don't want to show this on pages where an image
|
|
|
|
|
# doesn't exist along with the noimage message, that would suck. -ævar
|
2011-06-29 22:09:51 +00:00
|
|
|
if ( $this->mPage->getFile()->exists() ) {
|
2005-04-30 01:59:51 +00:00
|
|
|
$this->uploadLinksBox();
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-29 01:53:28 +00:00
|
|
|
/**
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param string $target
|
|
|
|
|
* @param int $limit
|
2011-10-29 01:53:28 +00:00
|
|
|
* @return ResultWrapper
|
|
|
|
|
*/
|
2011-05-14 12:20:45 +00:00
|
|
|
protected function queryImageLinks( $target, $limit ) {
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2008-05-05 22:14:55 +00:00
|
|
|
|
2011-05-14 12:20:45 +00:00
|
|
|
return $dbr->select(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'imagelinks', 'page' ],
|
|
|
|
|
[ 'page_namespace', 'page_title', 'il_to' ],
|
|
|
|
|
[ 'il_to' => $target, 'il_from = page_id' ],
|
2008-05-09 11:31:00 +00:00
|
|
|
__METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', ]
|
2011-06-30 01:24:54 +00:00
|
|
|
);
|
2011-05-14 12:20:45 +00:00
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2011-05-14 12:20:45 +00:00
|
|
|
protected function imageLinks() {
|
|
|
|
|
$limit = 100;
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
2014-01-04 22:07:33 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows = [];
|
|
|
|
|
$redirects = [];
|
2014-01-04 22:07:33 +00:00
|
|
|
foreach ( $this->getTitle()->getRedirectsHere( NS_FILE ) as $redir ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$redirects[$redir->getDBkey()] = [];
|
|
|
|
|
$rows[] = (object)[
|
2014-01-04 22:07:33 +00:00
|
|
|
'page_namespace' => NS_FILE,
|
|
|
|
|
'page_title' => $redir->getDBkey(),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-01-04 22:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 );
|
2011-05-14 12:20:45 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$rows[] = $row;
|
|
|
|
|
}
|
|
|
|
|
$count = count( $rows );
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2011-05-14 12:20:45 +00:00
|
|
|
$hasMore = $count > $limit;
|
|
|
|
|
if ( !$hasMore && count( $redirects ) ) {
|
2011-06-30 01:24:54 +00:00
|
|
|
$res = $this->queryImageLinks( array_keys( $redirects ),
|
2011-05-14 12:20:45 +00:00
|
|
|
$limit - count( $rows ) + 1 );
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$redirects[$row->il_to][] = $row;
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $count == 0 ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->wrapWikiMsg(
|
2011-04-02 14:50:31 +00:00
|
|
|
Html::rawElement( 'div',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'mw-imagepage-nolinkstoimage' ], "\n$1\n" ),
|
2011-04-02 14:50:31 +00:00
|
|
|
'nolinkstoimage'
|
|
|
|
|
);
|
2008-05-05 22:14:55 +00:00
|
|
|
return;
|
2008-08-08 20:55:25 +00:00
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
|
2011-05-14 12:20:45 +00:00
|
|
|
if ( !$hasMore ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addWikiMsg( 'linkstoimage', $count );
|
2008-08-07 18:46:18 +00:00
|
|
|
} else {
|
|
|
|
|
// More links than the limit. Add a link to [[Special:Whatlinkshere]]
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addWikiMsg( 'linkstoimage-more',
|
|
|
|
|
$this->getContext()->getLanguage()->formatNum( $limit ),
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->getTitle()->getPrefixedDBkey()
|
2008-08-08 21:31:38 +00:00
|
|
|
);
|
2008-05-05 22:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML(
|
2011-04-02 14:50:31 +00:00
|
|
|
Html::openElement( 'ul',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-imagepage-linkstoimage' ] ) . "\n"
|
2011-04-02 14:50:31 +00:00
|
|
|
);
|
2008-05-09 11:31:00 +00:00
|
|
|
$count = 0;
|
2010-06-29 13:38:55 +00:00
|
|
|
|
|
|
|
|
// Sort the list by namespace:title
|
2016-02-17 09:09:32 +00:00
|
|
|
usort( $rows, [ $this, 'compare' ] );
|
2010-06-29 13:38:55 +00:00
|
|
|
|
|
|
|
|
// Create links for every element
|
2011-05-14 12:20:45 +00:00
|
|
|
$currentCount = 0;
|
2013-04-20 22:49:30 +00:00
|
|
|
foreach ( $rows as $element ) {
|
2011-05-14 12:20:45 +00:00
|
|
|
$currentCount++;
|
|
|
|
|
if ( $currentCount > $limit ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$query = [];
|
2013-08-24 18:27:39 +00:00
|
|
|
# Add a redirect=no to make redirect pages reachable
|
|
|
|
|
if ( isset( $redirects[$element->page_title] ) ) {
|
|
|
|
|
$query['redirect'] = 'no';
|
|
|
|
|
}
|
|
|
|
|
$link = Linker::linkKnown(
|
|
|
|
|
Title::makeTitle( $element->page_namespace, $element->page_title ),
|
2016-02-17 09:09:32 +00:00
|
|
|
null, [], $query
|
2013-08-24 18:27:39 +00:00
|
|
|
);
|
2011-05-14 12:20:45 +00:00
|
|
|
if ( !isset( $redirects[$element->page_title] ) ) {
|
2013-01-09 13:30:25 +00:00
|
|
|
# No redirects
|
2011-05-14 12:20:45 +00:00
|
|
|
$liContents = $link;
|
2013-01-09 13:30:25 +00:00
|
|
|
} elseif ( count( $redirects[$element->page_title] ) === 0 ) {
|
|
|
|
|
# Redirect without usages
|
2015-09-26 09:58:36 +00:00
|
|
|
$liContents = $this->getContext()->msg( 'linkstoimage-redirect' )
|
|
|
|
|
->rawParams( $link, '' )
|
|
|
|
|
->parse();
|
2011-05-14 12:20:45 +00:00
|
|
|
} else {
|
2013-01-09 13:30:25 +00:00
|
|
|
# Redirect with usages
|
|
|
|
|
$li = '';
|
2011-05-14 12:20:45 +00:00
|
|
|
foreach ( $redirects[$element->page_title] as $row ) {
|
|
|
|
|
$currentCount++;
|
|
|
|
|
if ( $currentCount > $limit ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2011-07-06 14:45:19 +00:00
|
|
|
$link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
|
2013-01-09 13:30:25 +00:00
|
|
|
$li .= Html::rawElement(
|
2011-05-14 12:20:45 +00:00
|
|
|
'li',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
|
2011-05-14 12:20:45 +00:00
|
|
|
$link2
|
|
|
|
|
) . "\n";
|
|
|
|
|
}
|
2013-01-09 13:30:25 +00:00
|
|
|
|
|
|
|
|
$ul = Html::rawElement(
|
|
|
|
|
'ul',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-imagepage-redirectstofile' ],
|
2013-01-09 13:30:25 +00:00
|
|
|
$li
|
|
|
|
|
) . "\n";
|
2014-12-17 22:49:11 +00:00
|
|
|
$liContents = $this->getContext()->msg( 'linkstoimage-redirect' )->rawParams(
|
2011-05-14 12:20:45 +00:00
|
|
|
$link, $ul )->parse();
|
|
|
|
|
}
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( Html::rawElement(
|
2011-04-02 14:50:31 +00:00
|
|
|
'li',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
|
2011-05-14 12:20:45 +00:00
|
|
|
$liContents
|
2011-04-02 14:50:31 +00:00
|
|
|
) . "\n"
|
2010-06-29 13:38:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
};
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( Html::closeElement( 'ul' ) . "\n" );
|
2008-05-09 11:31:00 +00:00
|
|
|
$res->free();
|
2008-06-11 12:07:58 +00:00
|
|
|
|
2008-05-09 11:31:00 +00:00
|
|
|
// Add a links to [[Special:Whatlinkshere]]
|
2010-06-29 13:38:55 +00:00
|
|
|
if ( $count > $limit ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
|
2010-06-29 13:38:55 +00:00
|
|
|
}
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( Html::closeElement( 'div' ) . "\n" );
|
2008-05-05 22:14:55 +00:00
|
|
|
}
|
2008-06-11 12:07:58 +00:00
|
|
|
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function imageDupes() {
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
2008-05-20 03:26:59 +00:00
|
|
|
|
2011-06-29 22:09:51 +00:00
|
|
|
$dupes = $this->mPage->getDuplicates();
|
2011-03-05 17:01:33 +00:00
|
|
|
if ( count( $dupes ) == 0 ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-05-15 07:16:22 +00:00
|
|
|
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
|
|
|
|
|
$out->addWikiMsg( 'duplicatesoffile',
|
|
|
|
|
$this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
|
2008-08-08 21:31:38 +00:00
|
|
|
);
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
|
2008-05-15 07:16:22 +00:00
|
|
|
|
2011-10-29 01:53:28 +00:00
|
|
|
/**
|
|
|
|
|
* @var $file File
|
|
|
|
|
*/
|
2008-05-14 15:11:48 +00:00
|
|
|
foreach ( $dupes as $file ) {
|
2009-02-17 22:27:10 +00:00
|
|
|
$fromSrc = '';
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $file->isLocal() ) {
|
2012-07-11 07:18:07 +00:00
|
|
|
$link = Linker::linkKnown( $file->getTitle() );
|
2009-06-06 22:42:48 +00:00
|
|
|
} else {
|
2011-07-06 14:45:19 +00:00
|
|
|
$link = Linker::makeExternalLink( $file->getDescriptionUrl(),
|
2008-05-14 17:29:38 +00:00
|
|
|
$file->getTitle()->getPrefixedText() );
|
2015-09-26 09:58:36 +00:00
|
|
|
$fromSrc = $this->getContext()->msg(
|
|
|
|
|
'shared-repo-from',
|
|
|
|
|
$file->getRepo()->getDisplayName()
|
|
|
|
|
)->text();
|
2008-08-08 21:31:38 +00:00
|
|
|
}
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
|
2008-05-14 15:11:48 +00:00
|
|
|
}
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( "</ul></div>\n" );
|
2008-05-14 15:11:48 +00:00
|
|
|
}
|
2008-05-05 22:14:55 +00:00
|
|
|
|
2006-06-07 06:40:24 +00:00
|
|
|
/**
|
2007-08-17 20:53:17 +00:00
|
|
|
* Delete the file, or an earlier version of it
|
2006-06-07 06:40:24 +00:00
|
|
|
*/
|
2007-08-17 20:53:17 +00:00
|
|
|
public function delete() {
|
2011-11-15 18:08:34 +00:00
|
|
|
$file = $this->mPage->getFile();
|
|
|
|
|
if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
|
2007-08-17 20:53:17 +00:00
|
|
|
// Standard article deletion
|
2010-07-25 21:08:34 +00:00
|
|
|
parent::delete();
|
2007-08-17 20:53:17 +00:00
|
|
|
return;
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2011-11-15 18:08:34 +00:00
|
|
|
|
|
|
|
|
$deleter = new FileDeleteForm( $file );
|
2007-08-17 20:53:17 +00:00
|
|
|
$deleter->execute();
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2007-07-22 14:45:12 +00:00
|
|
|
* Display an error with a wikitext description
|
2011-09-11 21:07:17 +00:00
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param string $description
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function showError( $description ) {
|
2012-04-30 14:43:03 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
2014-12-17 22:49:11 +00:00
|
|
|
$out->setPageTitle( $this->getContext()->msg( 'internalerror' ) );
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->setRobotPolicy( 'noindex,nofollow' );
|
|
|
|
|
$out->setArticleRelated( false );
|
|
|
|
|
$out->enableClientCache( false );
|
|
|
|
|
$out->addWikiText( $description );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-29 13:38:55 +00:00
|
|
|
/**
|
|
|
|
|
* Callback for usort() to do link sorts by (namespace, title)
|
|
|
|
|
* Function copied from Title::compare()
|
2011-06-30 01:24:54 +00:00
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param object $a Object page to compare with
|
|
|
|
|
* @param object $b Object page to compare with
|
|
|
|
|
* @return int Result of string comparison, or namespace comparison
|
2010-06-29 13:38:55 +00:00
|
|
|
*/
|
|
|
|
|
protected function compare( $a, $b ) {
|
|
|
|
|
if ( $a->page_namespace == $b->page_namespace ) {
|
|
|
|
|
return strcmp( $a->page_title, $b->page_title );
|
|
|
|
|
} else {
|
|
|
|
|
return $a->page_namespace - $b->page_namespace;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-02 13:48:33 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-03-13 07:42:41 +00:00
|
|
|
* Returns the corresponding $wgImageLimits entry for the selected user option
|
2013-02-02 13:48:33 +00:00
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param User $user
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $optionName Name of a option to check, typically imagesize or thumbsize
|
2013-02-02 13:48:33 +00:00
|
|
|
* @return array
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getImageLimitsFromOption( $user, $optionName ) {
|
|
|
|
|
global $wgImageLimits;
|
|
|
|
|
|
2013-03-02 16:50:56 +00:00
|
|
|
$option = $user->getIntOption( $optionName );
|
2013-02-02 13:48:33 +00:00
|
|
|
if ( !isset( $wgImageLimits[$option] ) ) {
|
|
|
|
|
$option = User::getDefaultOption( $optionName );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The user offset might still be incorrect, specially if
|
|
|
|
|
// $wgImageLimits got changed (see bug #8858).
|
|
|
|
|
if ( !isset( $wgImageLimits[$option] ) ) {
|
|
|
|
|
// Default to the first offset in $wgImageLimits
|
|
|
|
|
$option = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isset( $wgImageLimits[$option] )
|
|
|
|
|
? $wgImageLimits[$option]
|
2016-02-17 09:09:32 +00:00
|
|
|
: [ 800, 600 ]; // if nothing is set, fallback to a hardcoded default
|
2013-02-02 13:48:33 +00:00
|
|
|
}
|
2013-11-16 01:47:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Output a drop-down box for language options for the file
|
|
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param array $langChoices Array of string language codes
|
|
|
|
|
* @param string $curLang Language code file is being viewed in.
|
|
|
|
|
* @param string $defaultLang Language code that image is rendered in by default
|
|
|
|
|
* @return string HTML to insert underneath image.
|
2013-11-16 01:47:51 +00:00
|
|
|
*/
|
|
|
|
|
protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) {
|
|
|
|
|
global $wgScript;
|
|
|
|
|
sort( $langChoices );
|
|
|
|
|
$curLang = wfBCP47( $curLang );
|
|
|
|
|
$defaultLang = wfBCP47( $defaultLang );
|
|
|
|
|
$opts = '';
|
|
|
|
|
$haveCurrentLang = false;
|
|
|
|
|
$haveDefaultLang = false;
|
|
|
|
|
|
|
|
|
|
// We make a list of all the language choices in the file.
|
|
|
|
|
// Additionally if the default language to render this file
|
|
|
|
|
// is not included as being in this file (for example, in svgs
|
|
|
|
|
// usually the fallback content is the english content) also
|
|
|
|
|
// include a choice for that. Last of all, if we're viewing
|
|
|
|
|
// the file in a language not on the list, add it as a choice.
|
|
|
|
|
foreach ( $langChoices as $lang ) {
|
|
|
|
|
$code = wfBCP47( $lang );
|
|
|
|
|
$name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() );
|
|
|
|
|
if ( $name !== '' ) {
|
2014-12-17 22:49:11 +00:00
|
|
|
$display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text();
|
2013-11-16 01:47:51 +00:00
|
|
|
} else {
|
|
|
|
|
$display = $code;
|
|
|
|
|
}
|
2013-12-14 02:16:35 +00:00
|
|
|
$opts .= "\n" . Xml::option( $display, $code, $curLang === $code );
|
2013-11-16 01:47:51 +00:00
|
|
|
if ( $curLang === $code ) {
|
|
|
|
|
$haveCurrentLang = true;
|
|
|
|
|
}
|
|
|
|
|
if ( $defaultLang === $code ) {
|
|
|
|
|
$haveDefaultLang = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !$haveDefaultLang ) {
|
|
|
|
|
// Its hard to know if the content is really in the default language, or
|
|
|
|
|
// if its just unmarked content that could be in any language.
|
2014-05-12 14:42:51 +00:00
|
|
|
$opts = Xml::option(
|
2014-12-17 22:49:11 +00:00
|
|
|
$this->getContext()->msg( 'img-lang-default' )->text(),
|
2014-05-12 14:42:51 +00:00
|
|
|
$defaultLang,
|
|
|
|
|
$defaultLang === $curLang
|
|
|
|
|
) . $opts;
|
2013-11-16 01:47:51 +00:00
|
|
|
}
|
|
|
|
|
if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
|
|
|
|
|
$name = Language::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() );
|
|
|
|
|
if ( $name !== '' ) {
|
2014-12-17 22:49:11 +00:00
|
|
|
$display = $this->getContext()->msg( 'img-lang-opt', $curLang, $name )->text();
|
2013-11-16 01:47:51 +00:00
|
|
|
} else {
|
|
|
|
|
$display = $curLang;
|
|
|
|
|
}
|
2013-12-14 02:16:35 +00:00
|
|
|
$opts = Xml::option( $display, $curLang, true ) . $opts;
|
2013-11-16 01:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
$select = Html::rawElement(
|
|
|
|
|
'select',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'mw-imglangselector', 'name' => 'lang' ],
|
2014-05-12 14:42:51 +00:00
|
|
|
$opts
|
|
|
|
|
);
|
2014-12-17 22:49:11 +00:00
|
|
|
$submit = Xml::submitButton( $this->getContext()->msg( 'img-lang-go' )->text() );
|
2013-11-16 01:47:51 +00:00
|
|
|
|
2015-09-26 09:58:36 +00:00
|
|
|
$formContents = $this->getContext()->msg( 'img-lang-info' )
|
|
|
|
|
->rawParams( $select, $submit )
|
|
|
|
|
->parse();
|
|
|
|
|
$formContents .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() );
|
2013-11-16 01:47:51 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$langSelectLine = Html::rawElement( 'div', [ 'id' => 'mw-imglangselector-line' ],
|
|
|
|
|
Html::rawElement( 'form', [ 'action' => $wgScript ], $formContents )
|
2013-11-16 01:47:51 +00:00
|
|
|
);
|
|
|
|
|
return $langSelectLine;
|
|
|
|
|
}
|
2014-05-22 17:44:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the width and height to display image at.
|
|
|
|
|
*
|
|
|
|
|
* @note This method assumes that it is only called if one
|
|
|
|
|
* of the dimensions are bigger than the max, or if the
|
|
|
|
|
* image is vectorized.
|
|
|
|
|
*
|
2014-07-24 17:43:25 +00:00
|
|
|
* @param int $maxWidth Max width to display at
|
|
|
|
|
* @param int $maxHeight Max height to display at
|
|
|
|
|
* @param int $width Actual width of the image
|
|
|
|
|
* @param int $height Actual height of the image
|
2014-05-22 17:44:43 +00:00
|
|
|
* @throws MWException
|
2014-07-24 17:43:25 +00:00
|
|
|
* @return array Array (width, height)
|
2014-05-22 17:44:43 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDisplayWidthHeight( $maxWidth, $maxHeight, $width, $height ) {
|
|
|
|
|
if ( !$maxWidth || !$maxHeight ) {
|
|
|
|
|
// should never happen
|
|
|
|
|
throw new MWException( 'Using a choice from $wgImageLimits that is 0x0' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$width || !$height ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 0, 0 ];
|
2014-05-22 17:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Calculate the thumbnail size.
|
|
|
|
|
if ( $width <= $maxWidth && $height <= $maxHeight ) {
|
|
|
|
|
// Vectorized image, do nothing.
|
|
|
|
|
} elseif ( $width / $height >= $maxWidth / $maxHeight ) {
|
|
|
|
|
# The limiting factor is the width, not the height.
|
|
|
|
|
$height = round( $height * $maxWidth / $width );
|
|
|
|
|
$width = $maxWidth;
|
|
|
|
|
# Note that $height <= $maxHeight now.
|
|
|
|
|
} else {
|
|
|
|
|
$newwidth = floor( $width * $maxHeight / $height );
|
|
|
|
|
$height = round( $height * $newwidth / $width );
|
|
|
|
|
$width = $newwidth;
|
|
|
|
|
# Note that $height <= $maxHeight now, but might not be identical
|
|
|
|
|
# because of rounding.
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $width, $height ];
|
2014-05-22 17:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get alternative thumbnail sizes.
|
|
|
|
|
*
|
|
|
|
|
* @note This will only list several alternatives if thumbnails are rendered on 404
|
2014-07-24 17:43:25 +00:00
|
|
|
* @param int $origWidth Actual width of image
|
|
|
|
|
* @param int $origHeight Actual height of image
|
|
|
|
|
* @return array An array of [width, height] pairs.
|
2014-05-22 17:44:43 +00:00
|
|
|
*/
|
|
|
|
|
protected function getThumbSizes( $origWidth, $origHeight ) {
|
|
|
|
|
global $wgImageLimits;
|
|
|
|
|
if ( $this->displayImg->getRepo()->canTransformVia404() ) {
|
|
|
|
|
$thumbSizes = $wgImageLimits;
|
|
|
|
|
// Also include the full sized resolution in the list, so
|
|
|
|
|
// that users know they can get it. This will link to the
|
|
|
|
|
// original file asset if mustRender() === false. In the case
|
|
|
|
|
// that we mustRender, some users have indicated that they would
|
|
|
|
|
// find it useful to have the full size image in the rendered
|
|
|
|
|
// image format.
|
2016-02-17 09:09:32 +00:00
|
|
|
$thumbSizes[] = [ $origWidth, $origHeight ];
|
2014-05-22 17:44:43 +00:00
|
|
|
} else {
|
|
|
|
|
# Creating thumb links triggers thumbnail generation.
|
|
|
|
|
# Just generate the thumb for the current users prefs.
|
2016-02-17 09:09:32 +00:00
|
|
|
$thumbSizes = [
|
2015-09-26 09:58:36 +00:00
|
|
|
$this->getImageLimitsFromOption( $this->getContext()->getUser(), 'thumbsize' )
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-05-22 17:44:43 +00:00
|
|
|
if ( !$this->displayImg->mustRender() ) {
|
|
|
|
|
// We can safely include a link to the "full-size" preview,
|
|
|
|
|
// without actually rendering.
|
2016-02-17 09:09:32 +00:00
|
|
|
$thumbSizes[] = [ $origWidth, $origHeight ];
|
2014-05-22 17:44:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $thumbSizes;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 16:48:20 +00:00
|
|
|
/**
|
|
|
|
|
* @see WikiFilePage::getFile
|
|
|
|
|
* @return bool|File
|
|
|
|
|
*/
|
|
|
|
|
public function getFile() {
|
|
|
|
|
return $this->mPage->getFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see WikiFilePage::isLocal
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isLocal() {
|
|
|
|
|
return $this->mPage->isLocal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see WikiFilePage::getDuplicates
|
|
|
|
|
* @return array|null
|
|
|
|
|
*/
|
|
|
|
|
public function getDuplicates() {
|
|
|
|
|
return $this->mPage->getDuplicates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see WikiFilePage::getForeignCategories
|
|
|
|
|
* @return TitleArray|Title[]
|
|
|
|
|
*/
|
|
|
|
|
public function getForeignCategories() {
|
|
|
|
|
$this->mPage->getForeignCategories();
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|