Added categroy feature, turned off by default
authorMagnus Manske <magnusmanske@users.mediawiki.org>
Fri, 11 Jul 2003 07:02:22 +0000 (07:02 +0000)
committerMagnus Manske <magnusmanske@users.mediawiki.org>
Fri, 11 Jul 2003 07:02:22 +0000 (07:02 +0000)
LocalSettings.sample
includes/OutputPage.php
includes/Skin.php
includes/SpecialCategories.php [new file with mode: 0644]
languages/Language.php

index 17d5dbf..0e13281 100644 (file)
@@ -47,6 +47,7 @@ $wgDBtransactions   = false; # Set to true if using InnoDB tables
 # $wgLanguageCode = "de";
 
 $wgUseTeX                      = false;
+$wgUseCategoryMagic = true ;
 
 $wgLocalInterwiki   = "w";
 
index 5a0337f..1b1f105 100644 (file)
@@ -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<p>$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 = "<br break=all>\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 .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
+     $r .= implode ( ", " , $children ) ;
+   }
+
+# Articles
+ if ( count ( $articles ) > 0 )
+   {
+     asort ( $articles ) ;
+     $h = str_replace ( "$1" , $ti[1] , wfMsg("category_header") ) ;
+     $r .= "<h2>{$h}</h2>\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;
index c20e22c..862c1ac 100644 (file)
@@ -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<br>\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<div id='article'>";
 
                $s .= $this->pageTitle();
-               $s .= $this->pageSubtitle() . "\n<p>";
+               $s .= $this->pageSubtitle() ;
+                $s .= getCategories(); // For some odd reason, zhis can't be a function of the object
+               $s .= "\n<p>";
                wfProfileOut();
                return $s;
        }
diff --git a/includes/SpecialCategories.php b/includes/SpecialCategories.php
new file mode 100644 (file)
index 0000000..831cc9b
--- /dev/null
@@ -0,0 +1,43 @@
+<?
+
+function wfSpecialCategories()
+{
+       global $wgUser, $wgOut , $wgLang ;
+       global $article , $category ;
+       $sk = $wgUser->getSkin() ;
+       $sc = "Special:Categories" ;
+       $r = "" ;
+       $r .= "<OL>\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 .= "<li>" ;
+           $r .= $sk->makeKnownLink ( $x->cur_title , $t ) ;
+           $r .= "</li>\n" ;
+         }
+       wfFreeResult ( $res ) ;
+       $r .= "</OL>\n" ;
+
+       $r .= "<hr>\n" ;
+       $sql = "SELECT DISTINCT bl_to FROM brokenlinks WHERE bl_to LIKE \"{$cat}:%\"" ;
+       $res = wfQuery ( $sql ) ;
+       $r .= "<OL>\n" ;
+       while ( $x = wfFetchObject ( $res ) )
+         {
+           $t = explode ( ":" , $x->bl_to , 2 ) ;
+           $t = $t[1] ;
+           $r .= "<li>" ;
+           $r .= $sk->makeBrokenLink ( $x->bl_to , $t ) ;
+           $r .= "</li>\n" ;
+         }
+       wfFreeResult ( $res ) ;
+       $r .= "</OL>\n" ;
+
+       $wgOut->addHTML ( $r ) ;
+}
+
+?>
index 5553b57..4f7b5c3 100644 (file)
@@ -274,7 +274,8 @@ this</a> (alternative: like this<a href=\"\" class=\"internal\">?</a>).",
        "Whatlinkshere" => "",
        "Recentchangeslinked" => "",
        "Movepage"              => "",
-       "Booksources"   => "External book sources"
+       "Booksources"   => "External book sources",
+"Categories" => "Page categories",
 );
 
 /* private */ $wgSysopSpecialPagesEn = array(
@@ -293,6 +294,11 @@ this</a> (alternative: like this<a href=\"\" class=\"internal\">?</a>).",
 
 # 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.",