Extension:Google Sitemap/Sources

Beautiful site,

SpecialGoogleSitemap.php
 \n\n";       }

function getSQL { $dbr =& wfGetDB( DB_SLAVE ); $page = $dbr->tableName( 'page' ); $revision = $dbr->tableName( 'revision' ); $criterion = $this->sorting_criterion=="REV"?"rev_timestamp":"page_counter"; return "SELECT 'Popularpages' AS type,                               page_id AS id,                                page_namespace AS namespace,                                page_title AS title,                                ( MAX( rev_timestamp ) ) AS last_modification,                                $criterion AS value                                FROM $page, $revision                                        WHERE ( page_namespace <> 8 AND page_namespace <> 9 )                                        AND page_is_redirect = 0                                        AND rev_page = page_id                                GROUP BY page_id"; }       function sortDescending { return true; }       function preprocessResults( $db, $res ) { $this->count = $db->numRows($res); }       function formatResult( $skin, $result ) { global $wgLang, $wgContLang, $wgServer; $title = Title::makeTitle( $result->namespace, $result->title ); $link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText ) ) );

$url = $title->escapeLocalURL; $this->form_action=$title->escapeLocalURL( 'action=submit' ); // The date must conform to ISO 8601 (http://www.w3.org/TR/NOTE-datetime) // UTC (Coordinated Universal Time) is used, google currently ignores time however $last_modification = gmdate( "Y-m-d\TH:i:s\Z", wfTimestamp( TS_UNIX, $result->last_modification ) ); $this->addURL( $wgServer, $url, $last_modification, $result->id ); ++$this->cursor_pos; return "{$link} ($wgServer$url) "; }

function addURL( $base, $url, $last_modification, $page_id ) { // parameters must be valid XML data $result=" \n    $base$url \n    ".$this->getPriority." \n    $last_modification \n    ".$this->getChangeFreq($page_id)." \n  \n"; $this->utf8_write( $this->file_handle, $result ); }       function getPriority { // must return valid XML data $x = $this->cursor_pos / $this->count;

switch( $this->article_priorities ) { case "constant"   : return $this->DEFAULT_PRIORITY; case "linear"     : return 1.0 - $x; case "quadratic"  : return pow( 1.0 - $x, 2.0 ) ; case "cubic"      : return 3.0 * pow( ( 1.0 - $x ), 2.0 ) - 2.0 * pow( ( 1.0 - $x ), 3.0 ); case "exponential" : return exp( -6 * $x ); # exp(-6) ~= 0,002479 case "smooth"     : return cos( $x * pi / 2.0 ); case "random"     : return mt_rand / mt_getrandmax; case "reverse"    : return $x; default: return $this->DEFAULT_PRIORITY; }       }        function getChangeFreq( $page_id ) { // must return valid XML data if( $this->estimate_change_freq ) { $dbr =& wfGetDB( DB_SLAVE );

$revision = $dbr->tableName( 'revision' );

$sql = "SELECT                                        MIN(rev_timestamp) AS creation_timestamp,                                        COUNT(rev_timestamp) AS revision_count                                        FROM $revision WHERE rev_page = $page_id"; $res = $dbr->query( $sql ); $count = $dbr->numRows( $res ); if( $count < 1 ) { return $this->DEFAULT_CHANGE_FREQ; } else { $item1 =( $dbr->fetchObject( $res ) ); $cur = time ; // now $first = wfTimestamp( TS_UNIX, $item1->creation_timestamp ); // there were $item1->revision_count revisions in ($cur - $first) seconds $diff = ($cur - $first) / $item1->revision_count ; switch( true ) { # case $diff < 60: return "always"; // I suspect Google to ignore these pages more often... case $diff < 3600: return "hourly"; case $diff < 24*3600: return "daily"; case $diff < 7*24*3600: return "weekly"; case $diff < 30.33*24*3600: return "monthly"; case $diff < 365.25*24*3600: return "yearly"; default: return $this->DEFAULT_CHANGE_FREQ; # return "never"; // for archived pages only }                       }                } else { return $this->DEFAULT_CHANGE_FREQ; }       } }

/** * Entry point. */ function wfSpecialGoogleSitemap { list( $limit, $offset ) = wfCheckLimits; $gsitemap = new GoogleSitemapPage( $offset, $limit ); $gsitemap->initialize; $gsitemap->finalize; }