MediaWiki HowTo
From KnowWiki
| MediaWiki HowTo |
|---|
| MediaWiki HowTo Topics |
Contents |
[edit] How to add a Google +1 (Google Plus One) button to every page
Here is how to do it for the default Vector skin.
- Backup /w/skins/Vector.php
- In Vector.php, find
<!-- firstHeading --> <h1 id="firstHeading" class="firstHeading"><?php $this->html( 'title' ) ?></h1>
- Add the following code right below the </h1>:
<g:plusone size="medium"></g:plusone> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script>
- If you use a different skin, try finding your first header and modifying it.
[edit] How to automatically generate sitemap for Google
[edit] MediaWiki 1.17
Use a new "urlpath" option of the .../maintenance/generateSitemap.php script:
- Try manually generating a site map like this:
php generateSitemap.php site.name.com --fspath /home/user/public_htmp --server "http://site.name.com" --urlpath "http://site.name.com"
- Upload the generated file to Google by logging in to Google Webmaster Tools and submitting the sitemap sitemap-index-user_database.xml as the sitemap. Everything should be marked as success.
- Run:
crontab -e
and add the following crontab entry:
*/45 * * * * /usr/local/bin/php /home/user/public_html/wikiengine/maintenance/generateSitemap.php site.name.com --fspath /home/user/public_html/ --server "http://site.name.com" --urlpath "http://site.name.com"
[edit] MediaWiki 1.16
First patch up your .../maintenance/generateSitemap.php script with the following patch (download):
--- generateSitemap.php.bak 2010-09-09 15:50:08.000000000 -0500 +++ generateSitemap.php 2010-09-09 16:53:33.000000000 -0500 @@ -74,6 +74,14 @@ var $compress; /** + * The server URL to prepend to the filename + * Nicola Asuni 2010-05-30 + * + * @var string + */ + var $server; + + /** * The number of entries to save in each sitemap file * * @var array @@ -147,6 +155,7 @@ $this->size_limit = pow( 2, 20 ) * 10; $this->fspath = self::init_path( $this->getOption( 'fspath', getcwd() ) ); $this->compress = $this->getOption( 'compress', 'yes' ) !== 'no'; + $this->server = $this->getOption( 'server', '/' ); $this->dbr = wfGetDB( DB_SLAVE ); $this->generateNamespaces(); $this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() ); @@ -290,7 +299,7 @@ $filename = $this->sitemapFilename( $namespace, $smcount++ ); $this->file = $this->open( $this->fspath . $filename, 'wb' ); $this->write( $this->file, $this->openFile() ); - fwrite( $this->findex, $this->indexEntry( $filename ) ); + fwrite( $this->findex, $this->indexEntry( $this->server.'/'.$filename ) ); $this->output( "\t$this->fspath$filename\n" ); $length = $this->limit[0]; $i = 1; @@ -405,10 +414,11 @@ * @return string */ function indexEntry( $filename ) { + $filename = preg_replace('/[\t\r\n\s]+/i', '', $filename); // Nicola Asuni 2010-05-30 return "\t<sitemap>\n" . "\t\t<loc>$filename</loc>\n" . - "\t\t<lastmod>{$this->timestamp}</lastmod>\n" . + "\t\t<lastmod>".$this->timestamp."</lastmod>\n" . "\t</sitemap>\n"; } @@ -444,11 +454,14 @@ * @return string */ function fileEntry( $url, $date, $priority ) { + $url = preg_replace('/http:\/\/.+?\//', '', $url); + $url = $this->server."/".$url; + $url = preg_replace('/[\t\r\n\s]+/i', '', $url); // Nicola Asuni 2010-05-30 return "\t<url>\n" . - "\t\t<loc>$url</loc>\n" . - "\t\t<lastmod>$date</lastmod>\n" . - "\t\t<priority>$priority</priority>\n" . + "\t\t<loc>".$url."</loc>\n" . + "\t\t<lastmod>".$date."</lastmod>\n" . + "\t\t<priority>".$priority."</priority>\n" . "\t</url>\n"; }
- Save the code above in a text file and patch generateSitemap.php:
patch generateSitemap.php generateSitemap.patch
- Try manually generating a site map like this:
php generateSitemap.php site.name.com --fspath /home/user/public_htmp --server "http://site.name.com"
- Upload the generated file to Google by logging in to Google Webmaster Tools and submitting the sitemap sitemap-index-user_database.xml as the sitemap. Everything should be marked as success.
- Run:
crontab -e
and add the following crontab entry:
*/45 * * * * /usr/local/bin/php /home/user/public_html/wikiengine/maintenance/generateSitemap.php tech.ivkin.net --fspath /home/user/public_html/ --server "http://tech.ivkin.net"
|
||