* (bug 8042) Make miser mode caching limits settable via $wgQueryCacheLimit
[lhc/web/wiklou.git] / includes / Linker.php
index 2a50547..f7b5c0a 100644 (file)
@@ -38,7 +38,6 @@ class Linker {
        function getInterwikiLinkAttributes( $link, $text, $class='' ) {
                global $wgContLang;
 
-               $same = ($link == $text);
                $link = urldecode( $link );
                $link = $wgContLang->checkTitleEncoding( $link );
                $link = preg_replace( '/[\\x00-\\x1f]/', ' ', $link );
@@ -200,8 +199,6 @@ class Linker {
                        return "<!-- ERROR -->{$prefix}{$text}{$trail}";
                }
 
-               $ns = $nt->getNamespace();
-               $dbkey = $nt->getDBkey();
                if ( $nt->isExternal() ) {
                        $u = $nt->getFullURL();
                        $link = $nt->getPrefixedURL();
@@ -210,6 +207,7 @@ class Linker {
 
                        $inside = '';
                        if ( '' != $trail ) {
+                               $m = array();
                                if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
                                        $inside = $m[1];
                                        $trail = $m[2];
@@ -381,8 +379,6 @@ class Linker {
         *                      the end of the link.
         */
        function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
-               $link = $nt->getPrefixedURL();
-
                $u = $nt->escapeLocalURL( $query );
 
                if ( '' == $text ) {
@@ -717,7 +713,6 @@ class Linker {
                        ### HOTFIX. Instead of breaking, return empty string.
                        return $text;
                } else {
-                       $name = $title->getDBKey();
                        $img  = new Image( $title );
                        if( $img->exists() ) {
                                $url  = $img->getURL();
@@ -770,9 +765,9 @@ class Linker {
        function userLink( $userId, $userText ) {
                $encName = htmlspecialchars( $userText );
                if( $userId == 0 ) {
-                       $contribsPage = SpecialPage::getTitleFor( 'Contributions' );
+                       $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
                        return $this->makeKnownLinkObj( $contribsPage,
-                               $encName, 'target=' . urlencode( $userText ) );
+                               $encName);
                } else {
                        $userPage = Title::makeTitle( NS_USER, $userText );
                        return $this->makeLinkObj( $userPage, $encName );
@@ -795,9 +790,9 @@ class Linker {
                        $items[] = $this->userTalkLink( $userId, $userText );
                }
                if( $userId ) {
-                       $contribsPage = SpecialPage::getTitleFor( 'Contributions' );
-                       $items[] = $this->makeKnownLinkObj( $contribsPage,
-                               wfMsgHtml( 'contribslink' ), 'target=' . urlencode( $userText ) );
+                       $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
+                       $items[] = $this->makeKnownLinkObj( $contribsPage ,
+                               wfMsgHtml( 'contribslink' ) );
                }
                if( $blockable && $wgUser->isAllowed( 'block' ) ) {
                        $items[] = $this->blockLink( $userId, $userText );
@@ -832,9 +827,9 @@ class Linker {
         * @private
         */
        function blockLink( $userId, $userText ) {
-               $blockPage = SpecialPage::getTitleFor( 'Blockip' );
+               $blockPage = SpecialPage::getTitleFor( 'Blockip', $userText );
                $blockLink = $this->makeKnownLinkObj( $blockPage,
-                       wfMsgHtml( 'blocklink' ), 'ip=' . urlencode( $userText ) );
+                       wfMsgHtml( 'blocklink' ) );
                return $blockLink;
        }
        
@@ -887,10 +882,10 @@ class Linker {
         * temporarily to a value pass. Should be adjusted further. --brion
         *
         * $param string $comment
-        * @param Title $title (to generate link to the section in autocomment)
+        * @param mixed $title Title object (to generate link to the section in autocomment) or null
         * @param bool $local Whether section links should refer to local page
         */
-       function formatComment($comment, Title $title = NULL, $local = false) {
+       function formatComment($comment, $title = NULL, $local = false) {
                wfProfileIn( __METHOD__ );
 
                global $wgContLang;
@@ -901,6 +896,7 @@ class Linker {
                # some nasty regex.
                # We look for all comments, match any text before and after the comment,
                # add a separator where needed and format the comment itself with CSS
+               $match = array();
                while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
                        $pre=$match[1];
                        $auto=$match[2];
@@ -935,7 +931,8 @@ class Linker {
 
                # format regular and media links - all other wiki formatting
                # is ignored
-               $medians = $wgContLang->getNsText( NS_MEDIA ) . ':';
+               $medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
+               $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
                while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
                        # Handle link renaming [[foo|text]] will show link as "text"
                        if( "" != $match[3] ) {
@@ -943,6 +940,7 @@ class Linker {
                        } else {
                                $text = $match[1];
                        }
+                       $submatch = array();
                        if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
                                # Media link; trail not supported.
                                $linkRegexp = '/\[\[(.*?)\]\]/';
@@ -959,7 +957,7 @@ class Linker {
                                        $match[1] = substr($match[1], 1);
                                $thelink = $this->makeLink( $match[1], $text, "", $trail );
                        }
-                       $comment = preg_replace( $linkRegexp, wfRegexReplacement( $thelink ), $comment, 1 );
+                       $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
                }
                wfProfileOut( __METHOD__ );
                return $comment;
@@ -970,12 +968,12 @@ class Linker {
         * it's non-empty, otherwise return empty string.
         *
         * @param string $comment
-        * @param Title $title
+        * @param mixed $title Title object (to generate link to section in autocomment) or null
         * @param bool $local Whether section links should refer to local page
         *
         * @return string
         */
-       function commentBlock( $comment, Title $title = NULL, $local = false ) {
+       function commentBlock( $comment, $title = NULL, $local = false ) {
                // '*' used to be the comment inserted by the software way back
                // in antiquity in case none was provided, here for backwards
                // compatability, acc. to brion -ævar
@@ -1094,6 +1092,7 @@ class Linker {
                }
                $inside = '';
                if ( '' != $trail ) {
+                       $m = array();
                        if ( preg_match( $regex, $trail, $m ) ) {
                                $inside = $m[1];
                                $trail = $m[2];