jenkins-bot has submitted this change and it was merged.
Change subject: Expose file page count, width, and height to Lua
......................................................................
Expose file page count, width, and height to Lua
Add a file table to Title objects, containing the number of pages, widths,
and heights, of files.
Change-Id: I9c6b5024ae6b5af393ed7eb1448a297c5c4e5830
---
M engines/LuaCommon/TitleLibrary.php
M engines/LuaCommon/lualib/mw.title.lua
2 files changed, 34 insertions(+), 10 deletions(-)
Approvals:
Anomie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/engines/LuaCommon/TitleLibrary.php
b/engines/LuaCommon/TitleLibrary.php
index 5094a17..c3db982 100644
--- a/engines/LuaCommon/TitleLibrary.php
+++ b/engines/LuaCommon/TitleLibrary.php
@@ -14,7 +14,7 @@
'makeTitle' => array( $this, 'makeTitle' ),
'getUrl' => array( $this, 'getUrl' ),
'getContent' => array( $this, 'getContent' ),
- 'fileExists' => array( $this, 'fileExists' ),
+ 'getFileInfo' => array( $this, 'getFileInfo' ),
'protectionLevels' => array( $this, 'protectionLevels'
),
'cascadingProtection' => array( $this,
'cascadingProtection' ),
);
@@ -91,7 +91,7 @@
$ret['exists'] = $title->exists();
}
if ( $ns !== NS_FILE && $ns !== NS_MEDIA ) {
- $ret['fileExists'] = false;
+ $ret['file'] = false;
}
return $ret;
}
@@ -243,8 +243,8 @@
return array( $content->serialize() );
}
- function fileExists( $text ) {
- $this->checkType( 'fileExists', 1, $text, 'string' );
+ function getFileInfo( $text ) {
+ $this->checkType( 'getFileInfo', 1, $text, 'string' );
$title = Title::newFromText( $text );
if ( !$title ) {
return array( false );
@@ -257,12 +257,32 @@
$this->incrementExpensiveFunctionCount();
$file = wfFindFile( $title );
if ( !$file ) {
- return array( false );
+ return array( array( 'exists' => false ) );
}
$this->getParser()->getOutput()->addImage(
$file->getName(), $file->getTimestamp(),
$file->getSha1()
);
- return array( (bool)$file->exists() );
+ if ( !$file->exists() ) {
+ return array( array( 'exists' => false ) );
+ }
+ $pageCount = $file->pageCount();
+ if ( $pageCount === false ) {
+ $pages = null;
+ } else {
+ $pages = array();
+ for ( $i = 1; $i <= $pageCount; ++$i ) {
+ $pages[$i] = array(
+ 'width' => $file->getWidth( $i ),
+ 'height' => $file->getHeight( $i )
+ );
+ }
+ }
+ return array( array(
+ 'exists' => true,
+ 'width' => $file->getWidth(),
+ 'height' => $file->getHeight(),
+ 'pages' => $pages
+ ) );
}
private static function makeArrayOneBased( $arr ) {
diff --git a/engines/LuaCommon/lualib/mw.title.lua
b/engines/LuaCommon/lualib/mw.title.lua
index bc1caa7..8594e4a 100644
--- a/engines/LuaCommon/lualib/mw.title.lua
+++ b/engines/LuaCommon/lualib/mw.title.lua
@@ -164,6 +164,7 @@
talkPageTitle = true,
subjectPageTitle = true,
fileExists = true,
+ file = true,
protectionLevels = true,
cascadingProtection = true,
}
@@ -225,11 +226,14 @@
end
return title.makeTitle( ns.id, data.text )
end
- if k == 'fileExists' then
- if data.fileExists == nil then
- data.fileExists = php.fileExists(
data.prefixedText )
+ if k == 'file' then
+ if data.file == nil then
+ data.file = php.getFileInfo(
data.prefixedText )
end
- return data.fileExists
+ return data.file or nil
+ end
+ if k == 'fileExists' then -- Kept for backward
compatibility. Since 1.25, file.exists is preferred over this
+ return t.file and t.file.exists
end
if k == 'protectionLevels' then
if data.protectionLevels == nil then
--
To view, visit https://gerrit.wikimedia.org/r/136274
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9c6b5024ae6b5af393ed7eb1448a297c5c4e5830
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits