Extension:ProxyPage

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
ProxyPage

Release status: stable

Implementation User interface
Description
MediaWiki 1.13.x - 1.16.0
License No license specified
Download No link
Example http://www.nozicaa.com/fr/page.content/Contact

Check usage (experimental)

Contents

[edit] What can this extension do?

Displays content from specified HTTP, without redirect.

[edit] Usage

Just add following code as standalone proxy page text:

<!-- ProxyURL: http://my.target.url/page -->

… or …

<!-- ProxyURL: Another wiki page title -->

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/ProxyPage/ProxyPage.setup.php");

[edit] Code

Put following code as $IP/extensions/ProxyPage/ProxyPage.setup.php.

<?php
if( !defined( 'MEDIAWIKI' ) ) {
    echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
    die( 1 );
}
 
$wgExtensionCredits['interface'][] = array( 
    'name' => 'ProxyPage', 
    'author' => 'Cedric Chantepie', 
    'description' => 'Page that display content from proxified HTTP url',
);
 
$wgHooks['OutputPageBeforeHTML'][] = 'displayHttpContent';
 
/**
 * Add head element for ProxyPage integration
 */
function displayHttpContent(&$out, &$text) {
  global $wgArticle, $wgTitle;
  $content = NULL;
  $pos = FALSE;
 
  if (!isset($wgTitle) || !$wgTitle->exists() ||
      !isset($wgArticle) || 
      ($content = $wgArticle->getContent()) == NULL ||
      ($pos = strpos($content, "<!-- ProxyURL:")) === FALSE) {
 
    return true;
  }
 
  // ---
 
  $href = NULL;
  $pos += 14;
  $end = strpos($content, '-->', $pos);
 
  if ($end == 0) {
    return true;
  }
 
  $href = trim( substr($content, $pos, $end-$pos) );
 
  if (strpos($href, 'http://') === FALSE) {
    $t = Title::newFromText($href);
    $href = $t->escapeFullURL();
 
    if (strpos($href, '?') === FALSE) {
      $href .= "?proxy=" . urlencode( $wgTitle->getFullText() );
    } else {
      $href .= "&proxy=" . urlencode( $wgTitle->getFullText() );
    }
  }
 
  $out->disable();
 
  echo file_get_contents($href);
 
  return true;
}
?>
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox