wfWarn( __METHOD__ . ': Requires $target to be a Title object.', 2 );
return "<!-- ERROR -->$html";
}
- wfProfileIn( __METHOD__ );
if ( is_string( $query ) ) {
// some functions withing core using this still hand over query strings
$dummy = new DummyLinker; // dummy linker instance for bc on the hooks
$ret = null;
- if ( !wfRunHooks( 'LinkBegin',
+ if ( !Hooks::run( 'LinkBegin',
array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) )
) {
- wfProfileOut( __METHOD__ );
return $ret;
}
$target = self::normaliseSpecialPage( $target );
# If we don't know whether the page exists, let's find out.
- wfProfileIn( __METHOD__ . '-checkPageExistence' );
if ( !in_array( 'known', $options ) && !in_array( 'broken', $options ) ) {
if ( $target->isKnown() ) {
$options[] = 'known';
$options[] = 'broken';
}
}
- wfProfileOut( __METHOD__ . '-checkPageExistence' );
$oldquery = array();
if ( in_array( "forcearticlepath", $options ) && $query ) {
}
$ret = null;
- if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
+ if ( Hooks::run( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
$ret = Html::rawElement( 'a', $attribs, $html );
}
- wfProfileOut( __METHOD__ );
return $ret;
}
* @return string
*/
private static function linkUrl( $target, $query, $options ) {
- wfProfileIn( __METHOD__ );
# We don't want to include fragments for broken links, because they
# generally make no sense.
if ( in_array( 'broken', $options ) && $target->hasFragment() ) {
}
$ret = $target->getLinkURL( $query, false, $proto );
- wfProfileOut( __METHOD__ );
return $ret;
}
* @return array
*/
private static function linkAttribs( $target, $attribs, $options ) {
- wfProfileIn( __METHOD__ );
global $wgUser;
$defaults = array();
if ( !in_array( 'noclasses', $options ) ) {
- wfProfileIn( __METHOD__ . '-getClasses' );
# Now build the classes.
$classes = array();
if ( $classes != array() ) {
$defaults['class'] = implode( ' ', $classes );
}
- wfProfileOut( __METHOD__ . '-getClasses' );
}
# Get a default title attribute.
$ret[$key] = $val;
}
}
- wfProfileOut( __METHOD__ );
return $ret;
}
*/
public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
$ret = "<strong class=\"selflink\">{$prefix}{$html}</strong>{$trail}";
- if ( !wfRunHooks( 'SelfLinkBegin', array( $nt, &$html, &$trail, &$prefix, &$ret ) ) ) {
+ if ( !Hooks::run( 'SelfLinkBegin', array( $nt, &$html, &$trail, &$prefix, &$ret ) ) ) {
return $ret;
}
$alt = self::fnamePart( $url );
}
$img = '';
- $success = wfRunHooks( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
+ $success = Hooks::run( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
if ( !$success ) {
wfDebug( "Hook LinkerMakeExternalImage changed the output of external image "
. "with url {$url} and alt text {$alt} to {$img}\n", true );
) {
$res = null;
$dummy = new DummyLinker;
- if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
+ if ( !Hooks::run( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
&$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
return $res;
}
}
global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
- wfProfileIn( __METHOD__ );
if ( $label == '' ) {
$label = $title->getPrefixedText();
}
$redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
if ( $redir ) {
- wfProfileOut( __METHOD__ );
return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
}
$href = self::getUploadUrl( $title, $query );
- wfProfileOut( __METHOD__ );
return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
$encLabel . '</a>';
}
- wfProfileOut( __METHOD__ );
return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
}
'title' => $alt
);
- if ( !wfRunHooks( 'LinkerMakeMediaLinkFile',
+ if ( !Hooks::run( 'LinkerMakeMediaLinkFile',
array( $title, $file, &$html, &$attribs, &$ret ) ) ) {
wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
. "with url {$url} and text {$html} to {$ret}\n", true );
}
$attribs['rel'] = Parser::getExternalLinkRel( $url, $title );
$link = '';
- $success = wfRunHooks( 'LinkerMakeExternalLink',
+ $success = Hooks::run( 'LinkerMakeExternalLink',
array( &$url, &$text, &$link, &$attribs, $linktype ) );
if ( !$success ) {
wfDebug( "Hook LinkerMakeExternalLink changed the output of link "
$items[] = self::emailLink( $userId, $userText );
}
- wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
+ Hooks::run( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
if ( $items ) {
- return wfMessage( 'word-separator' )->plain()
+ return wfMessage( 'word-separator' )->escaped()
. '<span class="mw-usertoollinks">'
. wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
. '</span>';
$userId = $rev->getUser( Revision::FOR_THIS_USER );
$userText = $rev->getUserText( Revision::FOR_THIS_USER );
$link = self::userLink( $userId, $userText )
- . wfMessage( 'word-separator' )->plain()
+ . wfMessage( 'word-separator' )->escaped()
. self::userToolLinks( $userId, $userText );
} else {
$link = wfMessage( 'rev-deleted-user' )->escaped();
* @return mixed|string
*/
public static function formatComment( $comment, $title = null, $local = false ) {
- wfProfileIn( __METHOD__ );
# Sanitize text a bit:
$comment = str_replace( "\n", " ", $comment );
$comment = self::formatAutocomments( $comment, $title, $local );
$comment = self::formatLinksInComment( $comment, $title, $local );
- wfProfileOut( __METHOD__ );
return $comment;
}
/**
* Converts autogenerated comments in edit summaries into section links.
+ *
* The pattern for autogen comments is / * foo * /, which makes for
* some nasty regex.
* We look for all comments, match any text before and after the comment,
* @return string Formatted comment
*/
private static function formatAutocomments( $comment, $title = null, $local = false ) {
- return preg_replace_callback(
- '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
- function ( $match ) use ( $title, $local ) {
+ // @todo $append here is something of a hack to preserve the status
+ // quo. Someone who knows more about bidi and such should decide
+ // (1) what sane rendering even *is* for an LTR edit summary on an RTL
+ // wiki, both when autocomments exist and when they don't, and
+ // (2) what markup will make that actually happen.
+ $append = '';
+ $comment = preg_replace_callback(
+ // To detect the presence of content before or after the
+ // auto-comment, we use capturing groups inside optional zero-width
+ // assertions. But older versions of PCRE can't directly make
+ // zero-width assertions optional, so wrap them in a non-capturing
+ // group.
+ '!(?:(?<=(.)))?/\*\s*(.*?)\s*\*/(?:(?=(.)))?!',
+ function ( $match ) use ( $title, $local, &$append ) {
global $wgLang;
- $pre = $match[1];
+ // Ensure all match positions are defined
+ $match += array( '', '', '', '' );
+
+ $pre = $match[1] !== '';
$auto = $match[2];
- $post = $match[3];
+ $post = $match[3] !== '';
$comment = null;
- wfRunHooks( 'FormatAutocomments', array( &$comment, $pre, $auto, $post, $title, $local ) );
+ Hooks::run( 'FormatAutocomments', array( &$comment, $pre, $auto, $post, $title, $local ) );
if ( $comment === null ) {
$link = '';
if ( $title ) {
}
if ( $pre ) {
# written summary $presep autocomment (summary /* section */)
- $pre .= wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
+ $pre = wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
}
if ( $post ) {
# autocomment $postsep written summary (/* section */ summary)
}
$auto = '<span class="autocomment">' . $auto . '</span>';
$comment = $pre . $link . $wgLang->getDirMark()
- . '<span dir="auto">' . $auto . $post . '</span>';
+ . '<span dir="auto">' . $auto;
+ $append .= '</span>';
}
return $comment;
},
$comment
);
+ return $comment . $append;
}
/**
* @param string $comment Text to format links in
* @param Title|null $title An optional title object used to links to sections
* @param bool $local Whether section links should refer to local page
+ * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), as used by WikiMap
+ *
* @return string
*/
- public static function formatLinksInComment( $comment, $title = null, $local = false ) {
+ public static function formatLinksInComment( $comment, $title = null, $local = false, $wikiId = null ) {
return preg_replace_callback(
'/
\[\[
\]\]
([^[]*) # 3. link trail (the text up until the next link)
/x',
- function ( $match ) use ( $title, $local ) {
+ function ( $match ) use ( $title, $local, $wikiId ) {
global $wgContLang;
$medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
$newTarget = clone ( $title );
$newTarget->setFragment( '#' . $target->getFragment() );
$target = $newTarget;
+
}
- $thelink = Linker::link(
- $target,
- $linkText . $inside
- ) . $trail;
+
+ if ( $wikiId !== null ) {
+ $thelink = Linker::makeExternalLink(
+ WikiMap::getForeignURL( $wikiId, $target->getPrefixedURL() ),
+ $linkText . $inside,
+ true
+ ) . $trail;
+ } else {
+ $thelink = Linker::link(
+ $target,
+ $linkText . $inside
+ ) . $trail;
+ }
+
}
}
if ( $thelink ) {
# ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
# (from CurrentPage/CurrentSubPage)
- wfProfileIn( __METHOD__ );
$ret = $target; # default return value is no change
# Some namespaces don't allow subpages,
}
}
- wfProfileOut( __METHOD__ );
return $ret;
}
$inner = self::buildRollbackLink( $rev, $context, $editCount );
if ( !in_array( 'noBrackets', $options ) ) {
- $inner = $context->msg( 'brackets' )->rawParams( $inner )->plain();
+ $inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
}
return '<span class="mw-rollback-link">' . $inner . '</span>';
) {
global $wgShowRollbackEditCount, $wgMiserMode;
- // To config which pages are effected by miser mode
+ // To config which pages are affected by miser mode
$disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' );
if ( $context === null ) {
$section = false, $more = null
) {
global $wgLang;
- wfProfileIn( __METHOD__ );
$outText = '';
if ( count( $templates ) > 0 ) {
$outText .= '</ul>';
}
- wfProfileOut( __METHOD__ );
return $outText;
}
* @return string HTML output
*/
public static function formatHiddenCategories( $hiddencats ) {
- wfProfileIn( __METHOD__ );
$outText = '';
if ( count( $hiddencats ) > 0 ) {
}
$outText .= '</ul>';
}
- wfProfileOut( __METHOD__ );
return $outText;
}
* escape), or false for no title attribute
*/
public static function titleAttrib( $name, $options = null ) {
- wfProfileIn( __METHOD__ );
$message = wfMessage( "tooltip-$name" );
}
}
- wfProfileOut( __METHOD__ );
return $tooltip;
}
if ( isset( self::$accesskeycache[$name] ) ) {
return self::$accesskeycache[$name];
}
- wfProfileIn( __METHOD__ );
$message = wfMessage( "accesskey-$name" );
}
}
- wfProfileOut( __METHOD__ );
self::$accesskeycache[$name] = $accesskey;
return self::$accesskeycache[$name];
}
static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
wfDeprecated( __METHOD__, '1.21' );
- wfProfileIn( __METHOD__ );
$query = wfCgiToArray( $query );
list( $inside, $trail ) = self::splitTrail( $trail );
if ( $text === '' ) {
$ret = self::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
- wfProfileOut( __METHOD__ );
return $ret;
}
) {
wfDeprecated( __METHOD__, '1.21' );
- wfProfileIn( __METHOD__ );
-
if ( $text == '' ) {
$text = self::linkText( $title );
}
$ret = self::link( $title, "$prefix$text$inside", $attribs, $query,
array( 'known', 'noclasses' ) ) . $trail;
- wfProfileOut( __METHOD__ );
return $ret;
}