Mailing List Archive

SEO extension
I didn't know if anybody else would be interested in this or possibly
adding it into the MediaWiki source tree but figured I'd toss this out
for people to use or not use as they may. It enhances the keyword and
description meta tags of the wiki by first allowing you to set the
number of link text keywords by setting $wgKeywordsX. You can set the
default keywords and description with $wgKeywords and $wgDescription. If
either the keywords or description aren't set otherwise then they'll get
filled in with the link text (as keywords did before). If you also use
the extension then users can edit the page's keywords and description
when editing the wiki using the keywords and description tags.

This can be useful for more fine grained control over how search engines
index your wiki pages.


Change to includes/OutputPage.php.

---
# This function takes the existing and broken links for the page
# and uses the first 10 of them for META keywords
function addMetaTags () {
global $wgLinkCache, $wgOut;
global $wgKeywordsX, $wgKeywords, $wgDescription;
$good = array_keys ( $wgLinkCache->mGoodLinks ) ;
$bad = array_keys ( $wgLinkCache->mBadLinks ) ;
if ( ! ( $wgKeywords && $wgDescription ) ) {
$a = array_merge ( $good , $bad ) ;
$wgKeywordsX ? $wgKeywordsX : 10;
$a = array_slice ( $a , 0 , $wgKeywordsX ) ; # keywords max
$a = implode ( "," , $a ) ;
$strip = array(
"/<.*?>/" => '',
"/[_]/" => ' '
);
$a = htmlspecialchars(preg_replace(array_keys($strip),
array_values($strip),$a ));
}
$wgKeywords = $wgKeywords ? $wgKeywords : $a;
$wgOut->addMeta ( "keywords" , $wgKeywords );
$wgDescription = $wgDescription ? $wgDescription : $a;
$wgOut->addMeta ( "description" , $wgDescription );
}
---

New file, extensions/SEO.php.
---
/*
MediaWiki extension to allow wiki users to change the page's keyword
and description meta tags. Introduces the description and keywords tags.
*/

$wgExtensionFunctions[] = "SEO_DescriptionExtension";
$wgExtensionFunctions[] = "SEO_KeywordsExtension";

function SEO_DescriptionExtension () {
global $wgParser;
$wgParser->setHook( 'description', '_SEO_Description' );
}

function _SEO_Description ( $input ) {
global $wgDescription;
$wgDescription = $input;
return '';
}

function SEO_KeywordsExtension () {
global $wgParser;
$wgParser->setHook( 'keywords', '_SEO_Keywords' );
}

function _SEO_Keywords ( $input ) {
global $wgKeywords;
$wgKeywords = $input;
return '';
}
---

--
Michael <mogmios@mlug.missouri.edu>
http://kavlon.org