jenkins-bot has submitted this change and it was merged.

Change subject: Add a function to return a single page image
......................................................................


Add a function to return a single page image

Change-Id: I3e891ee65476eb72b5ffd65d9af3ac1f080d849e
---
M ApiQueryPageImages.php
M PageImages.body.php
2 files changed, 30 insertions(+), 2 deletions(-)

Approvals:
  Awjrichards: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ApiQueryPageImages.php b/ApiQueryPageImages.php
index e4042f5..740aa45 100644
--- a/ApiQueryPageImages.php
+++ b/ApiQueryPageImages.php
@@ -58,7 +58,7 @@
                if ( count( $titles ) > 0 ) {
                        $this->addTables( 'page_props' );
                        $this->addFields( array( 'pp_page', 'pp_propname', 
'pp_value' ) );
-                       $this->addWhere( array( 'pp_page' => array_keys( 
$titles ), 'pp_propname' => 'page_image' ) );
+                       $this->addWhere( array( 'pp_page' => array_keys( 
$titles ), 'pp_propname' => PageImages::PROP_NAME ) );
 
                        wfProfileIn( __METHOD__ . '-select' );
                        $res = $this->select( __METHOD__ );
diff --git a/PageImages.body.php b/PageImages.body.php
index 396c604..fab9176 100644
--- a/PageImages.body.php
+++ b/PageImages.body.php
@@ -2,6 +2,34 @@
 
 class PageImages {
        /**
+        * Page property used to store the page image information
+        */
+       const PROP_NAME = 'page_image';
+
+       /**
+        * Returns page image for a given title
+        *
+        * @param Title $title: Title to get page image for
+        *
+        * @return File|null
+        */
+       public static function getPageImage( Title $title ) {
+               wfProfileIn( __METHOD__ );
+               $dbr = wfGetDB( DB_SLAVE );
+               $name = $dbr->selectField( 'page_props',
+                       'pp_value',
+                       array( 'pp_page' => $title->getArticleID(), 
'pp_propname' => self::PROP_NAME ),
+                       __METHOD__
+               );
+               $file = null;
+               if ( $name ) {
+                       $file = wfFindFile( $name );
+               }
+               wfProfileOut( __METHOD__ );
+               return $file;
+       }
+
+       /**
         * Returns true if data for this title should be saved
         *
         * @param Title $title
@@ -76,7 +104,7 @@
                        }
                }
                if ( $image ) {
-                       $lu->mProperties['page_image'] = $image;
+                       $lu->mProperties[self::PROP_NAME] = $image;
                }
 
                return true;

-- 
To view, visit https://gerrit.wikimedia.org/r/93607
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3e891ee65476eb72b5ffd65d9af3ac1f080d849e
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to