New feature, nicer display of redirects. Removed special case for redirects from...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 7 Aug 2004 03:50:46 +0000 (03:50 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 7 Aug 2004 03:50:46 +0000 (03:50 +0000)
includes/Article.php
includes/Parser.php
includes/Title.php
stylesheets/common.css
stylesheets/images/redirect.png [new file with mode: 0644]
stylesheets/monobook/main.css

index 2b45783..cca2bb0 100644 (file)
@@ -218,17 +218,14 @@ class Article {
                        return wfMsg( 'noarticletext' );
                } else {
                        $this->loadContent( $noredir );
-
-                       if(
-                               # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
-                               ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
-                                 preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
-                                 $action=='view'
-                               )
-                               {
+                       # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
+                       if ( $this->mTitle->getNamespace() == NS_USER_TALK &&
+                         preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
+                         $action=='view'
+                       ) {
                                wfProfileOut( $fname );
-                               return $this->mContent . "\n" .wfMsg('anontalkpagetext'); }
-                       else {
+                               return $this->mContent . "\n" .wfMsg('anontalkpagetext'); 
+                       else {
                                if($action=='edit') {
                                        if($section!='') {
                                                if($section=='new') {
@@ -332,7 +329,7 @@ class Article {
                }
                return $wgArticleOldContentFields;
        }
-
+                               
        # Load the revision (including cur_text) into this object
        function loadContent( $noredir = false )
        {
@@ -371,33 +368,29 @@ class Article {
 
                        # If we got a redirect, follow it (unless we've been told
                        # not to by either the function parameter or the query
-                       if ( ( 'no' != $redirect ) && ( false == $noredir ) &&
-                         ( $wgMwRedir->matchStart( $s->cur_text ) ) ) {
-                               if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
-                                 $s->cur_text, $m ) ) {
-                                       $rt = Title::newFromText( $m[1] );
-                                       if( $rt ) {
-                                               # Gotta hand redirects to special pages differently:
-                                               # Fill the HTTP response "Location" header and ignore
-                                               # the rest of the page we're on.
-
-                                               if ( $rt->getInterwiki() != '' ) {
-                                                       $wgOut->redirect( $rt->getFullURL() ) ;
-                                                       return;
-                                               }
-                                               if ( $rt->getNamespace() == Namespace::getSpecial() ) {
-                                                       $wgOut->redirect( $rt->getFullURL() );
-                                                       return;
-                                               }
-                                               $rid = $rt->getArticleID();
-                                               if ( 0 != $rid ) {
-                                                       $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
-
-                                                       if ( $redirRow !== false ) {
-                                                               $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                                               $this->mTitle = $rt;
-                                                               $s = $redirRow;
-                                                       }
+                       if ( ( 'no' != $redirect ) && ( false == $noredir ) ) {
+                               $rt = Title::newFromRedirect( $s->cur_text );
+                               if ( $rt ) {
+                                       # Gotta hand redirects to special pages differently:
+                                       # Fill the HTTP response "Location" header and ignore
+                                       # the rest of the page we're on.
+
+                                       if ( $rt->getInterwiki() != '' ) {
+                                               $wgOut->redirect( $rt->getFullURL() ) ;
+                                               return;
+                                       }
+                                       if ( $rt->getNamespace() == NS_SPECIAL ) {
+                                               $wgOut->redirect( $rt->getFullURL() );
+                                               return;
+                                       }
+                                       $rid = $rt->getArticleID();
+                                       if ( 0 != $rid ) {
+                                               $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
+
+                                               if ( $redirRow !== false ) {
+                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+                                                       $this->mTitle = $rt;
+                                                       $s = $redirRow;
                                                }
                                        }
                                }
@@ -461,20 +454,17 @@ class Article {
 
                        # If we got a redirect, follow it (unless we've been told
                        # not to by either the function parameter or the query
-                       if ( !$noredir && $wgMwRedir->matchStart( $s->cur_text ) ) {
-                               if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
-                                 $s->cur_text, $m ) ) {
-                                       $rt = Title::newFromText( $m[1] );
-                                       if( $rt &&  $rt->getInterwiki() == '' && $rt->getNamespace() != Namespace::getSpecial() ) {
-                                               $rid = $rt->getArticleID();
-                                               if ( 0 != $rid ) {
-                                                       $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
-
-                                                       if ( $redirRow !== false ) {
-                                                               $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                                               $this->mTitle = $rt;
-                                                               $s = $redirRow;
-                                                       }
+                       if ( !$noredir ) {
+                               $rt = Title::newFromRedirect( $s->cur_text );
+                               if( $rt &&  $rt->getInterwiki() == '' && $rt->getNamespace() != NS_SPECIAL ) {
+                                       $rid = $rt->getArticleID();
+                                       if ( 0 != $rid ) {
+                                               $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
+
+                                               if ( $redirRow !== false ) {
+                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+                                                       $this->mTitle = $rt;
+                                                       $s = $redirRow;
                                                }
                                        }
                                }
@@ -634,8 +624,8 @@ class Article {
 
        function view()
        {
-               global $wgUser, $wgOut, $wgLang, $wgRequest;
-               global $wgLinkCache, $IP, $wgEnableParserCache;
+               global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMwRedir;
+               global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath;
 
                $fname = 'Article::view';
                wfProfileIn( $fname );
@@ -718,14 +708,25 @@ class Article {
                        # wrap user css and user js in pre and don't parse
                        # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
                        if (
-                               $this->mTitle->getNamespace() == Namespace::getUser() &&
+                               $this->mTitle->getNamespace() == NS_USER &&
                                preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
                        ) {
                                $wgOut->addWikiText( wfMsg('clearyourcache'));
                                $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
+                       } else if ( $rt = Title::newFromRedirect( $text ) ) {
+                               # Display redirect
+                               $sk = $wgUser->getSkin();
+                               $imageUrl = "$wgStylePath/images/redirect.png";
+                               $targetUrl = $rt->escapeLocalURL();
+                               $titleText = htmlspecialchars( $rt->getPrefixedText() );
+                               $link = $sk->makeLinkObj( $rt );
+                               $wgOut->addHTML( "<img valign=\"center\" src=\"$imageUrl\">" .
+                                 "<span class=\"redirectText\">$link</span>" );
                        } else if ( $pcache ) {
+                               # Display content and save to parser cache
                                $wgOut->addWikiText( $text, true, $this );
                        } else {
+                               # Display content, don't attempt to save to parser cache
                                $wgOut->addWikiText( $text );
                        }
                }
@@ -1403,8 +1404,7 @@ class Article {
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
                        $sk = $wgUser->getSkin();
-                       $loglink = $sk->makeKnownLink( $wgLang->getNsText(
-                         Namespace::getWikipedia() ) .
+                       $loglink = $sk->makeKnownLink( $wgLang->getNsText( NS_WIKIPEDIA ) .
                          ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
 
                        $text = wfMsg( "deletedtext", $deleted, $loglink );
@@ -1747,7 +1747,7 @@ class Article {
                        and ($this->getID() != 0)
                        and ($wgUser->getId() == 0)
                        and (!$wgUser->getNewtalk())
-                       and ($this->mTitle->getNamespace() != Namespace::getSpecial())
+                       and ($this->mTitle->getNamespace() != NS_SPECIAL )
                        and ($action == 'view' || empty( $action ))
                        and (!isset($oldid))
                        and (!isset($diff))
index 8d8cde9..7334548 100644 (file)
@@ -378,8 +378,7 @@ class Parser
 
                if ( !$this->mOptions->getUseCategoryMagic() ) return ; # Doesn't use categories at all
 
-               $cns = Namespace::getCategory() ;
-               if ( $this->mTitle->getNamespace() != $cns ) return "" ; # This ain't a category page
+               if ( $this->mTitle->getNamespace() != NS_CATEGORY ) return "" ; # This ain't a category page
 
                $r = "<br style=\"clear:both;\"/>\n";
 
@@ -409,7 +408,7 @@ class Parser
                        if ( $t != "" ) $t .= ":" ;
                        $t .= $x->cur_title ;
 
-                       if ( $x->cur_namespace == $cns ) {
+                       if ( $x->cur_namespace == NS_CATEGORY ) {
                                array_push ( $children , $sk->makeLink ( $t ) ) ; # Subcategory
                        } else {
                                array_push ( $articles , $sk->makeLink ( $t ) ) ; # Page in this category
@@ -440,8 +439,7 @@ class Parser
                global $wgLang , $wgUser ;
                if ( !$this->mOptions->getUseCategoryMagic() ) return ; # Doesn't use categories at all
 
-               $cns = Namespace::getCategory() ;
-               if ( $this->mTitle->getNamespace() != $cns ) return '' ; # This ain't a category page
+               if ( $this->mTitle->getNamespace() != NS_CATEGORY ) return '' ; # This ain't a category page
 
                $r = "<br style=\"clear:both;\"/>\n";
 
@@ -470,7 +468,7 @@ class Parser
                        if ( $t != '' ) $t .= ':' ;
                        $t .= $x->cur_title ;
 
-                       if ( $x->cur_namespace == $cns ) {
+                       if ( $x->cur_namespace == NS_CATEGORY ) {
                                $ctitle = str_replace( '_',' ',$x->cur_title );
                                array_push ( $children, $sk->makeKnownLink ( $t, $ctitle ) ) ; # Subcategory
 
@@ -1159,7 +1157,6 @@ class Parser
                $sk =& $this->mOptions->getSkin();
 
                $redirect = MagicWord::get ( MAG_REDIRECT ) ;
-               $isRedirect = $redirect->matchStart ( strtoupper ( substr ( $s , 0 , 10 ) ) ) ;
 
                $a = explode( '[[', ' ' . $s );
                $s = array_shift( $a );
@@ -1174,14 +1171,6 @@ class Parser
 
                $useLinkPrefixExtension = $wgLang->linkPrefixExtension();
                # Special and Media are pseudo-namespaces; no pages actually exist in them
-               static $image = FALSE;
-               static $special = FALSE;
-               static $media = FALSE;
-               static $category = FALSE;
-               if ( !$image ) { $image = Namespace::getImage(); }
-               if ( !$special ) { $special = Namespace::getSpecial(); }
-               if ( !$media ) { $media = Namespace::getMedia(); }
-               if ( !$category ) { $category = Namespace::getCategory(); }
 
                $nottalk = !Namespace::isTalk( $this->mTitle->getNamespace() );
 
@@ -1271,14 +1260,14 @@ class Parser
                                        $s .= (trim($tmp) == '')? '': $tmp;
                                        continue;
                                }
-                               if ( $ns == $image ) {
+                               if ( $ns == NS_IMAGE ) {
                                        $s .= $prefix . $sk->makeImageLinkObj( $nt, $text ) . $trail;
                                        $wgLinkCache->addImageLinkObj( $nt );
                                        continue;
                                }
-                               if ( $ns == $category && !$isRedirect ) {
+                               if ( $ns == NS_CATEGORY ) {
                                        $t = $nt->getText() ;
-                                       $nnt = Title::newFromText ( Namespace::getCanonicalName($category).":".$t ) ;
+                                       $nnt = Title::newFromText ( Namespace::getCanonicalName(NS_CATEGORY).":".$t ) ;
 
                                        $wgLinkCache->suspend(); # Don't save in links/brokenlinks
                                        $pPLC=$sk->postParseLinkColour();
@@ -1301,11 +1290,11 @@ class Parser
                                continue;
                        }
 
-                       if( $ns == $media ) {
+                       if( $ns == NS_MEDIA ) {
                                $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text ) . $trail;
                                $wgLinkCache->addImageLinkObj( $nt );
                                continue;
-                       } elseif( $ns == $special ) {
+                       } elseif( $ns == NS_SPECIAL ) {
                                $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, '', $trail );
                                continue;
                        }
@@ -2417,10 +2406,8 @@ class Parser
                if(isset($wgLocaltimezone)) putenv('TZ='.$oldtzs);
 
                $text = preg_replace( '/~~~~~/', $d, $text );
-               $text = preg_replace( '/~~~~/', '[[' . $wgLang->getNsText(
-                 Namespace::getUser() ) . ":$n|$k]] $d", $text );
-               $text = preg_replace( '/~~~/', '[[' . $wgLang->getNsText(
-                 Namespace::getUser() ) . ":$n|$k]]", $text );
+               $text = preg_replace( '/~~~~/', '[[' . $wgLang->getNsText( NS_USER ) . ":$n|$k]] $d", $text );
+               $text = preg_replace( '/~~~/', '[[' . $wgLang->getNsText( NS_USER ) . ":$n|$k]]", $text );
 
                # Context links: [[|name]] and [[name (context)|]]
                #
index 74c11c5..9db099f 100644 (file)
@@ -151,10 +151,23 @@ class Title {
                }
        }
 
-       function newMainPage()
+       /* static */ function newMainPage()
        {
                return Title::newFromText( wfMsg( "mainpage" ) );
        }
+
+       # Get the title object for a redirect
+       # Returns NULL if the text is not a valid redirect
+       /* static */ function newFromRedirect( $text ) {
+               global $wgMwRedir;
+               $rt = NULL;
+               if ( $wgMwRedir->matchStart( $text ) ) {
+                       if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/', $text, $m ) ) {
+                               $rt = Title::newFromText( $m[1] );
+                       }
+               }
+               return $rt;
+       }
        
 #----------------------------------------------------------------------------
 #      Static functions
index ec18a7c..ed34001 100644 (file)
@@ -196,3 +196,7 @@ div.townBox dl dd {
 #siteNotice {
     border:1px solid #aaaaaa;
 }
+.redirectText {
+       font-size:150%;
+       margin:5px;
+}
diff --git a/stylesheets/images/redirect.png b/stylesheets/images/redirect.png
new file mode 100644 (file)
index 0000000..5b72c43
Binary files /dev/null and b/stylesheets/images/redirect.png differ
index a008022..5b13d47 100644 (file)
@@ -898,3 +898,7 @@ fieldset.operaprefsection { margin-left: 15em }
 * > html #footer {
     margin-left: 13.2em;
 }
+.redirectText {
+       font-size:150%;
+       margin:5px;
+}