* (bug 28031) Add pageCount support to ArchivedFile
authorSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 22:58:41 +0000 (22:58 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 22:58:41 +0000 (22:58 +0000)
Apply my patch

Add documentation to File

RELEASE-NOTES
includes/filerepo/ArchivedFile.php
includes/filerepo/File.php

index 66fe1fb..d88b479 100644 (file)
@@ -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
index be9d3f1..0fb2e06 100644 (file)
@@ -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.
index 8d9c42c..898ac64 100644 (file)
@@ -65,6 +65,11 @@ abstract class File {
 
        var $lastError, $redirected, $redirectedTitle;
 
+       /**
+        * @var MediaHandler
+        */
+       protected $handler;
+
        /**
         * Call this constructor from child classes
         */