(bug 27862; follow-up r77714) Make emailuser api module not freak out when SpecialEma...
[lhc/web/wiklou.git] / includes / api / ApiQueryImages.php
index 1804ce4..c63f897 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-
 /**
- * Created on May 13, 2007
  *
- * API for MediaWiki 1.8+
+ *
+ * Created on May 13, 2007
  *
  * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  *
  * 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.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -47,6 +48,10 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                $this->run( $resultPageSet );
        }
 
+       /**
+        * @param $resultPageSet ApiPageSet
+        * @return
+        */
        private function run( $resultPageSet = null ) {
                if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
                        return; // nothing to do
@@ -83,12 +88,24 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                }
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
 
-               $db = $this->getDB();
+               if ( !is_null( $params['images'] ) ) {
+                       $images = array();
+                       foreach ( $params['images'] as $img ) {
+                               $title = Title::newFromText( $img );
+                               if ( !$title || $title->getNamespace() != NS_FILE ) {
+                                       $this->setWarning( "``$img'' is not a file" );
+                               } else {
+                                       $images[] = $title->getDBkey();
+                               }
+                       }
+                       $this->addWhereFld( 'il_to', $images );
+               }
+
                $res = $this->select( __METHOD__ );
 
                if ( is_null( $resultPageSet ) ) {
                        $count = 0;
-                       while ( $row = $db->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                if ( ++$count > $params['limit'] ) {
                                        // We've reached the one extra which shows that
                                        // there are additional pages to be had. Stop here...
@@ -108,7 +125,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                } else {
                        $titles = array();
                        $count = 0;
-                       while ( $row = $db->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                if ( ++$count > $params['limit'] ) {
                                        // We've reached the one extra which shows that
                                        // there are additional pages to be had. Stop here...
@@ -122,6 +139,10 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                }
        }
 
+       public function getCacheMode( $params ) {
+               return 'public';
+       }
+
        public function getAllowedParams() {
                return array(
                        'limit' => array(
@@ -132,6 +153,9 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
                        ),
                        'continue' => null,
+                       'images' => array(
+                               ApiBase::PARAM_ISMULTI => true,
+                       )
                );
        }
 
@@ -139,6 +163,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                return array(
                        'limit' => 'How many images to return',
                        'continue' => 'When more results are available, use this to continue',
+                       'images' => 'Only list these images. Useful for checking whether a certain page has a certain Image.',
                );
        }
 
@@ -164,4 +189,4 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
-}
\ No newline at end of file
+}