Extension:ExternalArticles
External Articles Release status: experimental |
|||
---|---|---|---|
Implementation | Page action | ||
Description | Preloads source from external articles. | ||
Author(s) | Nathan Perry (Servel333Talk) | ||
Last version | 0.1.3 (2010-03-05) | ||
MediaWiki | 1.12.0+ | ||
License | GPL | ||
Download | source readme changelog |
||
|
|||
|
|||
Check usage (experimental) |
Contents |
[edit] Usage
Saves time when importing pages from an external website.
When a page is edited, its title must match the regular expression stored in $eagRules['rule']. If it matches, the content of the external article matching the current local page name is fetched and then preloaded into the local edit box. The extension will only preload when creating a new article, and when there is not already a local page being preloaded.
[edit] changelog
[edit] version 0.1.3
- Removed dependence on PHP config "allow_url_fopen" by changing to use cURL
- Thanks to Alvinos.
[edit] version 0.1.2
- rephrased errors, added todo's and other minor changes.
[edit] version 0.1.1
- Modified the $wgExtensionCredits
- Bug: hmm... defined the 'author' element twice when I meant 'url' the second time.
- Bug: The url specified was incorrect.
- Added a contact email address specific to this extension.
[edit] version 0.1
- preloads text into an edit box on article edit.
- Configure external wiki to draw text from (defaults to Wikipedia)
- Configure perl-compatible regular expression to include or exclude certain pages (defaults to Templates only)
[edit] readme
[edit] Installation
- Create a new folder in your MediaWiki extensions folder named "ExternalArticles"
- Create a new file in the just created folder "extensions/ExternalArticles/ExternalArticles.php"
- Copy the source below into the file "ExternalArticles.php"
- Add the following to your "LocalSettings.php"
require_once("$IP/extensions/ExternalArticles/ExternalArticles.php");
[edit] Configuration
This step is optional. If you do not include the below code, this extension will use the defaults. If you define $eagRules, you must define all the elements of it (likely to change later so you can only override the settings you want).
This extension currently has only one configuration variable "$eagRules". If you wish to change the default behavior, put the following code in your LocalSettings.php above the require_once
statement for this extension.
// External Articles Configuration $eagRules = array(); // Specifies if text will be preloaded on edit $eagRules['onpreload'] = true; // Specifies the URL of the external wiki. Must point to the index.php?title= and not the short link $eagRules['url'] = 'http://en.wikipedia.org/w/index.php?title='; // Specifies the regular expression used to determine if an article will be preloaded. // See http://us3.php.net/manual/en/function.preg-match.php for more information. #$eagRules['rule'] = '/.*/'; // All articles $eagRules['rule'] = '/^Template:.*$/'; // Tempaltes only (in English MediaWiki, default) #$eagRules['rule'] = '/^.*talk:.*$/'; // Talk pages only (and any page that contains "talk:")
[edit] Known Issues
- The default rule does not support languages other than English, as the namespace of a template is assumed to be "Template". When implementing in other languages the template namespace string is localized, so the rule must be updated to fit the current language.
[edit] Feedback
I'm looking for feedback on this extension. Security, performance, etc...
Please post feedback to the Extension_talk:ExternalArticles page or email me here.
[edit] Security
- This extension just fetches external wiki-text and inserts it to preload the edit box. No checking is done to validate or verify wiki-text.
[edit] Future development
The long term goal of this extension is to allow a wiki to use templates or other articles from external MediaWiki wiki's without having to import the articles and all the transcluded articles it depends on manually. When an article is demanded (viewed, created, linked to, transcluded) it is automatically downloaded from the external wiki and cached.
There is no release schedule for this extension. When I have time and motivation to work on this extension, I will do so and make new releases that implement features when it makes sense to do so.
[edit] source
<?php /** * ExternalArticles.php * * Copyright (C) 2009 Nathan Perry <nate perry 333 at g mail dot com> * http://www.nateperry.org/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @ingroup Extensions * @author Nathan Perry <[email protected]> * @version 0.1.3 * @link http://www.nateperry.org/wiki/External_Articles * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 * * Credit to Alvinos [http://www.mediawiki.org/wiki/User:Alvinos] for changing to use cURL. */ /** * Protect against register_globals vulnerabilities. * This line must be present before any global variable is referenced. */ if( !defined( 'MEDIAWIKI' ) ) { echo <<<EOT This file is not a valid entry point. To install this extension, put the following line in LocalSettings.php: require_once( "\$IP/extensions/ExternalArticles/ExternalArticles.php" ); EOT; exit( 1 ); } /** * Initialize variables */ define( 'MEDIAWIKI_EXTERNALARTICLES', true ); //define( 'EXTERNALARTICLES_DEBUG', true ); $wgExtensionCredits['other'][] = array ( 'name' => 'External Articles', 'description' => 'Preloads source from external articles.', //'descriptionmsg' => 'externalarticles-description-msg', 'version' => '0.1.3', // version date 2010-03-05 'author' => '[mailto:[email protected] Nathan Perry]', 'url' => 'http://www.mediawiki.org/wiki/Extension:ExternalArticles' ); // todo: change this so each setting is set to it's default if it is not defined. // Currently, if anything is overridden, all must be defined. if ( !isset( $eagRules ) || is_null( $eagRules ) ) { $eagRules = array(); $eagRules['onpreload'] = true; $eagRules['url'] = 'http://en.wikipedia.org/w/index.php?title='; // todo: remove assumption of English. $eagRules['rule'] = '/^Template:.*$/'; // http://us3.php.net/manual/en/function.preg-match.php } else { // todo: validate $eagRules URL's, etc... } $wgHooks['EditFormPreloadText'][] = 'externalarticles_EditFormPreloadText'; function externalarticles_EditFormPreloadText(&$text, &$title) { // Called when edit page for a new article is shown. This lets you fill the text-box of a new page with initial wikitext // $text: text to prefill edit form with // $title: title of new page (Title Object) global $wgOut, $eagRules; $pagename = $title->getEscapedText(); $url = $eagRules['url'] . urlencode( $pagename ) . '&action=raw'; $ismatch = preg_match( $eagRules['rule'], $pagename ) > 0; if ( defined( 'EXTERNALARTICLES_DEBUG' ) ) { if ( $ismatch ) { $wgOut->addWikiText( "URL: $url<br />" ); } else { $wgOut->addWikiText( "Page title does not match rule.<br />" ); } } if ( $eagRules['onpreload'] && $ismatch && empty($text) ) { // Initialize the cURL session $ch = curl_init(); // Set the URL of the page or file to download. curl_setopt($ch, CURLOPT_URL,$url); // Ask cURL to return the contents in a variable // instead of simply echoing them to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Execute the cURL session $url_text = curl_exec ($ch); // Close cURL session curl_close ($ch); if ( !empty( $url_text ) ) { $text = $url_text; } else { if ( defined( 'EXTERNALARTICLES_DEBUG' ) ) { $wgOut->addWikiText( "Failed to fetch external page.<br />" ); } } return true; } else { return false; } } ?>