Removed remaining profile calls
[lhc/web/wiklou.git] / includes / Linker.php
index 0e9ef2b..7b7c21b 100644 (file)
@@ -197,7 +197,6 @@ class Linker {
                        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
@@ -209,9 +208,9 @@ class Linker {
                $dummy = new DummyLinker; // dummy linker instance for bc on the hooks
 
                $ret = null;
-               if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html,
-               &$customAttribs, &$query, &$options, &$ret ) ) ) {
-                       wfProfileOut( __METHOD__ );
+               if ( !Hooks::run( 'LinkBegin',
+                       array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) )
+               ) {
                        return $ret;
                }
 
@@ -219,7 +218,6 @@ class Linker {
                $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';
@@ -227,7 +225,6 @@ class Linker {
                                $options[] = 'broken';
                        }
                }
-               wfProfileOut( __METHOD__ . '-checkPageExistence' );
 
                $oldquery = array();
                if ( in_array( "forcearticlepath", $options ) && $query ) {
@@ -250,11 +247,10 @@ class Linker {
                }
 
                $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;
        }
 
@@ -279,7 +275,6 @@ class Linker {
         * @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() ) {
@@ -305,7 +300,6 @@ class Linker {
                }
 
                $ret = $target->getLinkURL( $query, false, $proto );
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -319,12 +313,10 @@ class Linker {
         * @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();
 
@@ -345,7 +337,6 @@ class Linker {
                        if ( $classes != array() ) {
                                $defaults['class'] = implode( ' ', $classes );
                        }
-                       wfProfileOut( __METHOD__ . '-getClasses' );
                }
 
                # Get a default title attribute.
@@ -369,7 +360,6 @@ class Linker {
                                $ret[$key] = $val;
                        }
                }
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -410,7 +400,7 @@ class Linker {
         */
        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;
                }
 
@@ -496,7 +486,7 @@ class Linker {
                        $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 );
@@ -550,7 +540,7 @@ class Linker {
        ) {
                $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;
                }
@@ -932,7 +922,6 @@ class Linker {
                }
 
                global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
-               wfProfileIn( __METHOD__ );
                if ( $label == '' ) {
                        $label = $title->getPrefixedText();
                }
@@ -945,19 +934,16 @@ class Linker {
                        $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 ) );
        }
 
@@ -1030,7 +1016,7 @@ class Linker {
                        '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 );
@@ -1089,7 +1075,7 @@ class Linker {
                }
                $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 "
@@ -1175,10 +1161,10 @@ class Linker {
                        $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>';
@@ -1265,7 +1251,7 @@ class Linker {
                        $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();
@@ -1294,7 +1280,6 @@ class Linker {
         * @return mixed|string
         */
        public static function formatComment( $comment, $title = null, $local = false ) {
-               wfProfileIn( __METHOD__ );
 
                # Sanitize text a bit:
                $comment = str_replace( "\n", " ", $comment );
@@ -1305,12 +1290,12 @@ class Linker {
                $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,
@@ -1323,16 +1308,30 @@ class Linker {
         * @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 ) {
@@ -1360,7 +1359,7 @@ class Linker {
                                        }
                                        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)
@@ -1368,12 +1367,14 @@ class Linker {
                                        }
                                        $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;
        }
 
        /**
@@ -1490,11 +1491,13 @@ class Linker {
                # Foobar -- normal
                # :Foobar -- override special treatment of prefix (images, language links)
                # /Foobar -- convert to CurrentPage/Foobar
-               # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
+               # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
                # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
-               # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
+               # ../Foobar -- convert to CurrentPage/Foobar,
+               #              (from CurrentPage/CurrentSubPage)
+               # ../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,
@@ -1538,7 +1541,7 @@ class Linker {
                                                $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
                                                # / at the end means don't show full path
                                                if ( substr( $nodotdot, -1, 1 ) === '/' ) {
-                                                       $nodotdot = substr( $nodotdot, 0, -1 );
+                                                       $nodotdot = rtrim( $nodotdot, '/' );
                                                        if ( $text === '' ) {
                                                                $text = $nodotdot . $suffix;
                                                        }
@@ -1553,7 +1556,6 @@ class Linker {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -1808,7 +1810,7 @@ class Linker {
                $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>';
@@ -1893,7 +1895,7 @@ class Linker {
        ) {
                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 ) {
@@ -1976,7 +1978,6 @@ class Linker {
                $section = false, $more = null
        ) {
                global $wgLang;
-               wfProfileIn( __METHOD__ );
 
                $outText = '';
                if ( count( $templates ) > 0 ) {
@@ -2056,7 +2057,6 @@ class Linker {
 
                        $outText .= '</ul>';
                }
-               wfProfileOut( __METHOD__ );
                return $outText;
        }
 
@@ -2068,7 +2068,6 @@ class Linker {
         * @return string HTML output
         */
        public static function formatHiddenCategories( $hiddencats ) {
-               wfProfileIn( __METHOD__ );
 
                $outText = '';
                if ( count( $hiddencats ) > 0 ) {
@@ -2085,7 +2084,6 @@ class Linker {
                        }
                        $outText .= '</ul>';
                }
-               wfProfileOut( __METHOD__ );
                return $outText;
        }
 
@@ -2114,7 +2112,6 @@ class Linker {
         *   escape), or false for no title attribute
         */
        public static function titleAttrib( $name, $options = null ) {
-               wfProfileIn( __METHOD__ );
 
                $message = wfMessage( "tooltip-$name" );
 
@@ -2143,7 +2140,6 @@ class Linker {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $tooltip;
        }
 
@@ -2163,7 +2159,6 @@ class Linker {
                if ( isset( self::$accesskeycache[$name] ) ) {
                        return self::$accesskeycache[$name];
                }
-               wfProfileIn( __METHOD__ );
 
                $message = wfMessage( "accesskey-$name" );
 
@@ -2179,7 +2174,6 @@ class Linker {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                self::$accesskeycache[$name] = $accesskey;
                return self::$accesskeycache[$name];
        }
@@ -2287,7 +2281,6 @@ class Linker {
        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 === '' ) {
@@ -2296,7 +2289,6 @@ class Linker {
 
                $ret = self::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -2321,7 +2313,6 @@ class Linker {
        ) {
                wfDeprecated( __METHOD__, '1.21' );
 
-               wfProfileIn( __METHOD__ );
 
                if ( $text == '' ) {
                        $text = self::linkText( $title );
@@ -2336,7 +2327,6 @@ class Linker {
                $ret = self::link( $title, "$prefix$text$inside", $attribs, $query,
                        array( 'known', 'noclasses' ) ) . $trail;
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }