followup to r44520: simplify various bits by removing checks now made redundant
authorIlmari Karonen <vyznev@users.mediawiki.org>
Sat, 13 Dec 2008 04:14:40 +0000 (04:14 +0000)
committerIlmari Karonen <vyznev@users.mediawiki.org>
Sat, 13 Dec 2008 04:14:40 +0000 (04:14 +0000)
includes/FakeTitle.php
includes/Linker.php
includes/SkinTemplate.php
includes/Title.php
includes/parser/LinkHolderArray.php
includes/parser/Parser.php

index ac1c122..10bfa53 100644 (file)
@@ -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(); }
index a68d48c..d5f0342 100644 (file)
@@ -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';
index 7aef3f1..2ffd845 100644 (file)
@@ -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&section=new' )
                                        );
                                }
-                       } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
+                       } elseif ( $this->mTitle->isKnown() ) {
                                $content_actions['viewsource'] = array(
                                        'class' => ($action == 'edit') ? 'selected' : false,
                                        'text' => wfMsg('viewsource'),
index 6544428..a62d6aa 100644 (file)
@@ -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() {
index cea59ee..35b672b 100644 (file)
@@ -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 ) ) {
index 3323e85..38b562e 100644 (file)
@@ -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;