From: Ilmari Karonen Date: Sat, 13 Dec 2008 04:14:40 +0000 (+0000) Subject: followup to r44520: simplify various bits by removing checks now made redundant X-Git-Tag: 1.31.0-rc.0~44002 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=7f71d9e38f2324aa539cd336e2724458b559fd03;p=lhc%2Fweb%2Fwiklou.git followup to r44520: simplify various bits by removing checks now made redundant --- diff --git a/includes/FakeTitle.php b/includes/FakeTitle.php index ac1c122016..10bfa53887 100644 --- a/includes/FakeTitle.php +++ b/includes/FakeTitle.php @@ -77,6 +77,7 @@ class FakeTitle extends Title { function equals() { $this->error(); } function exists() { $this->error(); } function isAlwaysKnown() { $this->error(); } + function isKnown() { $this->error(); } function touchLinks() { $this->error(); } function trackbackURL() { $this->error(); } function trackbackRDF() { $this->error(); } diff --git a/includes/Linker.php b/includes/Linker.php index a68d48cd8d..d5f03428c3 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -190,15 +190,7 @@ class Linker { # If we don't know whether the page exists, let's find out. wfProfileIn( __METHOD__ . '-checkPageExistence' ); if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) { - if( $target->getNamespace() == NS_SPECIAL ) { - if( SpecialPage::exists( $target->getDBKey() ) ) { - $options []= 'known'; - } else { - $options []= 'broken'; - } - } elseif( $target->isAlwaysKnown() or - ($target->getPrefixedText() == '' and $target->getFragment() != '') - or $target->exists() ) { + if( $target->isKnown() ) { $options []= 'known'; } else { $options []= 'broken'; diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 7aef3f1de4..2ffd845f75 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -594,8 +594,7 @@ class SkinTemplate extends Skin { if( $selected ) { $classes[] = 'selected'; } - if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 && - !($title->getNamespace() == NS_FILE && wfFindFile( $title )) ) { + if( $checkEdit && !$title->isKnown() ) { $classes[] = 'new'; $query = 'action=edit'; } @@ -696,7 +695,7 @@ class SkinTemplate extends Skin { 'href' => $this->mTitle->getLocalUrl( 'action=edit§ion=new' ) ); } - } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) { + } elseif ( $this->mTitle->isKnown() ) { $content_actions['viewsource'] = array( 'class' => ($action == 'edit') ? 'selected' : false, 'text' => wfMsg('viewsource'), diff --git a/includes/Title.php b/includes/Title.php index 65444283e2..a62d6aafb9 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3114,6 +3114,11 @@ class Title { * misleadingly named. You probably just want to call isKnown(), which * calls this function internally. * + * (ISSUE: Most of these checks are cheap, but the file existence check + * can potentially be quite expensive. Including it here fixes a lot of + * existing code, but we might want to add an optional parameter to skip + * it and any other expensive checks.) + * * @return \type{\bool} TRUE or FALSE */ public function isAlwaysKnown() { diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index cea59ee953..35b672b94f 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -166,8 +166,6 @@ class LinkHolderArray { $output->addLink( $title, $id ); } elseif ( $linkCache->isBadLink( $pdbk ) ) { $colours[$pdbk] = 'new'; - } elseif ( $title->getNamespace() == NS_SPECIAL && !SpecialPage::exists( $pdbk ) ) { - $colours[$pdbk] = 'new'; } else { # Not in the link cache, add it to the query if ( !isset( $current ) ) { diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 3323e859f0..38b562ef49 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1813,14 +1813,15 @@ class Parser } # Self-link checking - if( $nt->getFragment() === '' && $nt->getNamespace() != NS_SPECIAL ) { + if( $nt->getFragment() === '' && $ns != NS_SPECIAL ) { if( in_array( $nt->getPrefixedText(), $selflink, true ) ) { $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail ); continue; } } - # Special and Media are pseudo-namespaces; no pages actually exist in them + # NS_MEDIA is a pseudo-namespace for linking directly to a file + # FIXME: Should do batch file existence checks, see comment below if( $ns == NS_MEDIA ) { # Give extensions a chance to select the file revision for us $skip = $time = false; @@ -1834,25 +1835,18 @@ class Parser $s .= $prefix . $this->armorLinks( $link ) . $trail; $this->mOutput->addImage( $nt->getDBkey() ); continue; - } elseif( $ns == NS_SPECIAL ) { - if( SpecialPage::exists( $nt->getDBkey() ) ) { - $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix ); - } else { - $s .= $holders->makeHolder( $nt, $text, '', $trail, $prefix ); - } - continue; - } elseif( $ns == NS_FILE ) { - $img = wfFindFile( $nt ); - if( $img ) { - // Force a blue link if the file exists; may be a remote - // upload on the shared repository, and we want to see its - // auto-generated page. - $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix ); - $this->mOutput->addLink( $nt ); - continue; - } } - $s .= $holders->makeHolder( $nt, $text, '', $trail, $prefix ); + + # Some titles, such as valid special pages or files in foreign repos, should + # be shown as bluelinks even though they're not included in the page table + # + # FIXME: isAlwaysKnown() can be expensive for file links; we should really do + # batch file existence checks for NS_FILE and NS_MEDIA + if( $nt->isAlwaysKnown() ) { + $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix ); + } else { + $s .= $holders->makeHolder( $nt, $text, '', $trail, $prefix ); + } } wfProfileOut( __METHOD__ ); return $holders;