From 00a8d5316d1df57bd16a8325ee14964cbe333629 Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Fri, 11 Jul 2003 07:02:22 +0000 Subject: [PATCH] Added categroy feature, turned off by default --- LocalSettings.sample | 1 + includes/OutputPage.php | 62 +++++++++++++++++++++++++++++++++- includes/Skin.php | 22 +++++++++++- includes/SpecialCategories.php | 43 +++++++++++++++++++++++ languages/Language.php | 8 ++++- 5 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 includes/SpecialCategories.php diff --git a/LocalSettings.sample b/LocalSettings.sample index 17d5dbf923..0e13281edd 100644 --- a/LocalSettings.sample +++ b/LocalSettings.sample @@ -47,6 +47,7 @@ $wgDBtransactions = false; # Set to true if using InnoDB tables # $wgLanguageCode = "de"; $wgUseTeX = false; +$wgUseCategoryMagic = true ; $wgLocalInterwiki = "w"; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 5a0337f7e2..1b1f105e25 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -119,7 +119,7 @@ class OutputPage { var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext; var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable; var $mSubtitle, $mRedirect, $mAutonumber, $mHeadtext; - var $mLastModified; + var $mLastModified, $mCategoryLinks; var $mDTopen, $mLastSection; # Used for processing DL, PRE var $mLanguageLinks, $mSupressQuickbar; @@ -134,6 +134,7 @@ class OutputPage { $this->mIsarticle = $this->mPrintable = true; $this->mSupressQuickbar = $this->mDTopen = $this->mPrintable = false; $this->mLanguageLinks = array(); + $this->mCategoryLinks = array() ; $this->mAutonumber = 0; } @@ -664,6 +665,64 @@ class OutputPage { $wgOut->addHTML( "\n

$r\n" ); } + +function categoryMagic () +{ +global $wgTitle , $wgUseCategoryMagic ; +if ( !isset ( $wgUseCategoryMagic ) || !$wgUseCategoryMagic ) return ; +$id = $wgTitle->getArticleID() ; +$cat = ucfirst ( wfMsg ( "category" ) ) ; +$ti = $wgTitle->getText() ; +$ti = explode ( ":" , $ti , 2 ) ; +if ( $cat != $ti[0] ) return "" ; +$r = "
\n" ; + +$articles = array() ; +$parents = array () ; +$children = array() ; + + +global $wgUser ; +$sk = $wgUser->getSkin() ; +$sql = "SELECT l_from FROM links WHERE l_to={$id}" ; +$res = wfQuery ( $sql ) ; +while ( $x = wfFetchObject ( $res ) ) +{ +# $t = new Title ; +# $t->newFromDBkey ( $x->l_from ) ; +# $t = $t->getText() ; + $t = $x->l_from ; + $y = explode ( ":" , $t , 2 ) ; + if ( count ( $y ) == 2 && $y[0] == $cat ) + { + array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ; + } + else array_push ( $articles , $sk->makeLink ( $t ) ) ; +} +wfFreeResult ( $res ) ; + +# Children + if ( count ( $children ) > 0 ) + { + asort ( $children ) ; + $r .= "

".wfMsg("subcategories")."

\n" ; + $r .= implode ( ", " , $children ) ; + } + +# Articles + if ( count ( $articles ) > 0 ) + { + asort ( $articles ) ; + $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ; + $r .= "

{$h}

\n" ; + $r .= implode ( ", " , $articles ) ; + } + + +return $r ; +} + + # Well, OK, it's actually about 14 passes. But since all the # hard lifting is done inside PHP's regex code, it probably # wouldn't speed things up much to add a real parser. @@ -696,6 +755,7 @@ class OutputPage { $sk = $wgUser->getSkin(); $text = $sk->transformContent( $text ); + $text .= $this->categoryMagic () ; wfProfileOut(); return $text; diff --git a/includes/Skin.php b/includes/Skin.php index c20e22c475..862c1ac714 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -9,6 +9,24 @@ "Standard", "Nostalgia", "CologneBlue" ); +# For some odd PHP bug, this function can't be part of a class +function getCategories () +{ + global $wgOut , $wgTitle , $wgUseCategoryMagic , $wgUser ; + if ( !isset ( $wgUseCategoryMagic ) || !$wgUseCategoryMagic ) return "" ; + if ( count ( $wgOut->mCategoryLinks ) == 0 ) return "" ; + if ( !$wgOut->isArticle() ) return "" ; + $sk = $wgUser->getSkin() ; + $s = "" ; + $s .= "\n
\n"; + $s .= $sk->makeKnownLink ( "Special:Categories" , "Categories" , "article=".$wgTitle->getDBkey() ) ; + $t = implode ( " | " , $wgOut->mCategoryLinks ) ; + if ( $t != "" ) $s .= " : " ; + $s .= $t ; + return $s ; +} + + class RecentChangesClass { var $secureName , $displayName , $link , $namespace ; var $oldid , $diffid , $timestamp , $curlink , $lastlink , $usertalklink , $versionlink ; @@ -237,7 +255,9 @@ class Skin { $s .= "\n
"; $s .= $this->pageTitle(); - $s .= $this->pageSubtitle() . "\n

"; + $s .= $this->pageSubtitle() ; + $s .= getCategories(); // For some odd reason, zhis can't be a function of the object + $s .= "\n

"; wfProfileOut(); return $s; } diff --git a/includes/SpecialCategories.php b/includes/SpecialCategories.php new file mode 100644 index 0000000000..831cc9bda8 --- /dev/null +++ b/includes/SpecialCategories.php @@ -0,0 +1,43 @@ +getSkin() ; + $sc = "Special:Categories" ; + $r = "" ; + $r .= "

    \n" ; + $cat = ucfirst ( wfMsg ( "category" ) ) ; + $sql = "SELECT cur_title FROM cur WHERE cur_title LIKE \"{$cat}:%\"" ; + $res = wfQuery ( $sql ) ; + while ( $x = wfFetchObject ( $res ) ) + { + $t = explode ( ":" , $x->cur_title , 2 ) ; + $t = $t[1] ; + $r .= "
  1. " ; + $r .= $sk->makeKnownLink ( $x->cur_title , $t ) ; + $r .= "
  2. \n" ; + } + wfFreeResult ( $res ) ; + $r .= "
\n" ; + + $r .= "
\n" ; + $sql = "SELECT DISTINCT bl_to FROM brokenlinks WHERE bl_to LIKE \"{$cat}:%\"" ; + $res = wfQuery ( $sql ) ; + $r .= "
    \n" ; + while ( $x = wfFetchObject ( $res ) ) + { + $t = explode ( ":" , $x->bl_to , 2 ) ; + $t = $t[1] ; + $r .= "
  1. " ; + $r .= $sk->makeBrokenLink ( $x->bl_to , $t ) ; + $r .= "
  2. \n" ; + } + wfFreeResult ( $res ) ; + $r .= "
\n" ; + + $wgOut->addHTML ( $r ) ; +} + +?> diff --git a/languages/Language.php b/languages/Language.php index 5553b57765..4f7b5c386c 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -274,7 +274,8 @@ this (alternative: like this?).", "Whatlinkshere" => "", "Recentchangeslinked" => "", "Movepage" => "", - "Booksources" => "External book sources" + "Booksources" => "External book sources", +"Categories" => "Page categories", ); /* private */ $wgSysopSpecialPagesEn = array( @@ -293,6 +294,11 @@ this (alternative: like this?).", # Bits of text used by many pages: # +"categories" => "Page categories", +"category" => "category", +"category_header" => "Articles in category \"$1\"", +"subcategories" => "Subcategories", + "linktrail" => "/^([a-z]+)(.*)\$/sD", "mainpage" => "Main Page", "mainpagetext" => "Wiki software successfully installed.", -- 2.20.1