X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FLinker.php;h=105e24bb0b8b785c93ac68d823f9167ac86314a1;hb=2818773456751c1a5aa6c87f77d631cbf1c12659;hp=223cf3469ac179fb1dd84b1e450b1ad00d358541;hpb=9c08024f3e13ea6e48faa2490bf4f1a3e50790fe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Linker.php b/includes/Linker.php index 223cf3469a..105e24bb0b 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -66,9 +66,13 @@ class Linker { * @param $text String: FIXME * @param $class String: CSS class of the link, default ''. */ - function getInternalLinkAttributesObj( &$nt, $text, $class='' ) { + function getInternalLinkAttributesObj( &$nt, $text, $class = '', $titleAttr = false ) { $r = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : ''; - $r .= ' title="' . $nt->getEscapedText() . '"'; + if ( $titleAttr === false ) { + $r .= ' title="' . $nt->getEscapedText() . '"'; + } else { + $r .= ' title="' . htmlspecialchars( $titleAttr ) . '"'; + } return $r; } @@ -76,18 +80,21 @@ class Linker { * Return the CSS colour of a known link * * @param mixed $s - * @param integer $id - * @param integer $threshold + * @param integer $threshold user defined threshold + * @return string CSS class */ function getLinkColour( $s, $threshold ) { - if( $threshold > 0 && $s!=false ) { - $colour = ( $s->page_len >= $threshold || - $s->page_is_redirect || - !Namespace::isContent( $s->page_namespace ) - ? '' : 'stub' ); + if( $s === false ) { + return ''; } - else { - $colour = ''; + + $colour = ''; + if ( !empty( $s->page_is_redirect ) ) { + # Page is a redirect + $colour = 'mw-redirect'; + } elseif ( $threshold > 0 && $s->page_len < $threshold && Namespace::isContent( $s->page_namespace ) ) { + # Page is a stub + $colour = 'stub'; } return $colour; } @@ -230,7 +237,7 @@ class Linker { } else { wfProfileIn( __METHOD__.'-immediate' ); - # Handles links to special pages wich do not exist in the database: + # Handles links to special pages which do not exist in the database: if( $nt->getNamespace() == NS_SPECIAL ) { if( SpecialPage::exists( $nt->getDBkey() ) ) { $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); @@ -249,15 +256,15 @@ class Linker { } else { $colour = ''; if ( $nt->isContentPage() ) { + # FIXME: This is stupid, we should combine this query with + # the Title::getArticleID() query above. $threshold = $wgUser->getOption('stubthreshold'); - if ( $threshold > 0 ) { - $dbr = wfGetDB( DB_SLAVE ); - $s = $dbr->selectRow( - array( 'page' ), - array( 'page_len', 'page_is_redirect', 'page_namespace' ), - array( 'page_id' => $aid ), __METHOD__ ) ; - $colour = $this->getLinkColour( $s, $threshold ); - } + $dbr = wfGetDB( DB_SLAVE ); + $s = $dbr->selectRow( + array( 'page' ), + array( 'page_len', 'page_is_redirect', 'page_namespace' ), + array( 'page_id' => $aid ), __METHOD__ ) ; + $colour = $this->getLinkColour( $s, $threshold ); } $retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix ); } @@ -337,16 +344,18 @@ class Linker { if( $nt->getNamespace() == NS_SPECIAL ) { $q = $query; } else if ( '' == $query ) { - $q = 'action=edit'; + $q = 'action=edit&redlink=1'; } else { - $q = 'action=edit&'.$query; + $q = 'action=edit&redlink=1&'.$query; } $u = $nt->escapeLocalURL( $q ); + $titleText = $nt->getPrefixedText(); if ( '' == $text ) { - $text = htmlspecialchars( $nt->getPrefixedText() ); + $text = htmlspecialchars( $titleText ); } - $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new' ); + $titleAttr = wfMsg( 'red-link-title', $titleText ); + $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new', $titleAttr ); list( $inside, $trail ) = Linker::splitTrail( $trail ); $s = "{$prefix}{$text}{$inside}{$trail}"; @@ -460,6 +469,7 @@ class Linker { * @param boolean $thumb shows image as thumbnail in a frame * @param string $manualthumb image name for the manual thumbnail * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom + * @param string $time, timestamp of the file, set as false for current * @return string */ function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false, @@ -482,11 +492,13 @@ class Linker { $frameParams['valign'] = $valign; } $file = wfFindFile( $title, $time ); - return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams ); + return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time ); } /** - * Make an image link + * Given parameters derived from [[Image:Foo|options...]], generate the + * HTML that that syntax inserts in the page. + * * @param Title $title Title object * @param File $file File object, or false if it doesn't exist * @@ -508,8 +520,16 @@ class Linker { * * @param array $handlerParams Associative array of media handler parameters, to be passed * to transform(). Typical keys are "width" and "page". + * @param string $time, timestamp of the file, set as false for current + * @return string HTML for an image, with links, wrappers, etc. */ - function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array() ) { + function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false ) { + $res = null; + if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title, + &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) { + return $res; + } + global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright; if ( $file && !$file->allowInlineDisplay() ) { wfDebug( __METHOD__.': '.$title->getPrefixedDBkey()." does not allow inline display\n" ); @@ -570,7 +590,7 @@ class Linker { if ( $fp['align'] == '' ) { $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right'; } - return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp ).$postfix; + return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time ).$postfix; } if ( $file && isset( $fp['frameless'] ) ) { @@ -590,7 +610,7 @@ class Linker { } if ( !$thumb ) { - $s = $this->makeBrokenImageLinkObj( $title ); + $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true ); } else { $s = $thumb->toHtml( array( 'desc-link' => true, @@ -620,7 +640,7 @@ class Linker { return $this->makeThumbLink2( $title, $file, $frameParams, $params ); } - function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array() ) { + function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false ) { global $wgStylePath, $wgContLang; $exists = $file && $file->exists(); @@ -680,7 +700,7 @@ class Linker { $s = "
"; if( !$exists ) { - $s .= $this->makeBrokenImageLinkObj( $title ); + $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true ); $zoomicon = ''; } elseif ( !$thumb ) { $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) ); @@ -711,14 +731,15 @@ class Linker { * @param string $query Query string * @param string $trail Link trail * @param string $prefix Link prefix + * @param bool $time, a file of a certain timestamp was requested * @return string */ - public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) { + public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) { global $wgEnableUploads; if( $title instanceof Title ) { wfProfileIn( __METHOD__ ); - $currentFile = wfFindFile( $title ); - if( $wgEnableUploads && !$currentFile ) { + $currentExists = $time ? ( wfFindFile( $title ) != false ) : false; + if( $wgEnableUploads && !$currentExists ) { $upload = SpecialPage::getTitleFor( 'Upload' ); if( $text == '' ) $text = htmlspecialchars( $title->getPrefixedText() ); @@ -1347,7 +1368,36 @@ class Linker { wfProfileOut( __METHOD__ ); return $outText; } - + + /** + * Returns HTML for the "hidden categories on this page" list. + * + * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories + * or similar + * @return string HTML output + */ + public function formatHiddenCategories( $hiddencats) { + global $wgUser, $wgLang; + wfProfileIn( __METHOD__ ); + + $sk = $wgUser->getSkin(); + + $outText = ''; + if ( count( $hiddencats ) > 0 ) { + # Construct the HTML + $outText = '
'; + $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) ); + $outText .= '
'; + } + wfProfileOut( __METHOD__ ); + return $outText; + } + /** * Format a size in bytes for output, using an appropriate * unit (B, KB, MB or GB) according to the magnitude in question