Index: trunk/extensions/RPED/RPED.php |
— | — | @@ -0,0 +1,44 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Remote Page Existence Detection (RPED) extension by Tisane |
| 5 | + * URL: http://www.mediawiki.org/wiki/Extension:RemotePageExistenceDetection |
| 6 | + * |
| 7 | + * This program is free software. You can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. You can also redistribute it and/or |
| 11 | + * modify it under the terms of the Creative Commons Attribution 3.0 license. |
| 12 | + * |
| 13 | + * This extension looks up all the wikilinks on a page that would otherwise be red and compares them |
| 14 | + * to a table of page titles to determine whether they exist on a remote wiki. If so, the wikilink |
| 15 | + * turns blue and links to the page on the remote wiki. |
| 16 | + */ |
| 17 | + |
| 18 | + |
| 19 | +/* Alert the user that this is not a valid entry point to MediaWiki if they try to access the |
| 20 | +special pages file directly.*/ |
| 21 | + |
| 22 | +if (!defined('MEDIAWIKI')) { |
| 23 | + echo <<<EOT |
| 24 | + To install the RPED extension, put the following line in LocalSettings.php: |
| 25 | + require( "extensions/RPED/RPED.php" ); |
| 26 | +EOT; |
| 27 | + exit( 1 ); |
| 28 | +} |
| 29 | + |
| 30 | +$wgExtensionCredits['specialpage'][] = array( |
| 31 | + 'name' => 'Remote Page Existence Detection', |
| 32 | + 'author' => 'Tisane', |
| 33 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:RemotePageExistenceDetection', |
| 34 | + 'description' => 'Remote Page Existence Detection', |
| 35 | + 'descriptionmsg' => 'rped-desc', |
| 36 | + 'version' => '1.0.0', |
| 37 | +); |
| 38 | + |
| 39 | +$dir = dirname(__FILE__) . '/'; |
| 40 | +$wgAutoloadClasses['RPEDHooks'] = $dir.'RPED.hooks.php'; |
| 41 | +$wgExtensionMessagesFiles['RPED'] = $dir . 'RPED.i18n.php'; |
| 42 | +$wgExtensionAliasesFiles['RPED'] = $dir . 'RPED.alias.php'; |
| 43 | + |
| 44 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'RPEDHooks::RPEDCreateTable'; |
| 45 | +$wgHooks['LinkBegin'][] = 'RPEDHooks::wikipediaLink'; |
\ No newline at end of file |
Property changes on: trunk/extensions/RPED/RPED.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 46 | + native |
Index: trunk/extensions/RPED/rpedtable.sql |
— | — | @@ -0,0 +1,12 @@ |
| 2 | +BEGIN; |
| 3 | + |
| 4 | +CREATE TABLE rped_page( |
| 5 | +rped_page_id int NOT NULL AUTO_INCREMENT, |
| 6 | +rped_page_title varchar(256), |
| 7 | +PRIMARY KEY (rped_page_id) |
| 8 | +); |
| 9 | + |
| 10 | +CREATE INDEX rped_page_id ON rped_page (rped_page_id); |
| 11 | +CREATE INDEX rped_page_title ON rped_page (rped_page_title); |
| 12 | + |
| 13 | +COMMIT; |
\ No newline at end of file |
Property changes on: trunk/extensions/RPED/rpedtable.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 14 | + native |
Index: trunk/extensions/RPED/RPED.hooks.php |
— | — | @@ -0,0 +1,82 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI')) { |
| 4 | + echo <<<EOT |
| 5 | +To install the RPED extension, put the following line in LocalSettings.php: |
| 6 | +require_once( "\$IP/extensions/RPED/RPED.php" ); |
| 7 | +EOT; |
| 8 | + exit( 1 ); |
| 9 | +} |
| 10 | + |
| 11 | +class RPEDHooks { |
| 12 | + |
| 13 | + public static function RPEDCreateTable() { |
| 14 | + global $wgExtNewTables; |
| 15 | + $wgExtNewTables[] = array( |
| 16 | + 'blanked_pages', |
| 17 | + dirname( __FILE__ ) . '/rpedtable.sql' ); |
| 18 | + return true; |
| 19 | + } |
| 20 | + |
| 21 | + public static function wikipediaLink( $skin, $target, &$text |
| 22 | + , &$customAttribs, &$query, &$options, &$ret ) { |
| 23 | + global $wgLocalStyle,$wgRemoteStyle,$wgPureWikiDeletionInEffect |
| 24 | + ,$wgTitle,$wgRequest; |
| 25 | + if ($wgTitle->getNamespace ()==-1){ |
| 26 | + return true; |
| 27 | + } |
| 28 | + if (isset($query['action']) && $query['action']=='history'){ |
| 29 | + return true; |
| 30 | + } |
| 31 | + if ($wgRequest->getText( 'action' )=='history'){ |
| 32 | + return true; |
| 33 | + } |
| 34 | + $itIsBlank=false; |
| 35 | + // Return immediately if we know it's existent on the local wiki |
| 36 | + if ( in_array( 'known', $options ) ) { |
| 37 | + if (!isset($query['action']) && !isset($query['curid'])){ |
| 38 | + $customAttribs['style']=$wgLocalStyle; |
| 39 | + } |
| 40 | + if (!isset($wgPureWikiDeletionInEffect) || $wgPureWikiDeletionInEffect!=true){ |
| 41 | + return true; |
| 42 | + } |
| 43 | + $dbr = wfGetDB( DB_SLAVE ); |
| 44 | + /*$myRevision=Revision::loadFromTitle($dbr,$target); |
| 45 | + if ($myRevision->getRawText()!=''){*/ |
| 46 | + $id=$target->getArticleID(); |
| 47 | + $result=$dbr->selectRow('blanked_page','blank_page_id' |
| 48 | + ,array("blank_page_id" => $id)); |
| 49 | + if (!$result){ |
| 50 | + return true; |
| 51 | + } |
| 52 | + $itIsBlank=true; |
| 53 | + } |
| 54 | + |
| 55 | + // If it doesn't exist on the local wiki, then see if it exists on the |
| 56 | + // remote wiki (Wikipedia) |
| 57 | + if ( in_array( 'broken', $options ) || $itIsBlank==true) { |
| 58 | + $title=$target->getPrefixedText (); |
| 59 | + for ($thiscount=0; $thiscount<strlen($title); $thiscount++){ |
| 60 | + if (substr($title,$thiscount,1)==' '){ |
| 61 | + $title=substr_replace($title,'_',$thiscount,1); |
| 62 | + } |
| 63 | + } |
| 64 | + $dbr = wfGetDB( DB_SLAVE ); |
| 65 | + $result=$dbr->selectRow('rped_page','rped_page_id' |
| 66 | + ,array("rped_page_title" => $title)); |
| 67 | + |
| 68 | + if (!$result){ |
| 69 | + return true; |
| 70 | + } else { |
| 71 | + $title=htmlentities($title); |
| 72 | + $url='http://en.wikipedia.org/wiki/'.$title; |
| 73 | + |
| 74 | + // The page that we'll link to |
| 75 | + $text='<a href="'.$url.'">'.$text.'</a>'; |
| 76 | + if ($wgRemoteStyle!=''){ |
| 77 | + $customAttribs['style']=$wgRemoteStyle; |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + return true; |
| 82 | + } |
| 83 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/RPED/RPED.hooks.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 84 | + native |
Index: trunk/extensions/RPED/RPEDFileReader.pl |
— | — | @@ -0,0 +1,68 @@ |
| 2 | +# RPEDFileReader.pl by Tisane, http://www.mediawiki.org/wiki/User:Tisane |
| 3 | +# |
| 4 | +# This script is free software that is available under the terms of the Creative Commons |
| 5 | +# Attribution 3.0 license and the current version of the GNU General Public License. |
| 6 | +# |
| 7 | +# The purpose of this script is to read a text file (specifically, the list of page titles from |
| 8 | +# Wikipedia's data dump) and add each page title to a database table. |
| 9 | + |
| 10 | +use strict; |
| 11 | + |
| 12 | +my $base_module_dir = (-d '/home2/rpedorg/perl' ? '/home2/rpedorg/perl' : ( getpwuid($>) )[7] . '/perl/'); |
| 13 | + unshift @INC, map { $base_module_dir . $_ } @INC; |
| 14 | + |
| 15 | +#use Mysql; |
| 16 | +use DBI; |
| 17 | + |
| 18 | +my $sql_login = 'rpedorg'; |
| 19 | +my $sql_pass = 'Ab123456!'; |
| 20 | +my $db_name = 'rpedorg_libertapedia'; |
| 21 | +my $db_host = 'localhost'; # or remote mysql server name |
| 22 | +my $numArgs = $#ARGV + 1; |
| 23 | +my $offset=0; |
| 24 | +my $titleMatch=''; |
| 25 | +if ($numArgs>1){ |
| 26 | + if ($ARGV[0] eq '-line' || $ARGV[0] eq '-l'){ |
| 27 | + $offset=$ARGV[1]; |
| 28 | + } |
| 29 | + if ($ARGV[0] eq '-title' || $ARGV[0] eq '-t'){ |
| 30 | + $titleMatch=$ARGV[1]; |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +# if left blank, this defaults to localhost |
| 35 | + |
| 36 | +# PERL MYSQL CONNECT() |
| 37 | +my $conn_string = "DBI:mysql:$db_name"; |
| 38 | +if ($db_host) { $conn_string .= ":$db_host"; } |
| 39 | +my $dbh = DBI->connect("$conn_string",$sql_login,$sql_pass); |
| 40 | + |
| 41 | +my $filename='enwiki-20100312-all-titles-in-ns0'; |
| 42 | +open(MYDATA, $filename) or |
| 43 | + die("Error: cannot open file '".$filename."'\n"); |
| 44 | +my $line; |
| 45 | +my $lnum = 1; |
| 46 | +my $titleMatched=0; |
| 47 | +if ($titleMatch eq ''){ |
| 48 | + $titleMatched=1; |
| 49 | +} |
| 50 | +while( $line = <MYDATA> ){ |
| 51 | + chomp($line); |
| 52 | + if ($titleMatched==0){ |
| 53 | + if ($titleMatch eq $line){ |
| 54 | + $titleMatched=1; |
| 55 | + } |
| 56 | + } |
| 57 | + if ($lnum>=$offset && $titleMatched==1){ |
| 58 | + $line=$dbh->quote("$line"); |
| 59 | + my $sql="INSERT INTO rped_page (rped_page_title) VALUES ($line)"; |
| 60 | + $dbh->prepare($sql); |
| 61 | + $dbh->do($sql); |
| 62 | + if ($lnum%100==0){ |
| 63 | + print "$lnum: $line\n"; |
| 64 | + } |
| 65 | + } |
| 66 | + $lnum++; |
| 67 | +} |
| 68 | + |
| 69 | +close MYDATA; |
\ No newline at end of file |
Index: trunk/extensions/RPED/RPED.alias.php |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +<?php |
| 3 | +$aliases = array(); |
| 4 | + |
| 5 | +/** English */ |
| 6 | +$aliases['en'] = array( |
| 7 | + 'RPED' => array( 'RPED' ), |
| 8 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/RPED/RPED.alias.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 9 | + native |
Index: trunk/extensions/RPED/RPED.i18n.php |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +<?php |
| 3 | +$messages = array(); |
| 4 | + |
| 5 | +$messages['en'] = array( |
| 6 | + 'rped' => 'Remote Page Existence Detection', |
| 7 | + 'rped-desc' => 'Links wikilinks to Wikipedia if the page is nonexistent on ' |
| 8 | + .'the local wiki but exists on Wikipedia', |
| 9 | +); |
Property changes on: trunk/extensions/RPED/RPED.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 10 | + native |