MediaWiki  1.34.0
PageImages\Hooks\LinksUpdateHookHandler Class Reference

Handler for the "LinksUpdate" hook. More...

Public Member Functions

 doLinksUpdate (LinksUpdate $linksUpdate)
 
 getPageImageCandidates (LinksUpdate $linksUpdate)
 Returns a list of page image candidates for consideration for scoring algorithm. More...
 

Static Public Member Functions

static onLinksUpdate (LinksUpdate $linksUpdate)
 LinksUpdate hook handler, sets at most 2 page properties depending on images on page. More...
 

Protected Member Functions

 fetchFileMetadata ( $file)
 Fetch file metadata. More...
 
 getBlacklist ()
 Returns a list of images blacklisted from influencing this extension's output. More...
 
 getRatio (array $image)
 Returns width/height ratio of an image as displayed or 0 is not available. More...
 
 getScore (array $image, $position)
 Returns score for image, the more the better, if it is less than zero, the image shouldn't be used for anything. More...
 
 isImageFree ( $fileName)
 Check whether image's copyright allows it to be used freely. More...
 
 scoreFromTable ( $value, array $scores)
 Returns score based on table of ranges. More...
 

Private Member Functions

 getDbBlacklist ( $dbName, $page)
 Returns list of images linked by the given blacklist page. More...
 
 getUrlBlacklist ( $url)
 Returns list of images on given remote blacklist page. More...
 

Detailed Description

Handler for the "LinksUpdate" hook.

Note
WTFPL
Author
Max Semenik
Thiemo Kreuz

Definition at line 22 of file LinksUpdateHookHandler.php.

Member Function Documentation

◆ doLinksUpdate()

PageImages\Hooks\LinksUpdateHookHandler::doLinksUpdate ( LinksUpdate  $linksUpdate)

◆ fetchFileMetadata()

PageImages\Hooks\LinksUpdateHookHandler::fetchFileMetadata (   $file)
protected

Fetch file metadata.

Parameters
File$fileFile to fetch metadata from
Returns
array

Definition at line 206 of file LinksUpdateHookHandler.php.

References $context, and $file.

Referenced by PageImages\Hooks\LinksUpdateHookHandler\isImageFree().

◆ getBlacklist()

PageImages\Hooks\LinksUpdateHookHandler::getBlacklist ( )
protected

Returns a list of images blacklisted from influencing this extension's output.

Exceptions
Exception
Returns
int[] Flipped associative array in format "image BDB key" => int

Definition at line 241 of file LinksUpdateHookHandler.php.

References $source, $wgMemc, PageImages\Hooks\LinksUpdateHookHandler\getDbBlacklist(), PageImages\Hooks\LinksUpdateHookHandler\getUrlBlacklist(), wfDebug(), and wfMemcKey().

Referenced by PageImages\Hooks\LinksUpdateHookHandler\getScore().

◆ getDbBlacklist()

PageImages\Hooks\LinksUpdateHookHandler::getDbBlacklist (   $dbName,
  $page 
)
private

Returns list of images linked by the given blacklist page.

Parameters
string | bool$dbNameDatabase name or false for current database
string$page
Returns
string[]

Definition at line 285 of file LinksUpdateHookHandler.php.

References $dbr, $res, $title, DB_REPLICA, Title\newFromText(), NS_FILE, and wfGetDB().

Referenced by PageImages\Hooks\LinksUpdateHookHandler\getBlacklist().

◆ getPageImageCandidates()

PageImages\Hooks\LinksUpdateHookHandler::getPageImageCandidates ( LinksUpdate  $linksUpdate)

Returns a list of page image candidates for consideration for scoring algorithm.

Parameters
LinksUpdate$linksUpdateLinksUpdate object used to determine what page to get page images for
Returns
array $image Associative array describing an image

Definition at line 43 of file LinksUpdateHookHandler.php.

References $content, LinksUpdate\getParserOutput(), LinksUpdate\getRevision(), LinksUpdate\getTitle(), and Revision\newFromTitle().

Referenced by PageImages\Hooks\LinksUpdateHookHandler\doLinksUpdate().

◆ getRatio()

PageImages\Hooks\LinksUpdateHookHandler::getRatio ( array  $image)
protected

Returns width/height ratio of an image as displayed or 0 is not available.

Parameters
array$imageArray representing the image to get the aspect ratio from
Returns
float|int

Definition at line 224 of file LinksUpdateHookHandler.php.

Referenced by PageImages\Hooks\LinksUpdateHookHandler\getScore().

◆ getScore()

PageImages\Hooks\LinksUpdateHookHandler::getScore ( array  $image,
  $position 
)
protected

Returns score for image, the more the better, if it is less than zero, the image shouldn't be used for anything.

Parameters
array$imageAssociative array describing an image
int$positionImage order on page
Returns
float

Definition at line 128 of file LinksUpdateHookHandler.php.

References PageImages\Hooks\LinksUpdateHookHandler\getBlacklist(), PageImages\Hooks\LinksUpdateHookHandler\getRatio(), and PageImages\Hooks\LinksUpdateHookHandler\scoreFromTable().

Referenced by PageImages\Hooks\LinksUpdateHookHandler\doLinksUpdate().

◆ getUrlBlacklist()

PageImages\Hooks\LinksUpdateHookHandler::getUrlBlacklist (   $url)
private

Returns list of images on given remote blacklist page.

Not quite 100% bulletproof due to localised namespaces and so on. Though if you beat people if they add bad entries to the list... :)

Parameters
string$url
Returns
string[]

Definition at line 320 of file LinksUpdateHookHandler.php.

References $matches, $s, $t, $wgFileExtensions, Http\get(), Title\makeTitleSafe(), and NS_FILE.

Referenced by PageImages\Hooks\LinksUpdateHookHandler\getBlacklist().

◆ isImageFree()

PageImages\Hooks\LinksUpdateHookHandler::isImageFree (   $fileName)
protected

Check whether image's copyright allows it to be used freely.

Parameters
string$fileNameName of the image file
Returns
bool

Definition at line 190 of file LinksUpdateHookHandler.php.

References $file, PageImages\Hooks\LinksUpdateHookHandler\fetchFileMetadata(), and wfFindFile().

Referenced by PageImages\Hooks\LinksUpdateHookHandler\doLinksUpdate().

◆ onLinksUpdate()

static PageImages\Hooks\LinksUpdateHookHandler::onLinksUpdate ( LinksUpdate  $linksUpdate)
static

LinksUpdate hook handler, sets at most 2 page properties depending on images on page.

See also
https://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdate
Parameters
LinksUpdate$linksUpdatethe LinksUpdate object that this hook is parsing

Definition at line 31 of file LinksUpdateHookHandler.php.

◆ scoreFromTable()

PageImages\Hooks\LinksUpdateHookHandler::scoreFromTable (   $value,
array  $scores 
)
protected

Returns score based on table of ranges.

Parameters
int$valueThe number that the various bounds are compared against to calculate the score
float[]$scoresTable of scores for different ranges of $value
Returns
float

Definition at line 163 of file LinksUpdateHookHandler.php.

References wfLogWarning().

Referenced by PageImages\Hooks\LinksUpdateHookHandler\getScore().


The documentation for this class was generated from the following file: