From: Jens Frank Date: Sun, 6 Jun 2004 09:24:07 +0000 (+0000) Subject: new layout for Category:XXX pages. X-Git-Tag: 1.5.0alpha1~3015 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=29c11354608e16e06ae96acf32f943a8fefdc4be;p=lhc%2Fweb%2Fwiklou.git new layout for Category:XXX pages. Can be turned on or off using MediaWiki:Usenewcategorypage --- diff --git a/includes/Parser.php b/includes/Parser.php index 9be150ff54..596c576be8 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -333,8 +333,25 @@ class Parser return $rnd; } + # categoryMagic + # generate a list of subcategories and pages for a category + # depending on wfMsg("usenewcategorypage") it either calls the new + # or the old code. The new code will not work properly for some + # languages due to sorting issues, so they might want to turn it + # off. + function categoryMagic() + { + $msg = wfMsg("usenewcategorypage"); + if ( "0" == @$msg[0] ) + { + return $this->oldCategoryMagic(); + } else { + return $this->newCategoryMagic(); + } + } + # This method generates the list of subcategories and pages for a category - function categoryMagic () + function oldCategoryMagic () { global $wgLang , $wgUser ; if ( !$this->mOptions->getUseCategoryMagic() ) return ; # Doesn't use categories at all @@ -391,6 +408,181 @@ class Parser return $r ; } + + + function newCategoryMagic () + { + 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 + + $r = "
\n"; + + + $sk =& $wgUser->getSkin() ; + + $articles = array() ; + $articles_start_char = array(); + $children = array() ; + $children_start_char = array(); + $data = array () ; + $id = $this->mTitle->getArticleID() ; + + # FIXME: add limits + $t = wfStrencode( $this->mTitle->getDBKey() ); + $sql = "SELECT DISTINCT cur_title,cur_namespace,cl_sortkey FROM +cur,categorylinks WHERE cl_to='$t' AND cl_from=cur_id ORDER BY +cl_sortkey" ; + $res = wfQuery ( $sql, DB_READ ) ; + while ( $x = wfFetchObject ( $res ) ) + { + $data[] = $x ; + } + + # For all pages that link to this category + foreach ( $data as $x ) + { + $t = $wgLang->getNsText ( $x->cur_namespace ) ; + if ( $t != "" ) $t .= ":" ; + $t .= $x->cur_title ; + + if ( $x->cur_namespace == $cns ) { + array_push ( $children, $sk->makeKnownLink ( $t, $x->cur_title) ) ; # Subcategory + array_push ( $children_start_char, $wgLang->firstChar( $x->cl_sortkey ) ) ; + } else { + array_push ( $articles , $sk->makeLink ( $t ) ) ; # Page in this category + array_push ( $articles_start_char, $wgLang->firstChar( $x->cl_sortkey ) ) ; + } + } + wfFreeResult ( $res ) ; + + $ti = $this->mTitle->getText() ; + + # Don't show subcategories section if there are none. + if ( count ( $children ) > 0 ) + { + # Showing subcategories + $r .= "

" . wfMsg( "subcategories" ) . "

\n" + . wfMsg( "subcategorycount", count( $children ) ); + if ( count ( $children ) > 20) { + + // divide list into three equal chunks + $chunk = (int) (count ( $children ) / 3); + + // get and display header + $r .= ""; + + $startChunk = 0; + $endChunk = $chunk; + + // loop through the chunks + for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0; + $chunkIndex < 3; + $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1) + { + + $r .= ""; + + + } + $r .= "
    "; + // output all subcategories to category + for ($index = $startChunk ; + $index < $endChunk && $index < count($children); + $index++ ) + { + // check for change of starting letter or begging of chunk + if ( ($children_start_char[$index] != $children_start_char[$index - 1]) + || ($index == $startChunk) ) + { + $r .= "

{$children_start_char[$index]}

\n
    "; + } + + $r .= "
  • {$children[$index]}
  • "; + } + $r .= "
"; + } else { + // for short lists of subcategories to category. + + $r .= "

{$children_start_char[0]}

\n"; + $r .= "

{$children_start_char[$index]}

\n"; + } + } # END of if ( count($children) > 0 ) + + $r .= "

" . wfMsg( "category_header", $ti ) . "

\n" . + wfMsg( "categoryarticlecount", count( $articles ) ); + + # Showing articles in this category + if ( count ( $articles ) > 6) { + $ti = $this->mTitle->getText() ; + + // divide list into three equal chunks + $chunk = (int) (count ( $articles ) / 3); + + // get and display header + $r .= ""; + + // loop through the chunks + for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0; + $chunkIndex < 3; + $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1) + { + + $r .= ""; + + + } + $r .= "
    "; + + // output all articles in category + for ($index = $startChunk ; + $index < $endChunk && $index < count($articles); + $index++ ) + { + // check for change of starting letter or begging of chunk + if ( ($articles_start_char[$index] != $articles_start_char[$index - 1]) + || ($index == $startChunk) ) + { + $r .= "

{$articles_start_char[$index]}

\n
    "; + } + + $r .= "
  • {$articles[$index]}
  • "; + } + $r .= "
"; + } else { + // for short lists of articles in categories. + $ti = $this->mTitle->getText() ; + + $r .= "

".$articles_start_char[0]."

\n"; + $r .= "

{$articles_start_char[$index]}

\n"; + } + + + return $r ; + } + # Return allowed HTML attributes function getHTMLattrs () { diff --git a/languages/Language.php b/languages/Language.php index d6959d26dc..437b84431d 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1561,7 +1561,10 @@ amusement.", "spamprotectiontitle" => "Spam protection filter", "spamprotectiontext" => "The page you wanted to save was blocked by the spam filter. This is probably caused by a link to an external site. -You might want to check the following regular expression for patterns that are currently blocked:" +You might want to check the following regular expression for patterns that are currently blocked:", +"subcategorycount" => "There are $1 subcategories to this category.", +"categoryarticlecount" => "There are $1 articles in this category.", +"usenewcategorypage" => "1\n\nSet first character to \"0\" to disable the new category page layout." ); diff --git a/languages/LanguageDe.php b/languages/LanguageDe.php index 251b9435e2..d698eceaec 100644 --- a/languages/LanguageDe.php +++ b/languages/LanguageDe.php @@ -1147,8 +1147,8 @@ Diskussions-Seite nicht, da schon eine mit dem neuen Titel existiert. Bitte glei "infobox_alert" => "Bitte geben Sie den Text ein, den Sie formatiert haben möchten.\\nEr wird dann zum Kopieren in der Infobox angezeigt.\\nBeispiel:\\n$1\\nwird zu\\n$2", "nocookiesnew" => "Der Benutzerzugang wurde erstellt, aber Sie sind nicht eingeloggt. {{SITENAME}} benötigt für diese Funktion Cookies, bitte aktivieren Sie diese und loggen sich dann mit Ihrem neuen Benutzernamen und dem Passwort ein.", "nocookieslogin" => "{{SITENAME}} benutzt Cookies zum Einloggen der Benutzer. Sie haben Cookies deaktiviert, bitte aktivieren Sie diese und versuchen es erneut.", - - +"subcategorycount" => "Diese Kategorie hat $1 Unterkategorien.", +"categoryarticlecount" => "Dieser Kategorie gehören $1 Artikel an.": );