Page MenuHomePhabricator

badimageexceptions_svnHEAD.diff

Authored By
bzimport
Nov 21 2014, 9:14 PM
Size
4 KB
Referenced Files
None
Subscribers
None

badimageexceptions_svnHEAD.diff

Index: includes/Parser.php
===================================================================
--- includes/Parser.php (revision 15161)
+++ includes/Parser.php (working copy)
@@ -1360,6 +1360,7 @@
}
$selflink = $this->mTitle->getPrefixedText();
+ $selfdbkey = $this->mTitle->getPrefixedDBkey();
wfProfileOut( $fname.'-setup' );
$checkVariantLink = sizeof($wgContLang->getVariants())>1;
@@ -1510,7 +1511,7 @@
if ( $ns == NS_IMAGE ) {
wfProfileIn( "$fname-image" );
- if ( !wfIsBadImage( $nt->getDBkey() ) ) {
+ if ( !wfIsBadImage( $nt->getDBkey(), $selfdbkey ) ) {
# recursively parse links inside the image caption
# actually, this will parse them in any other parameters, too,
# but it might be hard to fix that, and it doesn't matter ATM
@@ -4144,7 +4145,7 @@
$ig = new ImageGallery();
$ig->setShowBytes( false );
$ig->setShowFilename( false );
- $ig->setParsing();
+ $ig->setTargetPage( $this->mTitle->getPrefixedDBkey() );
$ig->useSkin( $this->mOptions->getSkin() );
if( isset( $params['caption'] ) )
Index: includes/Image.php
===================================================================
--- includes/Image.php (revision 15161)
+++ includes/Image.php (working copy)
@@ -2378,10 +2378,16 @@
/**
* Determine if an image exists on the 'bad image list'.
*
- * @param $name String: the image name to check
+ * The bad image list (MediaWiki:bad_image_list) should consist of lines
+ * of the form "* [[:Image:Bad image.jpg]]" optionally followed by text
+ * containing links to pages the image should be allowed on. Any lines
+ * not in this format are silently ignored.
+ *
+ * @param $name String: the image name to check (DBkey without prefix)
+ * @param $page String: the page being parsed (DBkey with ns prefix)
* @return bool
*/
-function wfIsBadImage( $name ) {
+function wfIsBadImage( $name, $page ) {
static $titleList = false;
if( !$titleList ) {
@@ -2389,14 +2395,32 @@
$titleList = array();
$lines = explode( "\n", wfMsgForContent( 'bad_image_list' ) );
foreach( $lines as $line ) {
- if( preg_match( '/^\*\s*\[\[:?(.*?)\]\]/i', $line, $matches ) ) {
- $title = Title::newFromText( $matches[1] );
- if( is_object( $title ) && $title->getNamespace() == NS_IMAGE )
- $titleList[ $title->getDBkey() ] = true;
+ if( !preg_match( '/^\*\s*\[\[:?(.*?)(?:\|.*?)?\]\](.*)/i', $line, $matches ) )
+ continue;
+ $imageTitle = Title::newFromText( $matches[1] );
+ if( !is_object( $imageTitle ) || $imageTitle->getNamespace() != NS_IMAGE )
+ continue;
+ $imageKey = $imageTitle->getDBkey();
+ $titleList[ $imageKey ] = array();
+ wfDebug( "Adding $imageKey to the bad image list.\n" );
+
+ if( !preg_match_all( '/\[\[:?(.*?)(?:\|.*?)?\]\]/', $matches[2], $exceptions ) )
+ continue;
+ foreach( $exceptions[1] as $pageName ) {
+ $pageTitle = Title::newFromText( $pageName );
+ if( !is_object( $pageTitle ) )
+ continue;
+ $pageKey = $pageTitle->getPrefixedDBkey();
+ $titleList[ $imageKey ][ $pageKey ] = true;
+ wfDebug( "Allowing $imageKey on $pageKey.\n" );
}
}
}
- return array_key_exists( $name, $titleList );
+
+ wfDebug( "Looking for $name (on $page) in the bad image list.\n" );
+
+ return ( array_key_exists( $name, $titleList ) &&
+ !array_key_exists( $page, $titleList[$name] ) );
}
Index: includes/ImageGallery.php
===================================================================
--- includes/ImageGallery.php (revision 15161)
+++ includes/ImageGallery.php (working copy)
@@ -20,9 +20,9 @@
var $mSkin = false;
/**
- * Is the gallery on a wiki page (i.e. not a special page)
+ * Name (prefixed DBkey) of the page the gallery is to be on.
*/
- var $mParsing;
+ var $mTargetPage;
/**
* Create a new image gallery object.
@@ -31,14 +31,17 @@
$this->mImages = array();
$this->mShowBytes = true;
$this->mShowFilename = true;
- $this->mParsing = false;
+ $this->mTargetPage = null;
}
/**
- * Set the "parse" bit so we know to hide "bad" images
+ * Set the name (prefixed DBkey) of the page we're generating
+ * the gallery for, so we know whether to hide "bad" images.
+ *
+ * @param $page String: page the gallery is to be on
*/
- function setParsing( $val = true ) {
- $this->mParsing = $val;
+ function setTargetPage( $page ) {
+ $this->mTargetPage = $page;
}
/**
@@ -152,7 +155,7 @@
# If we're dealing with a non-image, or a blacklisted image,
# spit out the name and be done with it
if( $nt->getNamespace() != NS_IMAGE
- || ( $this->mParsing && wfIsBadImage( $nt->getDBkey() ) ) ) {
+ || ( isset( $this->mTargetPage ) && wfIsBadImage( $nt->getDBkey(), $this->mTargetPage ) ) ) {
$s .=
(($i%4==0) ? "<tr>\n" : '') .
'<td><div class="gallerybox" style="height: 152px;">' .

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2421
Default Alt Text
badimageexceptions_svnHEAD.diff (4 KB)

Event Timeline