if ( $t->isRedirect() ) {
# Page is a redirect
$colour = 'mw-redirect';
- } elseif ( $threshold > 0 &&
- $t->exists() && $t->getLength() < $threshold &&
- $t->isContentPage() ) {
+ } elseif ( $threshold > 0 && $t->isContentPage() &&
+ $t->exists() && $t->getLength() < $threshold
+ ) {
# Page is a stub
$colour = 'stub';
}
wfProfileOut( __METHOD__ );
return "<!-- ERROR -->$html";
}
+
+ if( is_string( $query ) ) {
+ // some functions withing core using this still hand over query strings
+ wfDeprecated( __METHOD__ . ' with parameter $query as string (should be array)', '1.20' );
+ $query = wfCgiToArray( $query );
+ }
$options = (array)$options;
$dummy = new DummyLinker; // dummy linker instance for bc on the hooks
* Given parameters derived from [[Image:Foo|options...]], generate the
* HTML that that syntax inserts in the page.
*
- * @param $title Title object
+ * @param $parser Parser object
+ * @param $title Title object of the file (not the currently viewed page)
* @param $file File object, or false if it doesn't exist
* @param $frameParams Array: associative array of parameters external to the media handler.
* Boolean parameters are indicated by presence or absence, the value is arbitrary and
* @param $time String: timestamp of the file, set as false for current
* @param $query String: query params for desc url
* @param $widthOption: Used by the parser to remember the user preference thumbnailsize
+ * @since 1.20
* @return String: HTML for an image, with links, wrappers, etc.
*/
- public static function makeImageLink2( Title $title, $file, $frameParams = array(),
+ public static function makeImageLink( /*Parser*/ $parser, Title $title, $file, $frameParams = array(),
$handlerParams = array(), $time = false, $query = "", $widthOption = null )
{
$res = null;
}
if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
- global $wgContLang;
- # Create a thumbnail. Alignment depends on language
- # writing direction, # right aligned for left-to-right-
- # languages ("Western languages"), left-aligned
- # for right-to-left-languages ("Semitic languages")
+ # Create a thumbnail. Alignment depends on the writing direction of
+ # the page content language (right-aligned for LTR languages,
+ # left-aligned for RTL languages)
#
- # If thumbnail width has not been provided, it is set
+ # If a thumbnail width has not been provided, it is set
# to the default user option as specified in Language*.php
if ( $fp['align'] == '' ) {
- $fp['align'] = $wgContLang->alignEnd();
+ if( $parser instanceof Parser ) {
+ $fp['align'] = $parser->getTargetLanguage()->alignEnd();
+ } else {
+ # backwards compatibility, remove with makeImageLink2()
+ global $wgContLang;
+ $fp['align'] = $wgContLang->alignEnd();
+ }
}
return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
}
'title' => $fp['title'],
'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
- $params = self::getImageLinkMTOParams( $fp, $query ) + $params;
+ $params = self::getImageLinkMTOParams( $fp, $query, $parser ) + $params;
$s = $thumb->toHtml( $params );
}
return str_replace( "\n", ' ', $prefix . $s . $postfix );
}
+ /**
+ * See makeImageLink()
+ * When this function is removed, remove if( $parser instanceof Parser ) check there too
+ * @deprecated since 1.20
+ */
+ public static function makeImageLink2( Title $title, $file, $frameParams = array(),
+ $handlerParams = array(), $time = false, $query = "", $widthOption = null ) {
+ return self::makeImageLink( null, $title, $file, $frameParams,
+ $handlerParams, $time, $query, $widthOption );
+ }
+
/**
* Get the link parameters for MediaTransformOutput::toHtml() from given
* frame parameters supplied by the Parser.
* @param $query string An optional query string to add to description page links
* @return array
*/
- private static function getImageLinkMTOParams( $frameParams, $query = '' ) {
+ private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
$mtoParams = array();
if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
$mtoParams['custom-url-link'] = $frameParams['link-url'];
if ( isset( $frameParams['link-target'] ) ) {
$mtoParams['custom-target-link'] = $frameParams['link-target'];
}
+ if ( $parser ) {
+ $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] );
+ foreach ( $extLinkAttrs as $name => $val ) {
+ // Currently could include 'rel' and 'target'
+ $mtoParams['parser-extlink-'.$name] = $val;
+ }
+ }
} elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
$mtoParams['custom-title-link'] = self::normaliseSpecialPage( $frameParams['link-title'] );
} elseif ( !empty( $frameParams['no-link'] ) ) {
if ( $redir ) {
wfProfileOut( __METHOD__ );
- return self::linkKnown( $title, "$prefix$html$inside", array(), $query ) . $trail;
+ return self::linkKnown( $title, "$prefix$html$inside", array(), wfCgiToArray( $query ) ) . $trail;
}
$href = self::getUploadUrl( $title, $query );
"$prefix$html$inside</a>$trail";
} else {
wfProfileOut( __METHOD__ );
- return self::linkKnown( $title, "$prefix$html$inside", array(), $query ) . $trail;
+ return self::linkKnown( $title, "$prefix$html$inside", array(), wfCgiToArray( $query ) ) . $trail;
}
}
* @return String: HTML fragment
*/
public static function buildRollbackLink( $rev, IContextSource $context = null ) {
+ global $wgShowRollbackEditCount, $wgMiserMode;
+
+ // To config which pages are effected by miser mode
+ $disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' );
+
if ( $context === null ) {
$context = RequestContext::getMain();
}
$query['bot'] = '1';
$query['hidediff'] = '1'; // bug 15999
}
- return self::link(
- $title,
- $context->msg( 'rollbacklink' )->escaped(),
- array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
- $query,
- array( 'known', 'noclasses' )
- );
+
+ $disableRollbackEditCount = false;
+ if( $wgMiserMode ) {
+ foreach( $disableRollbackEditCountSpecialPage as $specialPage ) {
+ if( $context->getTitle()->isSpecial( $specialPage ) ) {
+ $disableRollbackEditCount = true;
+ break;
+ }
+ }
+ }
+
+ if( !$disableRollbackEditCount && is_int( $wgShowRollbackEditCount ) && $wgShowRollbackEditCount > 0 ) {
+ $dbr = wfGetDB( DB_SLAVE );
+
+ // Up to the value of $wgShowRollbackEditCount revisions are counted
+ $res = $dbr->select( 'revision',
+ array( 'rev_id', 'rev_user_text' ),
+ // $rev->getPage() returns null sometimes
+ array( 'rev_page' => $rev->getTitle()->getArticleID() ),
+ __METHOD__,
+ array( 'USE INDEX' => 'page_timestamp',
+ 'ORDER BY' => 'rev_timestamp DESC',
+ 'LIMIT' => $wgShowRollbackEditCount + 1 )
+ );
+
+ $editCount = 0;
+ while( $row = $dbr->fetchObject( $res ) ) {
+ if( $rev->getUserText() != $row->rev_user_text ) {
+ break;
+ }
+ $editCount++;
+ }
+
+ if( $editCount > $wgShowRollbackEditCount ) {
+ $editCount_output = $context->msg( 'rollbacklinkcount-morethan' )->numParams( $wgShowRollbackEditCount )->parse();
+ } else {
+ $editCount_output = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
+ }
+
+ return self::link(
+ $title,
+ $editCount_output,
+ array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
+ $query,
+ array( 'known', 'noclasses' )
+ );
+ } else {
+ return self::link(
+ $title,
+ $context->msg( 'rollbacklink' )->escaped(),
+ array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
+ $query,
+ array( 'known', 'noclasses' )
+ );
+ }
}
/**