do_user_real_name_update(); flush();
do_querycache_update(); flush();
do_objectcache_update(); flush();
+ do_categorylinks_update(); flush();
initialiseMessages(); flush();
chdir( "config" );
$sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
wfQuery( $sql, DB_WRITE, $fname );
+ $sql = "DELETE FROM categorylinks WHERE cl_from={$id}";
+ wfQuery( $sql, DB_WRITE, $fname );
+
$log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
$art = $this->mTitle->getPrefixedText();
$log->addEntry( wfMsg( "deletedarticle", $art ), $reason );
class LinkCache {
// Increment $mClassVer whenever old serialized versions of this class
// becomes incompatible with the new version.
- /* private */ var $mClassVer = 1;
+ /* private */ var $mClassVer = 2;
/* private */ var $mGoodLinks, $mBadLinks, $mActive;
- /* private */ var $mImageLinks;
+ /* private */ var $mImageLinks, $mCategoryLinks;
/* private */ var $mPreFilled, $mOldGoodLinks, $mOldBadLinks;
/* private */ function getKey( $title ) {
$this->mGoodLinks = array();
$this->mBadLinks = array();
$this->mImageLinks = array();
+ $this->mCategoryLinks = array();
$this->mOldGoodLinks = array();
$this->mOldBadLinks = array();
}
{
if ( $this->mActive ) { $this->mImageLinks[$nt->getDBkey()] = 1; }
}
+
+ function addCategoryLink( $title, $sortkey ) {
+ if ( $this->mActive ) { $this->mCategoryLinks[$title] = $sortkey; }
+ }
+
+ function addCategoryLinkObj( &$nt, $sortkey ) {
+ $this->addCategoryLink( $nt->getDBkey(), $sortkey );
+ }
function clearBadLink( $title )
{
function getGoodLinks() { return $this->mGoodLinks; }
function getBadLinks() { return array_keys( $this->mBadLinks ); }
function getImageLinks() { return $this->mImageLinks; }
+ function getCategoryLinks() { return $this->mCategoryLinks; }
function addLink( $title )
{
function doUpdate()
{
global $wgUseBetterLinksUpdate, $wgLinkCache, $wgDBtransactions;
- global $wgEnablePersistentLC;
+ global $wgEnablePersistentLC, $wgUseCategoryMagic;
/* Update link tables with outgoing links from an updated article */
/* Relies on the 'link cache' to be filled out */
}
if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
+ #------------------------------------------------------------------------------
+ # Category links
+ if( $wgUseCategoryMagic ) {
+ $sql = "DELETE FROM categorylinks WHERE cl_from='{$this->mId}'";
+ wfQuery( $sql, DB_WRITE, $fname );
+
+ # Get addition list
+ $add = $wgLinkCache->getCategoryLinks();
+
+ # Do the insertion
+ $sql = "";
+ if ( 0 != count ( $add ) ) {
+ $sql = "INSERT INTO categorylinks (cl_from,cl_to,cl_sortkey) VALUES ";
+ $first = true;
+ foreach( $add as $cname => $sortkey ) {
+ # FIXME: Change all this to avoid unnecessary duplication
+ $nt = Title::makeTitle( NS_CATEGORY, $cname );
+ if( !$nt ) continue;
+ $nt->invalidateCache();
+
+ if ( ! $first ) { $sql .= ","; }
+ $first = false;
+
+ $sql .= "({$this->mId},'" . wfStrencode( $cname ) .
+ "','" . wfStrencode( $sortkey ) . "')";
+ }
+ }
+ if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
+ }
+
$this->fixBrokenLinks();
if( $wgDBtransactions ) {
# Old inefficient update function
# Used for rebuilding the link table
- global $wgLinkCache, $wgDBtransactions;
+ global $wgLinkCache, $wgDBtransactions, $wgUseCategoryMagic;
$fname = "LinksUpdate::doDumbUpdate";
wfProfileIn( $fname );
}
if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
+ if( $wgUseCategoryMagic ) {
+ $sql = "DELETE FROM categorylinks WHERE cl_from='{$this->mId}'";
+ wfQuery( $sql, DB_WRITE, $fname );
+
+ # Get addition list
+ $add = $wgLinkCache->getCategoryLinks();
+
+ # Do the insertion
+ $sql = "";
+ if ( 0 != count ( $add ) ) {
+ $sql = "INSERT INTO categorylinks (cl_from,cl_to,cl_sortkey) VALUES ";
+ $first = true;
+ foreach( $add as $cname => $sortkey ) {
+ # FIXME: Change all this to avoid unnecessary duplication
+ $nt = Title::makeTitle( NS_CATEGORY, $cname );
+ if( !$nt ) continue;
+ $nt->invalidateCache();
+
+ if ( ! $first ) { $sql .= ","; }
+ $first = false;
+
+ $sql .= "({$this->mId},'" . wfStrencode( $cname ) .
+ "','" . wfStrencode( $sortkey ) . "')";
+ }
+ }
+ if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
+ }
$this->fixBrokenLinks();
if( $wgDBtransactions ) {
$data = array () ;
$id = $this->mTitle->getArticleID() ;
- # For existing categories
- if( $id ) {
- $sql = "SELECT DISTINCT cur_title,cur_namespace FROM cur,links WHERE l_to={$id} AND l_from=cur_id";
- $res = wfQuery ( $sql, DB_READ ) ;
- while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
- } else {
- # For non-existing categories
- $t = wfStrencode( $this->mTitle->getPrefixedDBKey() );
- $sql = "SELECT DISTINCT cur_title,cur_namespace FROM cur,brokenlinks WHERE bl_to='$t' AND bl_from=cur_id" ;
- $res = wfQuery ( $sql, DB_READ ) ;
- while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
- }
+ # FIXME: add limits
+ $t = wfStrencode( $this->mTitle->getDBKey() );
+ $sql = "SELECT DISTINCT cur_title,cur_namespace 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 )
wfFreeResult ( $res ) ;
# Showing subcategories
- if ( count ( $children ) > 0 )
- {
- asort ( $children ) ;
+ if ( count ( $children ) > 0 ) {
$r .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
$r .= implode ( ", " , $children ) ;
}
# Showing pages in this category
- if ( count ( $articles ) > 0 )
- {
+ if ( count ( $articles ) > 0 ) {
$ti = $this->mTitle->getText() ;
- asort ( $articles ) ;
$h = wfMsg( "category_header", $ti );
$r .= "<h2>{$h}</h2>\n" ;
$r .= implode ( ", " , $articles ) ;
$text = $sk->transformContent( $text );
if ( !isset ( $this->categoryMagicDone ) ) {
- $text .= $this->categoryMagic () ;
- $this->categoryMagicDone = true ;
- }
+ $text .= $this->categoryMagic () ;
+ $this->categoryMagicDone = true ;
+ }
wfProfileOut( $fname );
return $text;
} else {
$link = substr( $m[1], 1 );
}
- if( "" == $text )
+ $wasblank = ( "" == $text );
+ if( $wasblank )
$text = $link;
$nt = Title::newFromText( $link );
if ( $ns == $category ) {
$t = $nt->getText() ;
$nnt = Title::newFromText ( Namespace::getCanonicalName($category).":".$t ) ;
+
+ $wgLinkCache->suspend(); # Don't save in links/brokenlinks
$t = $sk->makeLinkObj( $nnt, $t, "", "" , $prefix );
+ $wgLinkCache->resume();
+
+ $sortkey = $wasblank ? $this->mTitle->getPrefixedText() : $text;
+ $wgLinkCache->addCategoryLinkObj( $nt, $sortkey );
$this->mOutput->mCategoryLinks[] = $t ;
$s .= $prefix . $trail ;
return $s ;
--- /dev/null
+--
+-- Track category inclusions *used inline*
+-- cl_from keys to cur_id, cl_to keys to cur_title of the category page.
+-- cl_sortkey is the title of the linking page or an optional override
+-- cl_timestamp marks when the link was last added
+--
+CREATE TABLE categorylinks (
+ cl_from int(8) unsigned NOT NULL default '0',
+ cl_to varchar(255) binary NOT NULL default '',
+ cl_sortkey varchar(255) binary NOT NULL default '',
+ cl_timestamp timestamp NOT NULL,
+ UNIQUE KEY cl_from(cl_from,cl_to),
+ KEY cl_sortkey(cl_to,cl_sortkey(128)),
+ KEY cl_timestamp(cl_to,cl_timestamp)
+);
object cache to cover some slow operations w/o memcached.
patch-querycache.sql
patch-objectcache.sql
+
+* 2004-05-14: Add categorylinks table for handling category membership
+patch-categorylinks.sql
KEY (il_to)
);
+--
+-- Track category inclusions *used inline*
+-- cl_from keys to cur_id, cl_to keys to cur_title of the category page.
+-- cl_sortkey is the title of the linking page or an optional override
+-- cl_timestamp marks when the link was last added
+--
+CREATE TABLE categorylinks (
+ cl_from int(8) unsigned NOT NULL default '0',
+ cl_to varchar(255) binary NOT NULL default '',
+ cl_sortkey varchar(255) binary NOT NULL default '',
+ cl_timestamp timestamp NOT NULL,
+ UNIQUE KEY cl_from(cl_from,cl_to),
+ KEY cl_sortkey(cl_to,cl_sortkey(128)),
+ KEY cl_timestamp(cl_to,cl_timestamp)
+);
+
--
-- Stores (possibly gzipped) serialized objects with
-- cache arrays to reduce database load slurping up
}
}
+function do_categorylinks_update() {
+ global $wgDatabase;
+ if( $wgDatabase->tableExists( "categorylinks" ) ) {
+ echo "...have categorylinks table.\n";
+ } else {
+ echo "Adding categorylinks table for category management... ";
+ dbsource( "maintenance/archives/patch-categorylinks.sql", $wgDatabase );
+ echo "ok\n";
+ }
+}
+
?>
\ No newline at end of file