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
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-09 20:48:02 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-10-04 17:58:19 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2017-02-19 05:03:13 +00:00
|
|
|
|
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
|
2019-06-29 14:11:57 +00:00
|
|
|
*
|
2019-08-31 16:14:38 +00:00
|
|
|
* @method WikiFilePage getPage()
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-09-01 09:59:53 +00:00
|
|
|
class ImagePage extends Article {
|
2019-11-18 15:13:45 +00:00
|
|
|
use MediaFileTrait;
|
|
|
|
|
|
2021-02-16 08:46:00 +00:00
|
|
|
/** @var File|false Only temporary false, most code can assume this is a 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
|
|
|
|
2021-02-16 08:46:00 +00:00
|
|
|
/** @var string|false Guaranteed to be HTML, {@see File::getDescriptionText} */
|
2014-05-12 14:42:51 +00:00
|
|
|
protected $mExtraDescription = false;
|
2005-07-03 04:40:07 +00:00
|
|
|
|
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 ) {
|
2020-03-27 22:43:01 +00:00
|
|
|
$this->getPage()->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
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onImagePageFindFile( $this, $img, $this->displayImg );
|
2011-06-29 22:09:51 +00:00
|
|
|
if ( !$img ) { // not set by hook?
|
2019-05-14 17:00:34 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$img = $services->getRepoGroup()->findFile( $this->getTitle() );
|
2011-06-29 22:09:51 +00:00
|
|
|
if ( !$img ) {
|
2019-05-14 17:00:34 +00:00
|
|
|
$img = $services->getRepoGroup()->getLocalRepo()->newFile( $this->getTitle() );
|
2008-05-21 22:20:07 +00:00
|
|
|
}
|
2008-05-23 09:03:49 +00:00
|
|
|
}
|
2020-03-27 22:43:01 +00:00
|
|
|
$this->getPage()->setFile( $img );
|
2011-06-29 22:09:51 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2018-10-18 03:06:23 +00:00
|
|
|
// For action=render, include body text only; none of the image extras
|
|
|
|
|
if ( $this->viewIsRenderAction ) {
|
|
|
|
|
parent::view();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2020-07-22 17:29:48 +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
|
|
|
|
2020-03-27 22:43:01 +00:00
|
|
|
if (
|
2020-07-22 17:29:48 +00:00
|
|
|
$this->getTitle()->getNamespace() === NS_FILE
|
2020-03-27 22:43:01 +00:00
|
|
|
&& $this->getFile()->getRedirected()
|
|
|
|
|
) {
|
|
|
|
|
if (
|
|
|
|
|
$this->getTitle()->getDBkey() == $this->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-01-17 05:01:54 +00:00
|
|
|
} else {
|
2020-05-15 05:34:04 +00:00
|
|
|
$formattedMetadata = false;
|
2007-01-17 05:01:54 +00:00
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2011-04-02 14:50:31 +00:00
|
|
|
if ( !$diff && $this->displayImg->exists() ) {
|
2020-05-15 05:34:04 +00:00
|
|
|
$out->addHTML( $this->showTOC( (bool)$formattedMetadata ) );
|
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()
|
2020-03-27 22:43:01 +00:00
|
|
|
if ( $this->getPage()->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() );
|
2020-03-27 22:43:01 +00:00
|
|
|
$this->getPage()->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() ) {
|
2018-09-25 15:02:07 +00:00
|
|
|
$out->addWikiTextAsInterface( $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 = '';
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onImagePageAfterImageLinks( $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
|
|
|
|
2020-05-15 05:34:04 +00:00
|
|
|
if ( $formattedMetadata ) {
|
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" );
|
2018-10-17 14:47:35 +00:00
|
|
|
$out->wrapWikiTextAsInterface(
|
|
|
|
|
'mw-imagepage-section-metadata',
|
|
|
|
|
$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
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onImagePageShowTOC( $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 ) {
|
2018-10-17 14:47:35 +00:00
|
|
|
$r = $this->getContext()->msg( 'metadata-help' )->plain();
|
2020-12-08 08:35:51 +00:00
|
|
|
// Initial state is collapsed
|
2017-12-05 00:09:06 +00:00
|
|
|
// see filepage.css and mediawiki.action.view.metadata module.
|
|
|
|
|
$r .= "<table id=\"mw_metadata\" class=\"mw_metadata collapsed\">\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' ) {
|
2017-12-04 23:50:06 +00:00
|
|
|
$class .= ' mw-metadata-collapsible';
|
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
|
|
|
}
|
|
|
|
|
}
|
2018-10-17 14:47:35 +00:00
|
|
|
$r .= "</table>\n";
|
2005-11-28 23:56:35 +00:00
|
|
|
return $r;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2019-01-09 20:48:02 +00:00
|
|
|
/**
|
|
|
|
|
* Returns language code to be used for dispaying the image, based on request context and
|
|
|
|
|
* languages available in the file.
|
|
|
|
|
*
|
|
|
|
|
* @param WebRequest $request
|
|
|
|
|
* @param File $file
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
2017-10-18 12:38:48 +00:00
|
|
|
private function getLanguageForRendering( WebRequest $request, File $file ) {
|
2019-01-09 20:48:02 +00:00
|
|
|
$handler = $file->getHandler();
|
2017-11-27 09:44:19 +00:00
|
|
|
if ( !$handler ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-10-18 12:38:48 +00:00
|
|
|
|
2019-01-09 20:48:02 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
|
$requestLanguage = $request->getVal( 'lang', $config->get( 'LanguageCode' ) );
|
|
|
|
|
if ( $handler->validateParam( 'lang', $requestLanguage ) ) {
|
|
|
|
|
return $file->getMatchedLanguage( $requestLanguage );
|
2017-10-18 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-09 20:48:02 +00:00
|
|
|
return $handler->getDefaultRenderLanguage( $file );
|
2017-10-18 12:38:48 +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
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $this->displayImg->exists() ) {
|
2019-11-18 15:13:45 +00:00
|
|
|
list( $maxWidth, $maxHeight ) = $this->getImageLimitsFromOption( $user, 'imagesize' );
|
|
|
|
|
|
2005-05-21 07:46:17 +00:00
|
|
|
# image
|
2012-04-30 14:43:03 +00:00
|
|
|
$page = $request->getIntOrNull( 'page' );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $page === null ) {
|
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
|
|
|
|
2017-10-18 12:38:48 +00:00
|
|
|
$renderLang = $this->getLanguageForRendering( $request, $this->displayImg );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $renderLang !== null ) {
|
2017-10-18 12:38:48 +00:00
|
|
|
$params['lang'] = $renderLang;
|
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
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onImageOpenShowImageInlineBefore( $this, $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,
|
2019-02-09 01:31:29 +00:00
|
|
|
# Language::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
|
2005-12-04 08:52:01 +00:00
|
|
|
# We'll show a thumbnail of this image
|
2019-11-18 15:13:45 +00:00
|
|
|
if ( $width > $maxWidth ||
|
|
|
|
|
$height > $maxHeight ||
|
|
|
|
|
$this->displayImg->isVectorized()
|
|
|
|
|
) {
|
|
|
|
|
list( $width, $height ) = $this->displayImg->getDisplayWidthHeight(
|
|
|
|
|
$maxWidth, $maxHeight, $page
|
2014-05-22 17:44:43 +00:00
|
|
|
);
|
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;
|
2020-05-28 12:49:35 +00:00
|
|
|
// Allow the MediaHandler to handle query string parameters on the file page,
|
|
|
|
|
// e.g. start time for videos (T203994)
|
2020-06-05 01:26:54 +00:00
|
|
|
$params['imagePageParams'] = $request->getQueryValuesOnly();
|
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();
|
2019-09-07 09:27:30 +00:00
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
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
|
2019-09-07 09:27:30 +00:00
|
|
|
$link = $linkRenderer->makeKnownLink(
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->getTitle(),
|
2019-09-07 09:27:30 +00:00
|
|
|
$label,
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'page' => $page - 1 ]
|
2009-06-06 22:42:48 +00:00
|
|
|
);
|
2020-12-30 18:38:48 +00:00
|
|
|
// @phan-suppress-next-line SecurityCheck-DoubleEscaped link getting a key, false positive
|
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();
|
2019-09-07 09:27:30 +00:00
|
|
|
$link = $linkRenderer->makeKnownLink(
|
2011-06-29 22:09:51 +00:00
|
|
|
$this->getTitle(),
|
2019-09-07 09:27:30 +00:00
|
|
|
$label,
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'page' => $page + 1 ]
|
2009-06-06 22:42:48 +00:00
|
|
|
);
|
2020-12-30 18:38:48 +00:00
|
|
|
// @phan-suppress-next-line SecurityCheck-DoubleEscaped link getting a key, false positive
|
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.
|
2018-01-01 13:10:16 +00:00
|
|
|
// phpcs:disable Generic.Files.LineLength
|
2018-10-17 14:28:05 +00:00
|
|
|
$out->wrapWikiTextAsInterface( 'fullMedia', <<<EOT
|
|
|
|
|
<span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span>
|
2007-05-30 21:02:32 +00:00
|
|
|
EOT
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2018-01-01 13:10:16 +00:00
|
|
|
// phpcs:enable
|
2018-10-17 14:28:05 +00:00
|
|
|
$out->wrapWikiTextAsInterface( 'mediaWarning', $warning );
|
2012-11-12 19:52:27 +00:00
|
|
|
} else {
|
2018-10-17 14:28:05 +00:00
|
|
|
$out->wrapWikiTextAsInterface( 'fullMedia', <<<EOT
|
|
|
|
|
{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
|
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 ) {
|
2017-10-18 12:38:48 +00:00
|
|
|
$out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $renderLang ) );
|
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();
|
|
|
|
|
|
2018-10-17 14:28:05 +00:00
|
|
|
$out->wrapWikiTextAsInterface( 'mw-noanimatethumb', $noAnimMesg );
|
2012-08-29 08:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
2020-03-27 22:43:01 +00:00
|
|
|
if ( !$this->getPage()->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,
|
2017-09-03 17:03:28 +00:00
|
|
|
[ 'delete', 'move', 'protect' ],
|
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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:01:06 +00:00
|
|
|
if ( $wgEnableUploads && MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $user, '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',
|
2020-03-27 22:43:01 +00:00
|
|
|
$uploadTitle->getFullURL( [
|
|
|
|
|
'wpDestFile' => $this->getFile()->getName()
|
|
|
|
|
] )
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
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 );
|
2020-03-27 22:43:01 +00:00
|
|
|
if ( !$this->getPage()->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
|
|
|
|
|
*
|
2017-08-11 15:46:31 +00:00
|
|
|
* @param array $params parameters for thumbnail
|
|
|
|
|
* @param string $sizeLinkBigImagePreview HTML for the current size
|
2015-07-19 08:16:23 +00:00
|
|
|
* @return string HTML output
|
|
|
|
|
*/
|
2017-12-21 07:42:19 +00:00
|
|
|
protected function getThumbPrevText( $params, $sizeLinkBigImagePreview ) {
|
2015-07-19 08:16:23 +00:00
|
|
|
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
|
|
|
*/
|
2017-12-21 07:42:19 +00:00
|
|
|
protected 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();
|
|
|
|
|
|
2020-03-27 22:43:01 +00:00
|
|
|
$descUrl = $this->getFile()->getDescriptionUrl();
|
|
|
|
|
$descText = $this->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 */
|
2020-03-27 22:43:01 +00:00
|
|
|
if ( $descUrl && !$this->getPage()->getId() ) {
|
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";
|
2020-03-27 22:43:01 +00:00
|
|
|
$repo = $this->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( [
|
2020-03-27 22:43:01 +00:00
|
|
|
'wpDestFile' => $this->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
|
|
|
/**
|
2019-08-07 21:09:57 +00:00
|
|
|
* Add the re-upload link (or message about not being able to re-upload) to the output.
|
2006-05-22 09:28:03 +00:00
|
|
|
*/
|
2008-11-28 14:29:25 +00:00
|
|
|
protected function uploadLinksBox() {
|
2019-08-07 21:09:57 +00:00
|
|
|
if ( !$this->getContext()->getConfig()->get( 'EnableUploads' ) ) {
|
2011-03-05 17:01:33 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2005-07-03 05:21:06 +00:00
|
|
|
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2020-03-27 22:43:01 +00:00
|
|
|
if ( !$this->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
|
|
|
|
2019-08-23 23:53:15 +00:00
|
|
|
$canUpload = MediaWikiServices::getInstance()->getPermissionManager()
|
|
|
|
|
->quickUserCan( 'upload', $this->getContext()->getUser(), $this->getTitle() );
|
2014-05-12 14:42:51 +00:00
|
|
|
if ( $canUpload && UploadBase::userCanReUpload(
|
|
|
|
|
$this->getContext()->getUser(),
|
2020-03-27 22:43:01 +00:00
|
|
|
$this->getFile() )
|
2014-05-12 14:42:51 +00:00
|
|
|
) {
|
2019-08-07 21:09:57 +00:00
|
|
|
// "Upload a new version of this file" link
|
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
|
|
|
);
|
2019-08-07 21:09:57 +00:00
|
|
|
$attrs = [ 'class' => 'plainlinks', 'id' => 'mw-imagepage-reupload-link' ];
|
|
|
|
|
$linkPara = Html::rawElement( 'p', $attrs, $ulink );
|
2012-08-29 08:07:10 +00:00
|
|
|
} else {
|
2019-08-07 21:09:57 +00:00
|
|
|
// "You cannot overwrite this file." message
|
|
|
|
|
$attrs = [ 'id' => 'mw-imagepage-upload-disallowed' ];
|
|
|
|
|
$msg = $this->getContext()->msg( 'upload-disallowed-here' )->text();
|
|
|
|
|
$linkPara = Html::element( 'p', $attrs, $msg );
|
2005-09-05 06:16:48 +00:00
|
|
|
}
|
2008-03-19 16:58:56 +00:00
|
|
|
|
2019-08-07 21:09:57 +00:00
|
|
|
$uploadLinks = Html::rawElement( 'div', [ 'class' => 'mw-imagepage-upload-links' ], $linkPara );
|
|
|
|
|
$this->getContext()->getOutput()->addHTML( $uploadLinks );
|
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();
|
2020-08-07 22:08:51 +00:00
|
|
|
$pager = new ImageHistoryPseudoPager(
|
|
|
|
|
$this,
|
|
|
|
|
MediaWikiServices::getInstance()->getLinkBatchFactory()
|
|
|
|
|
);
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML( $pager->getBody() );
|
|
|
|
|
$out->preventClickjacking( $pager->getPreventClickjacking() );
|
2005-04-30 01:59:51 +00:00
|
|
|
|
2020-03-27 22:43:01 +00:00
|
|
|
$this->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
|
2020-03-27 22:43:01 +00:00
|
|
|
if ( $this->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
|
|
|
/**
|
2019-07-01 20:30:14 +00:00
|
|
|
* @param string|string[] $target
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param int $limit
|
2019-10-04 17:58:19 +00:00
|
|
|
* @return IResultWrapper
|
2011-10-29 01:53:28 +00:00
|
|
|
*/
|
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
|
|
|
);
|
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
|
|
|
|
2019-09-07 09:27:30 +00:00
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
|
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';
|
|
|
|
|
}
|
2019-09-07 09:27:30 +00:00
|
|
|
$link = $linkRenderer->makeKnownLink(
|
2013-08-24 18:27:39 +00:00
|
|
|
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
|
|
|
|
2019-09-07 09:27:30 +00:00
|
|
|
$link2 = $linkRenderer->makeKnownLink(
|
|
|
|
|
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
|
|
|
);
|
|
|
|
|
|
2019-06-12 13:35:59 +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]]
|
2020-06-22 21:05:40 +00:00
|
|
|
if ( $currentCount > $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
|
|
|
|
2020-03-27 22:43:01 +00:00
|
|
|
$dupes = $this->getPage()->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
|
|
|
|
2019-09-07 09:27:30 +00:00
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
|
2011-10-29 01:53:28 +00:00
|
|
|
/**
|
2019-02-02 13:39:58 +00:00
|
|
|
* @var File $file
|
2011-10-29 01:53:28 +00:00
|
|
|
*/
|
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() ) {
|
2019-09-07 09:27:30 +00:00
|
|
|
$link = $linkRenderer->makeKnownLink( $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()
|
2017-10-16 06:01:56 +00:00
|
|
|
)->escaped();
|
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() {
|
2020-03-27 22:43:01 +00:00
|
|
|
$file = $this->getFile();
|
2011-11-15 18:08:34 +00:00
|
|
|
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
|
|
|
}
|
2019-09-04 18:46:57 +00:00
|
|
|
'@phan-var LocalFile $file';
|
2011-11-15 18:08:34 +00:00
|
|
|
|
2020-07-06 07:33:22 +00:00
|
|
|
$context = $this->getContext();
|
|
|
|
|
$deleter = new FileDeleteForm(
|
|
|
|
|
$file,
|
|
|
|
|
$context->getUser(),
|
|
|
|
|
$context->getOutput()
|
|
|
|
|
);
|
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
|
|
|
*/
|
2020-05-17 02:07:58 +00:00
|
|
|
public 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 );
|
2018-09-25 15:02:07 +00:00
|
|
|
$out->addWikiTextAsInterface( $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
|
|
|
*
|
2020-11-17 23:43:59 +00:00
|
|
|
* @param stdClass $a Object page to compare with
|
|
|
|
|
* @param stdClass $b Object page to compare with
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return int Result of string comparison, or namespace comparison
|
2010-06-29 13:38:55 +00:00
|
|
|
*/
|
|
|
|
|
protected function compare( $a, $b ) {
|
Use PHP 7 '<=>' operator in 'sort()' callbacks
`$a <=> $b` returns `-1` if `$a` is lesser, `1` if `$b` is lesser,
and `0` if they are equal, which are exactly the values 'sort()'
callbacks are supposed to return.
It also enables the neat idiom `$a[x] <=> $b[x] ?: $a[y] <=> $b[y]`
to sort arrays of objects first by 'x', and by 'y' if they are equal.
* Replace a common pattern like `return $a < $b ? -1 : 1` with the
new operator (and similar patterns with the variables, the numbers
or the comparison inverted). Some of the uses were previously not
correctly handling the variables being equal; this is now
automatically fixed.
* Also replace `return $a - $b`, which is equivalent to `return
$a <=> $b` if both variables are integers but less intuitive.
* (Do not replace `return strcmp( $a, $b )`. It is also equivalent
when both variables are strings, but if any of the variables is not,
'strcmp()' converts it to a string before comparison, which could
give different results than '<=>', so changing this would require
careful review and isn't worth it.)
* Also replace `return $a > $b`, which presumably sort of works most
of the time (returns `1` if `$b` is lesser, and `0` if they are
equal or `$a` is lesser) but is erroneous.
Change-Id: I19a3d2fc8fcdb208c10330bd7a42c4e05d7f5cf3
2017-10-06 20:39:13 +00:00
|
|
|
return $a->page_namespace <=> $b->page_namespace
|
|
|
|
|
?: strcmp( $a->page_title, $b->page_title );
|
2010-06-29 13:38:55 +00:00
|
|
|
}
|
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
|
2019-03-24 14:04:32 +00:00
|
|
|
* @return int[]
|
2013-02-02 13:48:33 +00:00
|
|
|
* @since 1.21
|
2019-11-18 15:13:45 +00:00
|
|
|
* @deprecated Since 1.35 Use static function MediaFileTrait::getImageLimitsFromOption
|
2013-02-02 13:48:33 +00:00
|
|
|
*/
|
|
|
|
|
public function getImageLimitsFromOption( $user, $optionName ) {
|
2019-11-18 15:13:45 +00:00
|
|
|
return MediaFileTrait::getImageLimitsFromOption( $user, $optionName );
|
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
|
2017-10-18 12:38:48 +00:00
|
|
|
* @param string $renderLang Language code for the language we want the file to rendered in.
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return string HTML to insert underneath image.
|
2013-11-16 01:47:51 +00:00
|
|
|
*/
|
2017-10-18 12:38:48 +00:00
|
|
|
protected function doRenderLangOpt( array $langChoices, $renderLang ) {
|
2013-11-16 01:47:51 +00:00
|
|
|
global $wgScript;
|
|
|
|
|
$opts = '';
|
2017-10-18 12:38:48 +00:00
|
|
|
|
|
|
|
|
$matchedRenderLang = $this->displayImg->getMatchedLanguage( $renderLang );
|
|
|
|
|
|
2013-11-16 01:47:51 +00:00
|
|
|
foreach ( $langChoices as $lang ) {
|
2017-10-18 12:38:48 +00:00
|
|
|
$opts .= $this->createXmlOptionStringForLanguage(
|
|
|
|
|
$lang,
|
|
|
|
|
$matchedRenderLang === $lang
|
|
|
|
|
);
|
2013-11-16 01:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-18 12:38:48 +00:00
|
|
|
// Allow for the default case in an svg <switch> that is displayed if no
|
|
|
|
|
// systemLanguage attribute matches
|
|
|
|
|
$opts .= "\n" .
|
|
|
|
|
Xml::option(
|
|
|
|
|
$this->getContext()->msg( 'img-lang-default' )->text(),
|
|
|
|
|
'und',
|
2020-01-09 23:48:34 +00:00
|
|
|
$matchedRenderLang === null
|
2017-10-18 12:38:48 +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
|
|
|
|
2017-10-18 12:38:48 +00:00
|
|
|
/**
|
2019-01-14 06:01:19 +00:00
|
|
|
* @param string $lang
|
|
|
|
|
* @param bool $selected
|
2017-10-18 12:38:48 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function createXmlOptionStringForLanguage( $lang, $selected ) {
|
|
|
|
|
$code = LanguageCode::bcp47( $lang );
|
2020-01-03 23:03:14 +00:00
|
|
|
$name = MediaWikiServices::getInstance()
|
|
|
|
|
->getLanguageNameUtils()
|
|
|
|
|
->getLanguageName( $code, $this->getContext()->getLanguage()->getCode() );
|
2017-10-18 12:38:48 +00:00
|
|
|
if ( $name !== '' ) {
|
|
|
|
|
$display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text();
|
|
|
|
|
} else {
|
|
|
|
|
$display = $code;
|
|
|
|
|
}
|
|
|
|
|
return "\n" .
|
|
|
|
|
Xml::option(
|
|
|
|
|
$display,
|
|
|
|
|
$lang,
|
|
|
|
|
$selected
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2019-10-11 14:31:51 +00:00
|
|
|
* @return int[][] An array of [width, height] pairs.
|
|
|
|
|
* @phan-return array<int,array{0:int,1:int}>
|
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() {
|
2020-03-27 22:43:01 +00:00
|
|
|
return $this->getPage()->getFile();
|
2016-02-02 16:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see WikiFilePage::isLocal
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isLocal() {
|
2020-03-27 22:43:01 +00:00
|
|
|
return $this->getPage()->isLocal();
|
2016-02-02 16:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see WikiFilePage::getDuplicates
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return File[]|null
|
2016-02-02 16:48:20 +00:00
|
|
|
*/
|
|
|
|
|
public function getDuplicates() {
|
2020-03-27 22:43:01 +00:00
|
|
|
return $this->getPage()->getDuplicates();
|
2016-02-02 16:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see WikiFilePage::getForeignCategories
|
|
|
|
|
* @return TitleArray|Title[]
|
|
|
|
|
*/
|
|
|
|
|
public function getForeignCategories() {
|
2020-03-27 22:43:01 +00:00
|
|
|
return $this->getPage()->getForeignCategories();
|
2016-02-02 16:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|