Extract

From Wikitech
Jump to: navigation, search

A sample of a script that reads stuff. (Third party users might want to trim this down, as it's more complicated than necessary for a simple page extraction.)

<?php
header("Content-Type: text/html; charset=utf-8");
$lang = "meta";
define( "MEDIAWIKI", true );
#include_once("CommonSettings.php");
include_once("/apache/common/php-1.4/includes/Defines.php" );
include_once("/apache/common/php-1.4/CommonSettings.php");
include_once("Setup.php");

$allowed_portals = array(
        "Www.wikipedia.org_portal",
        "Www.wikinews.org_portal",
        "Www.wiktionary.org_portal",
        "Www.wikinews.org_portal",
        "Www.wikiquote.org_portal",
);
$allowed_templates = array(
        "Www.wikipedia.org_template",
        "Www.wikinews.org_template",
        "Www.wiktionary.org_template",
        "Www.wikinews.org_template",
        "Www.wikiquote.org_template",
);

$useportal = $wgRequest->getText( 'title', 'Www.wikipedia.org_portal' );
$usetemplate = $wgRequest->getText( 'template', 'Www.wikipedia.org_template' );
if (!in_array($useportal, $allowed_portals) || !in_array($usetemplate, $allowed_templates)) {
        header("Content-Type", "text/plain; charset=US-ASCII");
        echo "sorry...";
        exit;
}

$wgTitle = Title::newFromText( $useportal );
$wgArticle = new Article( $wgTitle );
$mainText = $wgOut->parse( $wgArticle->getContent( false ) );

$templateTitle = Title::newFromText( $usetemplate );
$templateArticle = new Article( $templateTitle );
$templateText = $templateArticle->getContent( false ); 
$text = str_replace( '$1', $mainText, $templateText );

$lastmod = gmdate( 'D, j M Y H:i:s', wfTimestamp(TS_UNIX, max( $wgArticle->mTouched, $templateArticle->mTouched ) ) ) . ' GMT';
header( 'Cache-Control: s-maxage=3600, must-revalidate, max-age=0' );
header( "Last-modified: $lastmod" );

echo $text;
?>
Personal tools
Namespaces

Variants
Actions
Navigation
Ops documentation
Wiki
Toolbox