quotes
[lhc/web/wiklou.git] / includes / Linker.php
index 0b13506..25fad56 100644 (file)
@@ -1,11 +1,13 @@
 <?php
-
 /**
  * Split off some of the internal bits from Skin.php.
  * These functions are used for primarily page content:
  * links, embedded images, table of contents. Links are
  * also used in the skin.
- *
+ * @package MediaWiki
+ */
+
+/**
  * For the moment, Skin is a descendent class of Linker.
  * In the future, it should probably be further split
  * so that ever other bit of the wiki doesn't have to
  *
  * @package MediaWiki
  */
-
 class Linker {
        var $linktrail ; # linktrail regexp
        var $postParseLinkColour = false;
 
+       /** @todo document */
        function Linker() {
                global $wgContLang;
                $this->linktrail = $wgContLang->linkTrail();
@@ -37,13 +39,14 @@ class Linker {
                return wfSetVar( $this->postParseLinkColour, $setting );
        }
 
+       /** @todo document */
        function getExternalLinkAttributes( $link, $text, $class='' ) {
                global $wgContLang;
 
                $same = ($link == $text);
                $link = urldecode( $link );
                $link = $wgContLang->checkTitleEncoding( $link );
-               $link = str_replace( '_', ' ', $link );
+               $link = preg_replace( '/[\\x00-\\x1f_]/', ' ', $link );
                $link = htmlspecialchars( $link );
 
                $r = ($class != '') ? " class='$class'" : " class='external'";
@@ -54,6 +57,7 @@ class Linker {
                return $r;
        }
 
+       /** @todo document */
        function getInternalLinkAttributes( $link, $text, $broken = false ) {
                $link = urldecode( $link );
                $link = str_replace( '_', ' ', $link );
@@ -109,6 +113,7 @@ class Linker {
                return $result;
        }
 
+       /** @todo document */
        function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
                $nt = Title::newFromText( $title );
                if ($nt) {
@@ -119,6 +124,7 @@ class Linker {
                }
        }
 
+       /** @todo document */
        function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
                $nt = Title::newFromText( $title );
                if ($nt) {
@@ -129,6 +135,7 @@ class Linker {
                }
        }
 
+       /** @todo document */
        function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
                $nt = Title::newFromText( $title );
                if ($nt) {
@@ -169,12 +176,16 @@ class Linker {
                                        $trail = $m[2];
                                }
                        }
-                       # Assume $this->postParseLinkColour(). This prevents
-                       # interwiki links from being parsed as external links.
-                       global $wgInterwikiLinkHolders;
                        $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
-                       $nr = array_push($wgInterwikiLinkHolders, $t);
-                       $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
+                       if( $this->postParseLinkColour ) {
+                               # There's no existence check, but this will prevent
+                               # interwiki links from being parsed as external links.
+                               global $wgInterwikiLinkHolders;
+                               $nr = array_push($wgInterwikiLinkHolders, $t);
+                               $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
+                       } else {
+                               return $t;
+                       }
                } elseif ( 0 == $ns && "" == $dbkey ) {
                        # A self-link with a fragment; skip existence check.
                        $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
@@ -215,11 +226,16 @@ class Linker {
                                $threshold = $wgUser->getOption('stubthreshold') ;
                                if ( $threshold > 0 ) {
                                        $dbr =& wfGetDB( DB_SLAVE );
-                                       $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
-                                               'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
+                                       $s = $dbr->selectRow(
+                                               array( 'page', 'text' ),
+                                               array( 'LENGTH(old_text) AS x',
+                                                       'page_namespace',
+                                                       'page_is_redirect' ),
+                                               array( 'page_id' => $aid,
+                                                       'old_id = page_latest' ), $fname ) ;
                                        if ( $s !== false ) {
                                                $size = $s->x;
-                                               if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
+                                               if ( $s->page_is_redirect OR $s->page_namespace != NS_MAIN ) {
                                                        $size = $threshold*2 ; # Really big
                                                }
                                        } else {
@@ -356,6 +372,7 @@ class Linker {
                return $s;
        }
 
+       /** @todo document */
        function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                $u = $nt->escapeLocalURL( $query );
                if ( '' == $text ) {
@@ -371,6 +388,7 @@ class Linker {
                return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
        }
 
+       /** @todo document */
        function fnamePart( $url ) {
                $basename = strrchr( $url, '/' );
                if ( false === $basename ) {
@@ -381,6 +399,7 @@ class Linker {
                return htmlspecialchars( $basename );
        }
 
+       /** @todo document */
        function makeImage( $url, $alt = '' ) {
                global $wgOut;
                if ( '' == $alt ) {
@@ -390,11 +409,13 @@ class Linker {
                return $s;
        }
 
+       /** @todo document */
        function makeImageLink( $name, $url, $alt = '' ) {
                $nt = Title::makeTitleSafe( NS_IMAGE, $name );
                return $this->makeImageLinkObj( $nt, $alt );
        }
 
+       /** @todo document */
        function makeImageLinkObj( $nt, $alt = '' ) {
                global $wgContLang, $wgUseImageResize;
                $img   = Image::newFromTitle( $nt );
@@ -505,7 +526,7 @@ class Linker {
                $u = $nt->escapeLocalURL();
                if ( $url == '' ) {
                        $s = wfMsg( 'missingimage', $img->getName() );
-                       $s .= "<br>{$alt}<br>{$url}<br>\n";
+                       $s .= "<br />{$alt}<br />{$url}<br />\n";
                } else {
                        $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
                                 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
@@ -606,11 +627,13 @@ class Linker {
                return str_replace("\n", ' ', $s);
        }
 
+       /** @todo document */
        function makeMediaLink( $name, $url, $alt = '' ) {
                $nt = Title::makeTitleSafe( NS_IMAGE, $name );
                return $this->makeMediaLinkObj( $nt, $alt );
        }
 
+       /** @todo document */
        function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {             
                if ( ! isset( $nt ) )
                {
@@ -634,6 +657,7 @@ class Linker {
                return $s;
        }
 
+       /** @todo document */
        function specialLink( $name, $key = '' ) {
                global $wgContLang;
 
@@ -643,8 +667,13 @@ class Linker {
                  wfMsg( $key ) );
        }
 
-       function makeExternalLink( $url, $text, $escape = true ) {
-               $style = $this->getExternalLinkAttributes( $url, $text );
+       /** @todo document */
+       function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
+               $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
+               global $wgNoFollowLinks;
+               if( $wgNoFollowLinks ) {
+                       $style .= ' rel="nofollow"';
+               }
                $url = htmlspecialchars( $url );
                if( $escape ) {
                        $text = htmlspecialchars( $text );
@@ -730,38 +759,43 @@ class Linker {
                wfProfileOut( $fname );
                return $comment;
        }
-       
-       function tocIndent($level) {
-               return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
+
+       /** @todo document */
+       function tocIndent() {
+               return "\n<ul>";
        }
 
+       /** @todo document */
        function tocUnindent($level) {
-               return str_repeat( "</div>\n", $level>0 ? $level : 0 );
+               return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ? $level : 0 );
        }
 
        /**
         * parameter level defines if we are on an indentation level
         */
-       function tocLine( $anchor, $tocline, $level ) {
-               $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
-               if($level) {
-                       return $link."\n";
-               } else {
-                       return '<div class="tocline">'.$link."</div>\n";
-               }
-
-       }
-
-       function tocTable($toc) {
-               # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
-               # try min-width & co when somebody gets a chance
-               $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
-               return
-               '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
-               '<b>'.wfMsgForContent('toc').'</b>' .
-               $hideline .
-               '</td></tr><tr id="tocinside"><td>'."\n".
-               $toc."</td></tr></table>\n";
+       function tocLine( $anchor, $tocline, $tocnumber, $level ) {
+               return "\n<li class='toclevel-$level'><a href=\"#" . $anchor . '"><span class="tocnumber">' . $tocnumber . '</span> <span class="toctext">' . $tocline . '</span></a>';
+       }
+
+       /** @todo document */
+       function tocLineEnd() {
+               return "</li>\n";
+       }
+
+       /** @todo document */
+       function tocList($toc) {
+               return "<div id='toc'>\n" 
+                          . "<div id='toctitle'><h2>" . wfMsg('toc') . "</h2></div>\n"
+                    . $toc
+                                . "</ul>\n</div>\n"
+                                . '<script type="text/javascript">'
+                                . ' if (window.showTocToggle) {'
+                                . ' var tocShowText = "' . addslashes( wfMsg('showtoc') ) . '";'
+                                . ' var tocHideText = "' . addslashes( wfMsg('hidetoc') ) . '"; '
+                                . ' showTocToggle();'
+                                . ' } '
+                                . '</script>'
+                                . "<div class='visualClear'></div>\n";
        }
 
        /**
@@ -774,6 +808,7 @@ class Linker {
                return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
        }
 
+       /** @todo document */
        function editSectionScript( $nt, $section, $head ) {
                global $wgRequest;
                if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
@@ -783,6 +818,7 @@ class Linker {
                return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
        }
 
+       /** @todo document */
        function editSectionLinkForOther( $title, $section ) {
                global $wgRequest;
                global $wgContLang;
@@ -802,6 +838,7 @@ class Linker {
 
        }
 
+       /** @todo document */
        function editSectionLink( $nt, $section ) {
                global $wgRequest;
                global $wgContLang;
@@ -824,16 +861,6 @@ class Linker {
                        $nearside = 'left';
                }
                return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
-
        }
-
-       /**
-        * @access public
-        */
-       function suppressUrlExpansion() {
-               return false;
-       }
-
 }
-
-?>
\ No newline at end of file
+?>