Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / Skin.php
index ca352fc..fe1e947 100644 (file)
@@ -3,6 +3,7 @@
 /**
  *
  * @package MediaWiki
+ * @subpackage Skins
  */
 
 /**
@@ -13,27 +14,6 @@ if( defined( "MEDIAWIKI" ) ) {
 # See skin.doc
 require_once( 'Image.php' );
 
-# These are the INTERNAL names, which get mapped directly to class names and
-# file names in ./skins/. For display purposes, the Language class has
-# internationalized names
-#
-/*
-$wgValidSkinNames = array(
-       'standard'      => 'Standard',
-       'nostalgia'     => 'Nostalgia',
-       'cologneblue'   => 'CologneBlue'
-);
-if( $wgUsePHPTal ) {
-       #$wgValidSkinNames[] = 'PHPTal';
-       #$wgValidSkinNames['davinci'] = 'DaVinci';
-       #$wgValidSkinNames['mono'] = 'Mono';
-       #$wgValidSkinNames['monobookminimal'] = 'MonoBookMinimal';
-       $wgValidSkinNames['monobook'] = 'MonoBook';
-       $wgValidSkinNames['myskin'] = 'MySkin';
-       $wgValidSkinNames['chick'] = 'Chick';
-}
-*/
-
 # Get a list of all skins available in /skins/
 # Build using the regular expression '^(.*).php$'
 # Array keys are all lower case, array value keep the case used by filename
@@ -99,12 +79,10 @@ class Skin {
        var $rc_cache ; # Cache for Enhanced Recent Changes
        var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
        var $rcMoveIndex;
-       var $postParseLinkColour = true;
+       var $postParseLinkColour = false;
        /**#@-*/
 
        function Skin() {
-               global $wgUseOldExistenceCheck;
-               $postParseLinkColour = !$wgUseOldExistenceCheck;
                $this->linktrail = wfMsg('linktrail');
        }
 
@@ -296,7 +274,7 @@ class Skin {
                }
                else $a = array( 'bgcolor' => '#FFFFFF' );
                if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
-                 (!$wgTitle->isProtected() || $wgUser->isSysop()) ) {
+                 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
                        $t = wfMsg( 'editthispage' );
                        $oid = $red = '';
                        if ( !empty($redirect) && $redirect == 'no' ) {
@@ -473,7 +451,7 @@ class Skin {
                        $s .= '<br/><hr/>';
 
                        # get a big array of the parents tree
-                       $parenttree = $wgTitle->getCategorieBrowser();
+                       $parenttree = $wgTitle->getParentCategoryTree();
 
                        # Render the array as a serie of links
                        function walkThrough ($tree) {
@@ -491,7 +469,7 @@ class Skin {
                                        # add our current element to the list
                                        $eltitle = Title::NewFromText($element);
                                        # FIXME : should be makeLink() [AV]
-                                       $return .= $sk->makeKnownLink($element, $eltitle->getText()).' &gt; ';
+                                       $return .= $sk->makeLink($element, $eltitle->getText()).' &gt; ';
                                }
                                return $return;
                        }
@@ -599,7 +577,7 @@ class Skin {
 
        function getUndeleteLink() {
                global $wgUser, $wgTitle, $wgContLang, $action;
-               if( $wgUser->isSysop() &&
+               if( $wgUser->isAllowed('rollback') &&
                        (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
                        ($n = $wgTitle->isDeleted() ) ) {
                        return wfMsg( 'thisisdeleted',
@@ -802,10 +780,11 @@ class Skin {
                                        }
                                }
                        }
-                       if ( $wgUser->isSysop() && $wgTitle->getArticleId() ) {
-                               $s .= "\n<br />" . $this->deleteThisPage() .
-                               $sep . $this->protectThisPage() .
-                               $sep . $this->moveThisPage();
+                       if ( $wgTitle->getArticleId() ) {
+                               $s .= "\n<br />";
+                               if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
+                               if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
+                               if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
                        }
                        $s .= "<br />\n" . $this->otherLanguages();
                }
@@ -920,6 +899,10 @@ class Skin {
                return $s;
        }
 
+       /**
+        * show a drop-down box of special pages
+        * @TODO crash bug913. Need to be rewrote completly.
+        */
        function specialPagesList() {
                global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript;
                require_once('SpecialPage.php');
@@ -1022,7 +1005,7 @@ class Skin {
                global $wgUser, $wgOut, $wgTitle, $wgRequest;
 
                $diff = $wgRequest->getVal( 'diff' );
-               if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isSysop() ) {
+               if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
                        $n = $wgTitle->getPrefixedText();
                        $t = wfMsg( 'deletethispage' );
 
@@ -1037,7 +1020,7 @@ class Skin {
                global $wgUser, $wgOut, $wgTitle, $wgRequest;
 
                $diff = $wgRequest->getVal( 'diff' );
-               if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isSysop() ) {
+               if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
                        $n = $wgTitle->getPrefixedText();
 
                        if ( $wgTitle->isProtected() ) {
@@ -1658,7 +1641,6 @@ class Skin {
 
        function makeImage( $url, $alt = '' ) {
                global $wgOut;
-
                if ( '' == $alt ) {
                        $alt = $this->fnamePart( $url );
                }
@@ -1698,7 +1680,7 @@ class Skin {
                $mwWidth  =& MagicWord::get( MAG_IMG_WIDTH );
                $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
                $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
-               $alt = $part[count($part)-1];
+               $alt = '';
 
                $height = $framed = $thumb = false;
                $manual_thumb = "" ;
@@ -1734,6 +1716,8 @@ class Skin {
                                }
                        } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
                                $framed=true;
+                       } else {
+                               $alt = $val;
                        }
                }
                if ( 'center' == $align )
@@ -1772,22 +1756,17 @@ class Skin {
                        if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
                }
 
-               if ( empty( $alt ) ) {
-                       $alt = preg_replace( '/\.(.+?)^/', '', $img->getName() );
-               }
                $alt = preg_replace( '/<[^>]*>/', '', $alt );
                $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
                $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
 
                $u = $nt->escapeLocalURL();
-               $uf = $nt->escapeFullURL();
-               if ( $url == '' )
-               {
+               if ( $url == '' ) {
                        $s = wfMsg( 'missingimage', $img->getName() );
                        $s .= "<br>{$alt}<br>{$url}<br>\n";
                } else {
                        $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
-                                '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$uf.'" /></a>';
+                                '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
                }
                if ( '' != $align ) {
                        $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
@@ -1858,7 +1837,6 @@ class Skin {
                }
 
                $u = $img->getEscapeLocalURL();
-               $uf = $img->getEscapeFullURL();
 
                $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
                $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
@@ -1872,7 +1850,7 @@ class Skin {
                        $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
                                '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
                                'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
-                               'longdesc="'.$uf.'" /></a>';
+                               'longdesc="'.$u.'" /></a>';
                        if ( $framed ) {
                                $zoomicon="";
                        } else {
@@ -1887,24 +1865,29 @@ class Skin {
        }
 
        function makeMediaLink( $name, $url, $alt = '' ) {
-               $nt = Title::makeTitleSafe( Namespace::getMedia(), $name );
+               $nt = Title::makeTitleSafe( NS_IMAGE, $name );
                return $this->makeMediaLinkObj( $nt, $alt );
        }
 
-       function makeMediaLinkObj( $nt, $alt = '' ) {
+       function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {             
                if ( ! isset( $nt ) )
                {
                        ### HOTFIX. Instead of breaking, return empty string.
                        $s = $alt;
                } else {
-                       $name = $nt->getDBKey();
-                       $url = Image::wfImageUrl( $name );
+                       $name = $nt->getDBKey();        
+                       $img   = Image::newFromTitle( $nt );
+                       $url = $img->getURL();
+                       # $nourl can be set by the parser
+                       # this is a hack to mask absolute URLs, so the parser doesn't
+                       # linkify them (it is currently not context-aware)
+                       # 2004-10-25
+                       if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
                        if ( empty( $alt ) ) {
                                $alt = preg_replace( '/\.(.+?)^/', '', $name );
                        }
-
                        $u = htmlspecialchars( $url );
-                       $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
+                       $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";                   
                }
                return $s;
        }
@@ -1977,7 +1960,7 @@ class Skin {
                if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $r .= '&nbsp;&nbsp;';
                } else {
-                       # M & N (minor & new)
+                       # M, N and !
                        $M = wfMsg( 'minoreditletter' );
                        $N = wfMsg( 'newpageletter' );
 
@@ -1991,6 +1974,11 @@ class Skin {
                        } else {
                                $r .= '&nbsp;' ;
                        }
+                       if ( $rcObj->unpatrolled ) {
+                               $r .= '!';
+                       } else {
+                               $r .= '&nbsp;';
+                       }
                }
 
                # Timestamp
@@ -2036,12 +2024,20 @@ class Skin {
 
                # Collate list of users
                $isnew = false ;
+               $unpatrolled = false;
                $userlinks = array () ;
                foreach ( $block AS $rcObj ) {
                        $oldid = $rcObj->mAttribs['rc_last_oldid'];
-                       if ( $rcObj->mAttribs['rc_new'] ) $isnew = true ;
+                       if ( $rcObj->mAttribs['rc_new'] ) {
+                               $isnew = true ;
+                       }
                        $u = $rcObj->userlink ;
-                       if ( !isset ( $userlinks[$u] ) ) $userlinks[$u] = 0 ;
+                       if ( !isset ( $userlinks[$u] ) ) {
+                               $userlinks[$u] = 0 ;
+                       }
+                       if ( $rcObj->unpatrolled ) {
+                               $unpatrolled = true;
+                       }
                        $userlinks[$u]++ ;
                }
 
@@ -2062,8 +2058,8 @@ class Skin {
                $rcm = 'RCM'.$this->rcCacheIndex ;
                $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
                $arrowdir = $wgContLang->isRTL() ? 'l' : 'r';
-               $tl  = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" /></a></span>' ;
-               $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" /></a></span>' ;
+               $tl  = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
+               $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" alt="-" /></a></span>' ;
                $r .= $tl ;
 
                # Main line
@@ -2072,6 +2068,11 @@ class Skin {
                if ( $isnew ) $r .= $N ;
                else $r .= '&nbsp;' ;
                $r .= '&nbsp;' ; # Minor
+               if ( $unpatrolled ) {
+                       $r .= "!";
+               } else {
+                       $r .= "&nbsp;";
+               }
 
                # Timestamp
                $r .= ' '.$block[0]->timestamp.' ' ;
@@ -2107,11 +2108,25 @@ class Skin {
 
                        $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
                        $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;' ;
-                       if ( $rc_new ) $r .= $N ;
-                       else $r .= '&nbsp;' ;
-                       if ( $rc_minor ) $r .= $M ;
-                       else $r .= '&nbsp;' ;
-                       $r .= '</tt>' ;
+                       if ( $rc_new ) {
+                               $r .= $N ;
+                       } else {
+                               $r .= '&nbsp;' ;
+                       }
+
+                       if ( $rc_minor ) {
+                               $r .= $M ;
+                       } else {
+                               $r .= '&nbsp;' ;
+                       }
+
+                       if ( $rcObj->unpatrolled ) {
+                               $r .= "!";
+                       } else {
+                               $r .= "&nbsp;";
+                       }
+
+                       $r .= '&nbsp;</tt>' ;
 
                        $o = '' ;
                        if ( $rc_last_oldid != 0 ) {
@@ -2183,19 +2198,22 @@ class Skin {
                extract( $rc->mAttribs );
                $curIdEq = 'curid=' . $rc_cur_id;
 
+               # Should patrol-related stuff be shown?
+               $unpatrolled = $wgUseRCPatrol && $wgUser->getID() != 0 && 
+                 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
+               
                # Make date header if necessary
                $date = $wgContLang->date( $rc_timestamp, true);
                $uidate = $wgLang->date( $rc_timestamp, true);
                $s = '';
                if ( $date != $this->lastdate ) {
                        if ( '' != $this->lastdate ) { $s .= "</ul>\n"; }
-                       $s .= "<h4>{$uidate}</h4>\n<ul class='special'>";
+                       $s .= "<h4>{$uidate}</h4>\n<ul class=\"special\">";
                        $this->lastdate = $date;
                        $this->rclistOpen = true;
                }
 
-               # If this edit has not yet been patrolled, make it stick out
-               $s .= ( ! $wgUseRCPatrol || $rc_patrolled ) ? '<li> ' : '<li class="not_patrolled"> ';
+               $s .= '<li>';
 
                if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        # Diff
@@ -2218,8 +2236,7 @@ class Skin {
                        if ( $rc_type == RC_NEW || $rc_type == RC_LOG ) {
                                $diffLink = wfMsg( 'diff' );
                        } else {
-                               if ( $wgUseRCPatrol && $rc_patrolled == 0 && $wgUser->getID() != 0 &&
-                                    ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) )
+                               if ( $unpatrolled )
                                        $rcidparam = "&rcid={$rc_id}";
                                else
                                        $rcidparam = "";
@@ -2233,15 +2250,15 @@ class Skin {
                        $s .= $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
                        $s .= ') . . ';
 
-                       # M and N (minor and new)
+                       # M, N and ! (minor, new and unpatrolled)
                        if ( $rc_minor ) { $s .= ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>'; }
                        if ( $rc_type == RC_NEW ) { $s .= '<span class="newpage">'.wfMsg( "newpageletter" ).'</span>'; }
+                       if ( !$rc_patrolled ) { $s .= ' <span class="unpatrolled">!</span>'; }
 
                        # Article link
                        # If it's a new article, there is no diff link, but if it hasn't been
                        # patrolled yet, we need to give users a way to do so
-                       if ( $wgUseRCPatrol && $rc_type == RC_NEW && $rc_patrolled == 0 &&
-                            $wgUser->getID() != 0 && ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) )
+                       if ( $unpatrolled && $rc_type == RC_NEW )
                                $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
                        else
                                $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '' );
@@ -2276,7 +2293,7 @@ class Skin {
                }
                # Block link
                $blockLink='';
-               if ( ( 0 == $rc_user ) && $wgUser->isSysop() ) {
+               if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
                        $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
                          'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
 
@@ -2299,7 +2316,8 @@ class Skin {
 
        function recentChangesLineNew( &$baseRC, $watched = false ) {
                global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds;
-
+               global $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
+               
                # Create a specialised object
                $rc = RCCacheEntry::newFromParent( $baseRC ) ;
 
@@ -2318,7 +2336,15 @@ class Skin {
                        $ret .= "<h4>{$uidate}</h4>\n";
                        $this->lastdate = $date;
                }
-
+               
+               # Should patrol-related stuff be shown?
+               if ( $wgUseRCPatrol && $wgUser->getID() != 0 && 
+                 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') )) {
+                       $rc->unpatrolled = !$rc_patrolled;
+               } else {
+                       $rc->unpatrolled = false;
+               }
+               
                # Make article link
                if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
@@ -2329,6 +2355,9 @@ class Skin {
                        $logtype = $matches[1];
                        $logname = LogPage::logName( $logtype );
                        $clink = '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
+               } elseif ( $rc->unpatrolled && $rc_type == RC_NEW ) {
+                       # Unpatrolled new page, give rc_id in query
+                       $clink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
                } else {
                        $clink = $this->makeKnownLinkObj( $rc->getTitle(), '' ) ;
                }
@@ -2351,11 +2380,16 @@ class Skin {
 
                # Make "last" link
                $titleObj = $rc->getTitle();
+               if ( $rc->unpatrolled ) {
+                       $rcIdQuery = "&rcid={$rc_id}";
+               } else {
+                       $rcIdQuery = '';
+               }
                if ( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $lastLink = wfMsg( 'last' );
                } else {
                        $lastLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'last' ),
-                         $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid );
+                         $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
                }
 
                # Make user link (or user contributions for unregistered users)
@@ -2378,7 +2412,7 @@ class Skin {
                $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
 
                global $wgDisableAnonTalk;
-               if ( ( 0 == $rc_user ) && $wgUser->isSysop() ) {
+               if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
                        $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
                          'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
                        if( $wgDisableAnonTalk )
@@ -2497,7 +2531,7 @@ class Skin {
                if ( $iscur ) {
                        $url = Image::wfImageUrl( $img );
                        $rlink = $cur;
-                       if ( $wgUser->isSysop() ) {
+                       if ( $wgUser->isAllowed('delete') ) {
                                $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
                                  '&action=delete' );
                                $style = $this->getInternalLinkAttributes( $link, $delall );