2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2012-05-12 20:33:02 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-16 19:27:21 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2024-09-27 20:18:58 +00:00
|
|
|
use MediaWiki\Language\LanguageCode;
|
2022-12-05 11:29:37 +00:00
|
|
|
use MediaWiki\Linker\Linker;
|
2022-04-10 15:34:45 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2019-01-09 20:48:02 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-09-07 11:46:15 +00:00
|
|
|
use MediaWiki\Request\WebRequest;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-10-04 13:33:42 +00:00
|
|
|
use MediaWiki\Title\TitleArrayFromResult;
|
2024-05-16 10:52:03 +00:00
|
|
|
use MediaWiki\Xml\Xml;
|
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
|
|
|
/**
|
2022-04-08 15:13:15 +00:00
|
|
|
* Rendering of 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-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
|
|
|
}
|
2021-10-25 19:15:52 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable should be set
|
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?
|
2021-10-25 19:15:52 +00:00
|
|
|
// @phan-suppress-next-line PhanPossiblyNullTypeMismatchProperty should be set
|
2011-06-29 22:09:51 +00:00
|
|
|
$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() {
|
2022-06-09 21:06:18 +00:00
|
|
|
$context = $this->getContext();
|
|
|
|
|
$showEXIF = $context->getConfig()->get( MainConfigNames::ShowEXIF );
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 21:06:18 +00:00
|
|
|
$out = $context->getOutput();
|
|
|
|
|
$request = $context->getRequest();
|
2012-04-30 14:43:03 +00:00
|
|
|
$diff = $request->getVal( 'diff' );
|
2010-06-09 21:09:13 +00:00
|
|
|
|
2022-04-22 12:32:02 +00:00
|
|
|
if ( $this->getTitle()->getNamespace() !== NS_FILE || ( $diff !== null && $this->isDiffOnlyView() ) ) {
|
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
|
|
|
|
2022-01-06 18:44:56 +00:00
|
|
|
if ( $showEXIF && $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() ) {
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
$out->addHTML( Html::openElement( 'div', [ 'id' => 'mw-imagepage-content' ] ) );
|
|
|
|
|
// NS_FILE pages render mostly in the user language (like special pages),
|
|
|
|
|
// except the editable wikitext content, which is rendered in the page content
|
|
|
|
|
// language by the parent class.
|
2012-06-12 09:11:37 +00:00
|
|
|
parent::view();
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
$out->addHTML( Html::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(
|
2022-06-09 21:06:18 +00:00
|
|
|
$context->getAuthority(),
|
2020-03-27 22:43:01 +00:00
|
|
|
$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 ) {
|
2022-06-09 21:06:18 +00:00
|
|
|
$fol = $context->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
|
|
|
}
|
2021-02-04 20:34:22 +00:00
|
|
|
$out->addHTML(
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'div',
|
|
|
|
|
[ 'id' => 'shared-image-desc' ],
|
|
|
|
|
$this->mExtraDescription
|
|
|
|
|
) . "\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' ],
|
2022-06-09 21:06:18 +00:00
|
|
|
$context->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' ],
|
2022-06-09 21:06:18 +00:00
|
|
|
$context->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( [
|
|
|
|
|
'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 = [
|
2021-02-04 20:34:22 +00:00
|
|
|
Html::rawElement(
|
|
|
|
|
'li',
|
|
|
|
|
[],
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'a',
|
|
|
|
|
[ 'href' => '#file' ],
|
|
|
|
|
$this->getContext()->msg( 'file-anchor-link' )->escaped()
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'li',
|
|
|
|
|
[],
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'a',
|
|
|
|
|
[ 'href' => '#filehistory' ],
|
|
|
|
|
$this->getContext()->msg( 'filehist' )->escaped()
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'li',
|
|
|
|
|
[],
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'a',
|
|
|
|
|
[ 'href' => '#filelinks' ],
|
|
|
|
|
$this->getContext()->msg( 'imagelinks' )->escaped()
|
|
|
|
|
)
|
|
|
|
|
),
|
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 ) {
|
2021-02-04 20:34:22 +00:00
|
|
|
$r[] = Html::rawElement(
|
|
|
|
|
'li',
|
|
|
|
|
[],
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'a',
|
|
|
|
|
[ 'href' => '#metadata' ],
|
|
|
|
|
$this->getContext()->msg( 'metadata' )->escaped()
|
|
|
|
|
)
|
|
|
|
|
);
|
2009-11-08 11:09:20 +00:00
|
|
|
}
|
2011-06-30 01:24:54 +00:00
|
|
|
|
2023-10-17 21:10:07 +00:00
|
|
|
return Html::rawElement( 'ul', [
|
2024-04-19 22:25:15 +00:00
|
|
|
'id' => 'filetoc',
|
|
|
|
|
'role' => 'navigation'
|
2023-10-17 21:10:07 +00:00
|
|
|
], implode( "\n", $r ) );
|
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();
|
2023-01-21 22:58:36 +00:00
|
|
|
// Initial state of collapsible rows is collapsed
|
|
|
|
|
// see mediawiki.action.view.filepage.less and mediawiki.action.view.metadata module.
|
2017-12-05 00:09:06 +00:00
|
|
|
$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'] );
|
2023-01-21 22:58:36 +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
|
|
|
/**
|
2022-05-09 09:09:00 +00:00
|
|
|
* Returns language code to be used for displaying the image, based on request context and
|
2019-01-09 20:48:02 +00:00
|
|
|
* languages available in the file.
|
|
|
|
|
*
|
|
|
|
|
* @param WebRequest $request
|
|
|
|
|
* @param File $file
|
2022-06-11 16:31:09 +00:00
|
|
|
* @return string|null a valid IETF language tag
|
2019-01-09 20:48:02 +00:00
|
|
|
*/
|
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
|
|
|
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
$requestLanguage = $request->getVal( 'lang' );
|
|
|
|
|
if ( $requestLanguage === null ) {
|
|
|
|
|
// For on File pages about a translatable SVG, decide which
|
|
|
|
|
// language to render the large thumbnail in (T310445)
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$variantLangCode = $services->getLanguageConverterFactory()
|
|
|
|
|
->getLanguageConverter( $services->getContentLanguage() )
|
|
|
|
|
->getPreferredVariant();
|
|
|
|
|
$requestLanguage = LanguageCode::bcp47( $variantLangCode );
|
|
|
|
|
}
|
2019-01-09 20:48:02 +00:00
|
|
|
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() {
|
2022-06-09 21:06:18 +00:00
|
|
|
$context = $this->getContext();
|
|
|
|
|
$mainConfig = $context->getConfig();
|
2022-04-10 15:34:45 +00:00
|
|
|
$enableUploads = $mainConfig->get( MainConfigNames::EnableUploads );
|
|
|
|
|
$send404Code = $mainConfig->get( MainConfigNames::Send404Code );
|
|
|
|
|
$svgMaxSize = $mainConfig->get( MainConfigNames::SVGMaxSize );
|
2023-06-19 18:31:30 +00:00
|
|
|
$enableLegacyMediaDOM = $mainConfig->get( MainConfigNames::ParserEnableLegacyMediaDOM );
|
2008-05-20 03:26:59 +00:00
|
|
|
$this->loadFile();
|
2022-06-09 21:06:18 +00:00
|
|
|
$out = $context->getOutput();
|
|
|
|
|
$user = $context->getUser();
|
|
|
|
|
$lang = $context->getLanguage();
|
2024-09-29 19:37:12 +00:00
|
|
|
$sitedir = MediaWikiServices::getInstance()->getContentLanguage()->getDir();
|
2022-06-09 21:06:18 +00:00
|
|
|
$request = $context->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
|
|
|
[ $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()
|
|
|
|
|
) {
|
|
|
|
|
[ $width, $height ] = $this->displayImg->getDisplayWidthHeight(
|
|
|
|
|
$maxWidth, $maxHeight, $page
|
2014-05-22 17:44:43 +00:00
|
|
|
);
|
2022-06-09 21:06:18 +00:00
|
|
|
$linktext = $context->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()
|
2022-01-06 18:44:56 +00:00
|
|
|
&& max( $size[0], $size[1] ) <= $svgMaxSize )
|
2015-07-19 11:26:58 +00:00
|
|
|
)
|
2013-12-01 20:39:00 +00:00
|
|
|
&& $size[0] != $width && $size[1] != $height
|
2021-01-17 21:11:47 +00:00
|
|
|
&& $size[0] != $maxWidth && $size[1] != $maxHeight
|
2013-12-01 20:39:00 +00:00
|
|
|
) {
|
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' ],
|
2022-06-09 21:06:18 +00:00
|
|
|
$context->msg( 'show-big-image-other' )
|
2015-09-26 09:58:36 +00:00
|
|
|
->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;
|
2022-01-23 06:05:18 +00:00
|
|
|
$params['isFilePageThumb'] = true;
|
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' );
|
2023-01-20 23:38:12 +00:00
|
|
|
/* TODO: multipageimage class is deprecated since Jan 2023 */
|
|
|
|
|
$out->addHTML( '<div class="mw-filepage-multipage multipageimage">' );
|
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
|
|
|
];
|
2021-02-04 20:34:22 +00:00
|
|
|
$out->addHTML(
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'div',
|
|
|
|
|
[ 'class' => 'fullImageLink', 'id' => 'file' ],
|
|
|
|
|
$thumbnail->toHtml( $options ) . $anchorclose
|
|
|
|
|
) . "\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 ) {
|
2023-01-20 23:38:12 +00:00
|
|
|
$linkPrev = $linkNext = '';
|
2008-05-21 21:33:58 +00:00
|
|
|
$count = $this->displayImg->pageCount();
|
2023-06-19 18:31:30 +00:00
|
|
|
if ( !$enableLegacyMediaDOM ) {
|
|
|
|
|
$out->addModules( 'mediawiki.page.media' );
|
|
|
|
|
}
|
2007-01-26 12:00:04 +00:00
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $page > 1 ) {
|
2022-06-09 21:06:18 +00:00
|
|
|
$label = $context->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
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$linkPrev = $this->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
|
|
|
);
|
2023-01-20 23:38:12 +00:00
|
|
|
$thumbPrevPage = Linker::makeThumbLinkObj(
|
2014-05-12 14:42:51 +00:00
|
|
|
$this->getTitle(),
|
|
|
|
|
$this->displayImg,
|
2023-01-20 23:38:12 +00:00
|
|
|
$linkPrev,
|
2014-05-12 14:42:51 +00:00
|
|
|
$label,
|
|
|
|
|
'none',
|
2022-01-23 06:05:18 +00:00
|
|
|
[ 'page' => $page - 1, 'isFilePageThumb' => true ]
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2007-01-26 12:00:04 +00:00
|
|
|
} else {
|
2023-01-20 23:38:12 +00:00
|
|
|
$thumbPrevPage = '';
|
2007-01-26 12:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-20 22:58:48 +00:00
|
|
|
if ( $page < $count ) {
|
2022-06-09 21:06:18 +00:00
|
|
|
$label = $context->msg( 'imgmultipagenext' )->text();
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$linkNext = $this->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
|
|
|
);
|
2023-01-20 23:38:12 +00:00
|
|
|
$thumbNextPage = Linker::makeThumbLinkObj(
|
2014-05-12 14:42:51 +00:00
|
|
|
$this->getTitle(),
|
|
|
|
|
$this->displayImg,
|
2023-01-20 23:38:12 +00:00
|
|
|
$linkNext,
|
2014-05-12 14:42:51 +00:00
|
|
|
$label,
|
|
|
|
|
'none',
|
2022-01-23 06:05:18 +00:00
|
|
|
[ 'page' => $page + 1, 'isFilePageThumb' => true ]
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2007-01-26 12:00:04 +00:00
|
|
|
} else {
|
2023-01-20 23:38:12 +00:00
|
|
|
$thumbNextPage = '';
|
2006-08-13 17:34:48 +00:00
|
|
|
}
|
2007-01-26 12:00:04 +00:00
|
|
|
|
2022-06-09 21:06:18 +00:00
|
|
|
$script = $mainConfig->get( MainConfigNames::Script );
|
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',
|
2022-01-06 18:44:56 +00:00
|
|
|
'action' => $script,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
|
|
|
|
$options = [];
|
2010-03-20 22:58:48 +00:00
|
|
|
for ( $i = 1; $i <= $count; $i++ ) {
|
2022-02-26 16:28:48 +00:00
|
|
|
$options[] = Xml::option( $lang->formatNum( $i ), (string)$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 ) );
|
|
|
|
|
|
2023-01-20 23:38:12 +00:00
|
|
|
/* TODO: multipageimagenavbox class is deprecated since Jan 2023 */
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->addHTML(
|
2023-01-20 23:38:12 +00:00
|
|
|
'<div class="mw-filepage-multipage-navigation multipageimagenavbox">' .
|
|
|
|
|
$linkPrev .
|
2024-04-18 13:06:44 +00:00
|
|
|
Html::rawElement( 'form', $formParams,
|
|
|
|
|
Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
|
|
|
|
|
$context->msg( 'imgmultigoto' )->rawParams( $select )->parse() .
|
|
|
|
|
$context->msg( 'word-separator' )->escaped() .
|
|
|
|
|
Xml::submitButton( $context->msg( 'imgmultigo' )->text() )
|
|
|
|
|
) .
|
2023-01-20 23:38:12 +00:00
|
|
|
"$thumbPrevPage\n$thumbNextPage\n$linkNext</div></div>"
|
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
|
|
|
|
2021-02-04 20:34:22 +00:00
|
|
|
$out->addHTML(
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'div',
|
|
|
|
|
[ 'class' => 'fullImageLink', 'id' => 'file' ],
|
|
|
|
|
$icon->toHtml( [ 'file-link' => true ] )
|
|
|
|
|
) . "\n"
|
|
|
|
|
);
|
2004-01-16 18:11:47 +00:00
|
|
|
}
|
2005-07-03 04:40:07 +00:00
|
|
|
|
2022-06-09 21:06:18 +00:00
|
|
|
$longDesc = $context->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.
|
2022-06-09 21:06:18 +00:00
|
|
|
$output = $context->getOutput();
|
2015-03-05 18:52:11 +00:00
|
|
|
$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() ) {
|
2022-06-09 21:06:18 +00:00
|
|
|
$warning = $context->msg( 'mediawarning' )->plain();
|
2024-09-29 19:37:12 +00:00
|
|
|
// <bdi> is needed here to separate the file name, which
|
2012-11-12 19:52:27 +00:00
|
|
|
// most likely ends in Latin characters, from the description,
|
|
|
|
|
// which may begin with the file type. In RTL environment
|
|
|
|
|
// this will get messy.
|
2018-10-17 14:28:05 +00:00
|
|
|
$out->wrapWikiTextAsInterface( 'fullMedia', <<<EOT
|
2024-09-29 19:37:12 +00:00
|
|
|
<bdi dir="$sitedir"><span class="dangerousLink">$medialink</span></bdi> <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
|
2024-09-29 19:37:12 +00:00
|
|
|
<bdi dir="$sitedir">$medialink</bdi> <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();
|
2022-06-08 20:37:53 +00:00
|
|
|
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'
|
2022-06-09 21:06:18 +00:00
|
|
|
)->setContext( $context )->plain();
|
2012-08-29 08:07:10 +00:00
|
|
|
|
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() ) {
|
2023-10-17 20:08:33 +00:00
|
|
|
$dbr = $this->dbProvider->getReplicaDatabase();
|
2017-02-22 17:55:56 +00:00
|
|
|
|
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,
|
2024-10-03 16:31:57 +00:00
|
|
|
[ 'delete', 'move', 'protect', 'merge' ],
|
2012-03-02 01:02:41 +00:00
|
|
|
$this->getTitle()->getPrefixedText(),
|
|
|
|
|
'',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'lim' => 10,
|
2023-10-21 11:32:26 +00:00
|
|
|
'conds' => [ $dbr->expr( 'log_action', '!=', '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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-06 18:44:56 +00:00
|
|
|
if ( $enableUploads &&
|
2022-06-09 21:06:18 +00:00
|
|
|
$context->getAuthority()->isAllowed( 'upload' )
|
2019-08-21 02:01:06 +00:00
|
|
|
) {
|
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 );
|
2022-01-06 18:44:56 +00:00
|
|
|
if ( !$this->getPage()->getId() && $send404Code ) {
|
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 );
|
|
|
|
|
[ $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
|
|
|
/**
|
2023-03-18 18:16:00 +00:00
|
|
|
* Creates a 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 &&
|
2022-02-25 14:02:18 +00:00
|
|
|
!$this->getContext()->msg( 'sharedupload-desc-here' )->isDisabled()
|
2015-09-26 09:58:36 +00:00
|
|
|
) {
|
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 &&
|
2022-02-25 14:02:18 +00:00
|
|
|
!$this->getContext()->msg( 'sharedupload-desc-there' )->isDisabled()
|
2015-09-26 09:58:36 +00:00
|
|
|
) {
|
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() {
|
2022-04-10 15:34:45 +00:00
|
|
|
if ( !$this->getContext()->getConfig()->get( MainConfigNames::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
|
|
|
|
2021-03-02 23:39:12 +00:00
|
|
|
$canUpload = $this->getContext()->getAuthority()
|
|
|
|
|
->probablyCan( 'upload', $this->getTitle() );
|
2014-05-12 14:42:51 +00:00
|
|
|
if ( $canUpload && UploadBase::userCanReUpload(
|
2021-03-02 23:39:12 +00:00
|
|
|
$this->getContext()->getAuthority(),
|
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
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$ulink = $this->linkRenderer->makeExternalLink(
|
2014-05-12 14:42:51 +00:00
|
|
|
$this->getUploadUrl(),
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$this->getContext()->msg( 'uploadnewversion-linktext' ),
|
|
|
|
|
$this->getTitle()
|
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() );
|
2021-09-29 20:58:59 +00:00
|
|
|
$out->setPreventClickjacking( $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 ) {
|
2023-10-17 20:08:33 +00:00
|
|
|
return $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
|
2023-08-24 10:55:34 +00:00
|
|
|
->select( [ 'page_namespace', 'page_title', 'il_to' ] )
|
|
|
|
|
->from( 'imagelinks' )
|
|
|
|
|
->join( 'page', null, 'il_from = page_id' )
|
|
|
|
|
->where( [ 'il_to' => $target ] )
|
|
|
|
|
->orderBy( 'il_from' )
|
|
|
|
|
->limit( $limit + 1 )
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$link = $this->linkRenderer->makeKnownLink(
|
2013-08-24 18:27:39 +00:00
|
|
|
Title::makeTitle( $element->page_namespace, $element->page_title ),
|
2022-04-25 08:14:30 +00:00
|
|
|
null,
|
|
|
|
|
[],
|
|
|
|
|
// Add a redirect=no to make redirect pages reachable
|
|
|
|
|
[ 'redirect' => isset( $redirects[$element->page_title] ) ? 'no' : null ]
|
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
|
|
|
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$link2 = $this->linkRenderer->makeKnownLink(
|
2019-09-07 09:27:30 +00:00
|
|
|
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
|
|
|
|
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() ) {
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$link = $this->linkRenderer->makeKnownLink( $file->getTitle() );
|
2009-06-06 22:42:48 +00:00
|
|
|
} else {
|
Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.
In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object. In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().
This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.
We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle. This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable. The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances. The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible. A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.
Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-02-09 20:19:38 +00:00
|
|
|
$link = $this->linkRenderer->makeExternalLink(
|
|
|
|
|
$file->getDescriptionUrl(),
|
|
|
|
|
$file->getTitle()->getPrefixedText(),
|
|
|
|
|
$this->getTitle()
|
|
|
|
|
);
|
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
|
|
|
|
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();
|
2023-08-10 17:25:17 +00:00
|
|
|
$out->setPageTitleMsg( $this->getContext()->msg( 'internalerror' ) );
|
2012-04-30 14:43:03 +00:00
|
|
|
$out->setRobotPolicy( 'noindex,nofollow' );
|
|
|
|
|
$out->setArticleRelated( false );
|
2022-02-04 19:12:11 +00:00
|
|
|
$out->disableClientCache();
|
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-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
|
2022-06-09 20:21:53 +00:00
|
|
|
* @param string|null $renderLang Language code for the language we want the file to rendered in,
|
|
|
|
|
* it is pre-selected in the drop down box, use null to select the default case in the option list
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return string HTML to insert underneath image.
|
2013-11-16 01:47:51 +00:00
|
|
|
*/
|
2022-06-09 20:21:53 +00:00
|
|
|
protected function doRenderLangOpt( array $langChoices, $renderLang ) {
|
2022-06-09 21:06:18 +00:00
|
|
|
$context = $this->getContext();
|
|
|
|
|
$script = $context->getConfig()->get( MainConfigNames::Script );
|
2013-11-16 01:47:51 +00:00
|
|
|
$opts = '';
|
2017-10-18 12:38:48 +00:00
|
|
|
|
2022-06-09 20:21:53 +00:00
|
|
|
$matchedRenderLang = $renderLang === null ? null : $this->displayImg->getMatchedLanguage( $renderLang );
|
2017-10-18 12:38:48 +00:00
|
|
|
|
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(
|
2022-06-09 21:06:18 +00:00
|
|
|
$context->msg( 'img-lang-default' )->text(),
|
2017-10-18 12:38:48 +00:00
|
|
|
'und',
|
2022-06-11 16:13:37 +00:00
|
|
|
$matchedRenderLang === null || $matchedRenderLang === 'und'
|
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
|
|
|
|
|
);
|
2022-06-09 21:06:18 +00:00
|
|
|
$submit = Xml::submitButton( $context->msg( 'img-lang-go' )->text() );
|
2013-11-16 01:47:51 +00:00
|
|
|
|
2022-06-09 21:06:18 +00:00
|
|
|
$formContents = $context->msg( 'img-lang-info' )
|
2015-09-26 09:58:36 +00:00
|
|
|
->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' ],
|
2022-01-06 18:44:56 +00:00
|
|
|
Html::rawElement( 'form', [ 'action' => $script ], $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 ) {
|
2022-06-11 16:31:09 +00:00
|
|
|
// TODO: There is no good way to get the language name of a BCP code,
|
|
|
|
|
// as MW language codes take precedence
|
2020-01-03 23:03:14 +00:00
|
|
|
$name = MediaWikiServices::getInstance()
|
|
|
|
|
->getLanguageNameUtils()
|
2022-06-11 16:31:09 +00:00
|
|
|
->getLanguageName( $lang, $this->getContext()->getLanguage()->getCode() );
|
2017-10-18 12:38:48 +00:00
|
|
|
if ( $name !== '' ) {
|
2022-06-11 16:31:09 +00:00
|
|
|
$display = $this->getContext()->msg( 'img-lang-opt', $lang, $name )->text();
|
2017-10-18 12:38:48 +00:00
|
|
|
} else {
|
2022-06-11 16:31:09 +00:00
|
|
|
$display = $lang;
|
2017-10-18 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
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 ) {
|
2022-06-09 21:06:18 +00:00
|
|
|
$context = $this->getContext();
|
|
|
|
|
$imageLimits = $context->getConfig()->get( MainConfigNames::ImageLimits );
|
2014-05-22 17:44:43 +00:00
|
|
|
if ( $this->displayImg->getRepo()->canTransformVia404() ) {
|
2022-01-06 18:44:56 +00:00
|
|
|
$thumbSizes = $imageLimits;
|
2014-05-22 17:44:43 +00:00
|
|
|
// 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 = [
|
2022-06-09 21:06:18 +00:00
|
|
|
$this->getImageLimitsFromOption( $context->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
|
2021-08-11 12:46:34 +00:00
|
|
|
* @return File
|
2016-02-02 16:48:20 +00:00
|
|
|
*/
|
2021-08-11 12:46:34 +00:00
|
|
|
public function getFile(): File {
|
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
|
2023-10-04 13:33:42 +00:00
|
|
|
* @return TitleArrayFromResult
|
2016-02-02 16:48:20 +00:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|