MediaWiki/Botclasses.php/en

Материал из СисадминВики (SysadminWiki.ru)
Перейти к: навигация, поиск
Эта страница — перевод страницы MediaWiki/Botclasses.php. Перевод выполнен на 91%.

Таким образом помечены устаревшие переводы.
Другие языки:
English • ‎русский

MediaWiki site statistics in skin

In MediaWiki-based sites there is an ability to show statistics by using special magic words. But they work only inside the article content. In order to show statistics in skin (header, footer or elsewhere) we need to use API of the engine. That requires some additional PHP code.

There is the helping script botclasses.php we can use. The small additional script wikistat.php (which goes together with botclasses.php) will help us to use it. All we need is just to set some connection parameters. Call wiki_statistics() function within skin at desired place.

There is an example to show statistics on number of articles in wiki:

require_once( "botclasses.php" ); //include bot functions

<?php echo wiki_statistics('articles'); ?>
  • There is an example of HTML code to show number of articles in wiki, uploaded images and number of articles in "Города" (Cities) category.
<?php require_once( "botclasses.php" ); ?>

<p><a href="/semantic/Служебная:Все_страницы" title="Показать все статьи">Статей</a>: 
<b><?php echo wiki_statistics('articles'); ?></b>,

<a href="/semantic/Служебная:Список_файлов" title="Показать список всех загруженных файлов">Файлов</a>: 
<b><?php echo wiki_statistics('images'); ?> </b></p> 

<a href="/semantic/Шаблон:Основные_порталы" title="Показать количество статей в категории Города">Городов</a>: 
<b><?php echo wiki_statistics('category', 'Города'); ?></b>,

</p>

Function wiki_statistics() holds all the statistics parameters:

  • activeusers - active users
  • admins - administrators
  • articles
  • category
  • edits
  • images - uploaded images
  • pages
  • users - all users

Writing error to /tmp/ directory

If your hoster forbids to write to system temporary directory, then we need to change two lines for curl:

curl_setopt($this->ch,CURLOPT_COOKIEJAR, '/tmp/cluewikibot.cookies.'.$this->uid.'.dat');
curl_setopt($this->ch,CURLOPT_COOKIEFILE,'/tmp/cluewikibot.cookies.'.$this->uid.'.dat');

change /tmp/ to appropriate directory. For example if the path of the system user temporary directory is /home/www/user/temp/, then those lines should look like these:

curl_setopt($this->ch,CURLOPT_COOKIEJAR, '/home/www/user/temp/cluewikibot.cookies.'.$this->uid.'.dat');
curl_setopt($this->ch,CURLOPT_COOKIEFILE,'/home/www/user/temp/cluewikibot.cookies.'.$this->uid.'.dat');

See also