From 361745ca219e3f6fc5aea3ed07d4b24883a46da7 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 13 Mar 2011 22:58:41 +0000 Subject: [PATCH] * (bug 28031) Add pageCount support to ArchivedFile Apply my patch Add documentation to File --- RELEASE-NOTES | 3 ++- includes/filerepo/ArchivedFile.php | 33 +++++++++++++++++++++++++++++- includes/filerepo/File.php | 5 +++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 66fe1fb2e7..d88b479e7c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -114,7 +114,8 @@ PHP if you have not done so prior to upgrading MediaWiki. extension * (bug 2581, bug 6834) Added links to thumbnail in several resolutions to the file description page. The sizes are set by $wgImageLimits. - +* (bug 28031) Add pageCount support to ArchivedFile + === Bug fixes in 1.18 === * (bug 23119) WikiError class and subclasses are now marked as deprecated * (bug 10871) Javascript and CSS pages in MediaWiki namespace are no longer diff --git a/includes/filerepo/ArchivedFile.php b/includes/filerepo/ArchivedFile.php index be9d3f1e09..0fb2e06164 100644 --- a/includes/filerepo/ArchivedFile.php +++ b/includes/filerepo/ArchivedFile.php @@ -31,8 +31,13 @@ class ArchivedFile { $user_text, # user name of uploader $timestamp, # time of upload $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx) - $deleted; # Bitfield akin to rev_deleted + $deleted, # Bitfield akin to rev_deleted + $pageCount; + /** + * @var MediaHandler + */ + var $handler; /** * @var Title */ @@ -279,6 +284,32 @@ class ArchivedFile { return $this->mime; } + /** + * Get a MediaHandler instance for this file + * @return MediaHandler + */ + function getHandler() { + if ( !isset( $this->handler ) ) { + $this->handler = MediaHandler::getHandler( $this->getMimeType() ); + } + return $this->handler; + } + + /** + * Returns the number of pages of a multipage document, or false for + * documents which aren't multipage documents + */ + function pageCount() { + if ( !isset( $this->pageCount ) ) { + if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) { + $this->pageCount = $this->handler->pageCount( $this ); + } else { + $this->pageCount = false; + } + } + return $this->pageCount; + } + /** * Return the type of the media in the file. * Use the value returned by this function with the MEDIATYPE_xxx constants. diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 8d9c42c470..898ac64a8a 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -65,6 +65,11 @@ abstract class File { var $lastError, $redirected, $redirectedTitle; + /** + * @var MediaHandler + */ + protected $handler; + /** * Call this constructor from child classes */ -- 2.20.1