X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FLinker.php;h=105e24bb0b8b785c93ac68d823f9167ac86314a1;hb=2818773456751c1a5aa6c87f77d631cbf1c12659;hp=4599b1bb1dcb477a61932dfa7b2eb1abb268e3a3;hpb=abf601e0fc2f0c102b585c1982e487910c167053;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Linker.php b/includes/Linker.php index 4599b1bb1d..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,9 +237,9 @@ 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() ) ) { + if( SpecialPage::exists( $nt->getDBkey() ) ) { $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } else { $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); @@ -249,16 +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' ), - 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 ); } @@ -319,7 +325,7 @@ class Linker { /** * Make a red link to the edit page of a given title. * - * @param $title String: The text of the title + * @param $nt Title object of the target page * @param $text String: Link text * @param $query String: Optional query part * @param $trail String: Optional trail. Alphabetic characters at the start of this string will @@ -338,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}"; @@ -361,7 +369,7 @@ class Linker { * * Make a brown link to a short article. * - * @param $title String: the text of the title + * @param $nt Title object of the target page * @param $text String: link text * @param $query String: optional query part * @param $trail String: optional trail. Alphabetic characters at the start of this string will @@ -369,13 +377,13 @@ class Linker { * the end of the link. */ function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix ); + return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix ); } /** * Make a coloured link. * - * @param $title String: the text of the title + * @param $nt Title object of the target page * @param $colour Integer: colour of the link * @param $text String: link text * @param $query String: optional query part @@ -461,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, @@ -483,34 +492,44 @@ 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 * - * @param array $frameParams Associative array of parameters external to the media handler. - * Boolean parameters are indicated by presence or absence, the value is arbitrary and - * will often be false. - * thumbnail If present, downscale and frame - * manualthumb Image name to use as a thumbnail, instead of automatic scaling - * framed Shows image in original size in a frame - * frameless Downscale but don't frame - * upright If present, tweak default sizes for portrait orientation - * upright_factor Fudge factor for "upright" tweak (default 0.75) - * border If present, show a border around the image - * align Horizontal alignment (left, right, center, none) - * valign Vertical alignment (baseline, sub, super, top, text-top, middle, - * bottom, text-bottom) - * alt Alternate text for image (i.e. alt attribute). Plain text. - * caption HTML for image caption. + * @param array $frameParams Associative array of parameters external to the media handler. + * Boolean parameters are indicated by presence or absence, the value is arbitrary and + * will often be false. + * thumbnail If present, downscale and frame + * manualthumb Image name to use as a thumbnail, instead of automatic scaling + * framed Shows image in original size in a frame + * frameless Downscale but don't frame + * upright If present, tweak default sizes for portrait orientation + * upright_factor Fudge factor for "upright" tweak (default 0.75) + * border If present, show a border around the image + * align Horizontal alignment (left, right, center, none) + * valign Vertical alignment (baseline, sub, super, top, text-top, middle, + * bottom, text-bottom) + * alt Alternate text for image (i.e. alt attribute). Plain text. + * caption HTML for image caption. * - * @param array $handlerParams Associative array of media handler parameters, to be passed - * to transform(). Typical keys are "width" and "page". + * @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" ); @@ -571,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'] ) ) { @@ -591,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, @@ -621,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(); @@ -678,12 +697,10 @@ class Linker { $url = $title->getLocalURL( $query ); $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) ); - $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right'; - $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : ''; $s = "