From d73935a5f0fb09882b4a9269868a9bb68bb29d72 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 7 Aug 2004 03:50:46 +0000 Subject: [PATCH] New feature, nicer display of redirects. Removed special case for redirects from Parser.php, which probably would have caused problems anyway. Changed a few places to use NS_xxx constants instead of the old Namespace:: functions. --- includes/Article.php | 116 ++++++++++++++++---------------- includes/Parser.php | 35 +++------- includes/Title.php | 15 ++++- stylesheets/common.css | 4 ++ stylesheets/images/redirect.png | Bin 0 -> 1117 bytes stylesheets/monobook/main.css | 4 ++ 6 files changed, 91 insertions(+), 83 deletions(-) create mode 100644 stylesheets/images/redirect.png diff --git a/includes/Article.php b/includes/Article.php index 2b457830ee..cca2bb0fa7 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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( '
'.htmlspecialchars($this->mContent)."\n
" ); + } 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( "" . + "$link" ); } 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)) diff --git a/includes/Parser.php b/includes/Parser.php index 8d8cde96a4..73345485eb 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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 = "
\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 = "
\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)|]] # diff --git a/includes/Title.php b/includes/Title.php index 74c11c5676..9db099f261 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 diff --git a/stylesheets/common.css b/stylesheets/common.css index ec18a7c806..ed340016f5 100644 --- a/stylesheets/common.css +++ b/stylesheets/common.css @@ -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 index 0000000000000000000000000000000000000000..5b72c43c3b57239883dfb31da3e02fb13484ce0f GIT binary patch literal 1117 zcmbtT`%l|d6hGfSuyj=0lrhTs!vUci&L0@aV-eyld{MgbYAMog2&F4eVFO0u6k}S# zq-8#+IxS^EKp?o`hQt}>vZM&Is^G>zR;FYWr(%_COo44q@pk`$C%O0B^ZcB9?zy(y z?B_(nFd+blR2i&>ay4CX0xsP>HNp9m@yeB1N`SNOM1JdURF*ZQ>l*S7mo>apQeO&6 z(_v#Ns%lEgOEsk>rkCr!E={IRuG~y*Iw52o;4gryi1z^25dT5+03;_T-={tRa{xa8 zTn1PKSO%B@SOHiC_zB=UfN209zy`nr#0LQLh*JQQ0M`&_5myjr5dTKJkGO$&1>h#) zEr11pS%9BuX2eCryNG{MT!34M3yA+BeovzSentEp(Tli>IET25XfPObI^9|HQ!l{g z=H`(@S8mcONrNUkkBa|?;LFBOSpd#86|2-9y>1-Z5#aH7ISHXv49992szlOc17@69 zDm_^|0S5f2kUS;2;8&R!lAbm){SU33b+tJLr$9`CmVdFoD3$|H%spjk&WwoYW9acU zt|}%l0612r#bOHO^Zn6N?VEtBcp8dC&~ zYI)qvN{WiM>h;ml(Zl{5^u8)eRBN?_?A`aRi)?=(e%I+(rIg_a=Gn4HY5d6f`T29_ zrnKrTljixkaDzX|2W68&;eg`K?Sa#$oDQAS`OR3S$uz6hXvWK_z59KyYvkED``bA> z-Mb$a7ZnxXC@k1!>Pgyiyr+kE$e;USCvz#j-)1y6HC3giW{RbI_C!TSdTJfCWKUH= zZlN@0TBmvEP0@vR+J=w#7}b~VW>ZoU64IXBPvgrwI458EY)as$uvRJvNGdiQqf5@C z#a!ClIvEpxW_2Qn!0xv9#!&HuH!B4g_6wUU_^kpF0eeNnE^i?P>UC!5sJz>gx1GMv zn!g!7f6rzUC1?(luD}nxDy1QVN#L4CB&Bg#U zFM8di(8tJZ&#XN}YO}MwwL^ACv|JxZU^I)jzeV1HX6Kd?UsARDNcc&9K1XbT$BNqR T!&fi1(eDDP^lbJ_s-fvWZ}X`! literal 0 HcmV?d00001 diff --git a/stylesheets/monobook/main.css b/stylesheets/monobook/main.css index a0080228f2..5b13d4740f 100644 --- a/stylesheets/monobook/main.css +++ b/stylesheets/monobook/main.css @@ -898,3 +898,7 @@ fieldset.operaprefsection { margin-left: 15em } * > html #footer { margin-left: 13.2em; } +.redirectText { + font-size:150%; + margin:5px; +} -- 2.20.1