Go to the documentation of this file.
32 $handler =
new self();
33 $handler->doLinksUpdate( $linksUpdate );
44 global $wgPageImagesLeadSectionOnly;
47 if ( $wgPageImagesLeadSectionOnly ) {
52 Revision::READ_LATEST );
57 $section =
$content->getSection( 0 );
61 $po = $section->getParserOutput( $linksUpdate->
getTitle() );
69 return $po ? $po->getExtensionData(
'pageImages' ) : [];
78 if ( $images ===
null ) {
85 foreach ( $images as $image ) {
86 $fileName = $image[
'filename'];
88 if ( !isset( $scores[$fileName] ) ) {
89 $scores[$fileName] = -1;
92 $scores[$fileName] = max( $scores[$fileName], $this->
getScore( $image, $counter++ ) );
98 foreach ( $scores as $name => $score ) {
100 if ( !$image || $score > $scores[$image] ) {
103 if ( ( !$free_image || $score > $scores[$free_image] ) && $this->
isImageFree( $name ) ) {
114 if ( $image && $image !== $free_image ) {
128 protected function getScore( array $image, $position ) {
129 global $wgPageImagesScores;
131 if ( isset( $image[
'handler'] ) ) {
133 $score = $this->
scoreFromTable( $image[
'handler'][
'width'], $wgPageImagesScores[
'width'] );
136 $score = $this->
scoreFromTable( $image[
'fullwidth'], $wgPageImagesScores[
'galleryImageWidth'] );
139 if ( isset( $wgPageImagesScores[
'position'][$position] ) ) {
140 $score += $wgPageImagesScores[
'position'][$position];
143 $ratio = intval( $this->
getRatio( $image ) * 10 );
144 $score += $this->
scoreFromTable( $ratio, $wgPageImagesScores[
'ratio'] );
147 if ( isset( $blacklist[$image[
'filename']] ) ) {
168 ksort( $scores, SORT_NUMERIC );
169 foreach ( $scores as $upperBoundary => $score ) {
172 if ( $value <= $upperBoundary ) {
177 if ( !is_numeric( $lastScore ) ) {
178 wfLogWarning(
'The PageImagesScores setting must only contain numeric values!' );
181 return (
float)$lastScore;
210 $format->setSingleLanguage(
true );
214 return $format->fetchExtendedMetadata(
$file );
225 $width = $image[
'fullwidth'];
226 $height = $image[
'fullheight'];
228 if ( !$width || !$height ) {
232 return $width / $height;
242 global $wgPageImagesBlacklist, $wgPageImagesBlacklistExpiry,
$wgMemc;
243 static $list =
false;
245 if ( $list !==
false ) {
249 $key =
wfMemcKey(
'pageimages',
'blacklist' );
251 if ( $list !==
false ) {
255 wfDebug( __METHOD__ .
"(): cache miss\n" );
258 foreach ( $wgPageImagesBlacklist as
$source ) {
264 $list = array_merge( $list, $this->
getUrlBlacklist( $source[
'url'] ) );
268 __METHOD__ .
"(): unrecognized image blacklist type '{$source['type']}'" );
272 $list = array_flip( $list );
273 $wgMemc->set( $key, $list, $wgPageImagesBlacklistExpiry );
290 $id =
$dbr->selectField(
293 [
'page_namespace' =>
$title->getNamespace(),
'page_title' =>
$title->getDBkey() ],
300 [
'pl_from' => $id,
'pl_namespace' =>
NS_FILE ],
303 foreach (
$res as $row ) {
304 $list[] = $row->pl_title;
324 $text =
Http::get( $url, [
'timeout' => 3 ], __METHOD__ );
327 if ( $text && preg_match_all( $regex, $text,
$matches ) ) {
332 $list[] =
$t->getDBkey();
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
getRatio(array $image)
Returns width/height ratio of an image as displayed or 0 is not available.
fetchFileMetadata( $file)
Fetch file metadata.
Class the manages updates of *_link tables as well as similar extension-managed tables.
$wgFileExtensions
This is the list of preferred extensions for uploading files.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
doLinksUpdate(LinksUpdate $linksUpdate)
getDbBlacklist( $dbName, $page)
Returns list of images linked by the given blacklist page.
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
static onLinksUpdate(LinksUpdate $linksUpdate)
LinksUpdate hook handler, sets at most 2 page properties depending on images on page.
An IContextSource implementation which will inherit context from another source but allow individual ...
Implements some public methods and some protected utility functions which are required by multiple ch...
getBlacklist()
Returns a list of images blacklisted from influencing this extension's output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static get( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
getPageImageCandidates(LinksUpdate $linksUpdate)
Returns a list of page image candidates for consideration for scoring algorithm.
getTitle()
Return the title object of the page being updated.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
scoreFromTable( $value, array $scores)
Returns score based on table of ranges.
Handler for the "LinksUpdate" hook.
getParserOutput()
Returns parser output.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
getUrlBlacklist( $url)
Returns list of images on given remote blacklist page.
isImageFree( $fileName)
Check whether image's copyright allows it to be used freely.
wfFindFile( $title, $options=[])
Find a file.
Represents a title within MediaWiki.
static getPropName( $isFree)
Get property name used in page_props table.
getScore(array $image, $position)
Returns score for image, the more the better, if it is less than zero, the image shouldn't be used fo...
wfMemcKey(... $args)
Make a cache key for the local wiki.
Various HTTP related functions.