Extension:Urllogger

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
Urllogger

Release status: unknown

Implementation User interface
Description Script to log added URLs to a text file.
Author(s) Aerik Sylvan
Download see below
Hooks used

ArticleSave

Urllogger is a script to log added URLs to a text file. To install it, copy the code below to extensions/Urllogger.php and add require_once ("$IP/extensions/Urllogger.php"); to your wiki's LocalSettings.php. Make sure that the file extensions/urllog.txt is writable.

[edit] Source code

<?php
/**
Script to log added URLs to a text file, based loosly on Brion's early captcha work
Aerik Sylvan, January 2006
 */
 
if ( defined( 'MEDIAWIKI' ) ) {
 
        $wgHooks['ArticleSave'][] = "logurls";
}
 
 
        // ----------------------------------
 
        /**
         * @param EditPage $editPage
         * @param string $newtext
         * @param string $section
         * @return bool true if the captcha should run
         */
        function logurls($article, $user, $newtext) {
        $logfile = "extensions/urllog.txt";
        print_r($ary);
                $oldtext = $article->getContent( TRUE );
                $oldLinks = findLinks( $oldtext );
                $newLinks = findLinks( $newtext );
                //$unknownLinks = array_filter( $newLinks, array( &$this, 'filterLink' ) 
 
                //$addedLinks = array_diff( $unknownLinks, $oldLinks );
                $addedLinks = array_diff( $newLinks, $oldLinks );
                print_r($addedLinks);
                $numLinks = count( $addedLinks );
 
                if( $numLinks > 0 ) {
                        global $wgUser;
                        $name = $user->getName();
                        foreach($addedLinks as $link){
                                $logentry .= $link."\t".date("U")."\t".$name."\n";
                        }
                        $handle = fopen ($logfile, "a");
            fwrite($handle,$logentry);
            fclose($handle);
                }
 
                return true;
        }
 
        function findLinks( $text ) {
                $regex = '/((?:' . HTTP_PROTOCOLS . ')' . EXT_LINK_URL_CLASS . '+)/';
                //print "***".$regex."***\n";
 
                if( preg_match_all( $regex, $text, $matches, PREG_PATTERN_ORDER ) ) {
                        return $matches[0];
                } else {
                        return array();
                }
        }
 
        function loadText( $editPage, $section ) {
                $rev = Revision::newFromTitle( $editPage->mTitle );
                if( is_null( $rev ) ) {
                        return "";
                } else {
                        $text = $rev->getText();
                        if( $section != '' ) {
                                return Article::getSection( $text, $section );
                        } else {
                                return $text;
                        }
                }
        }
Personal tools