<?php
-/*
+/**
* Created on Oct 13, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiFeedWatchlist extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
/**
* Wrap the result as an RSS/Atom feed.
*/
public function execute() {
-
global $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgContLanguageCode;
try {
$dbr = wfGetDB( DB_SLAVE );
// Prepare parameters for nested request
- $fauxReqArr = array (
+ $fauxReqArr = array(
'action' => 'query',
'meta' => 'siteinfo',
'siprop' => 'general',
'list' => 'watchlist',
'wlprop' => 'title|user|comment|timestamp',
- 'wldir' => 'older', // reverse order - from newest to oldest
+ 'wldir' => 'older', // reverse order - from newest to oldest
'wlend' => $dbr->timestamp( $endTime ), // stop at this time
'wllimit' => ( 50 > $wgFeedLimit ) ? $wgFeedLimit : 50
);
}
// Check for 'allrev' parameter, and if found, show all revisions to each page on wl.
- if ( !is_null ( $params['allrev'] ) ) {
+ if ( !is_null( $params['allrev'] ) ) {
$fauxReqArr['wlallrev'] = '';
}
// Create the request
- $fauxReq = new FauxRequest ( $fauxReqArr );
+ $fauxReq = new FauxRequest( $fauxReqArr );
// Execute
$module = new ApiMain( $fauxReq );
}
$feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgContLanguageCode . ']';
- $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullUrl();
+ $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL();
$feed = new $wgFeedClasses[$params['feedformat']] ( $feedTitle, htmlspecialchars( wfMsgForContent( 'watchlist' ) ), $feedUrl );
- ApiFormatFeedWrapper :: setResult( $this->getResult(), $feed, $feedItems );
+ ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems );
} catch ( Exception $e ) {
$this->getMain()->setCacheMaxAge( 0 );
$feedTitle = $wgSitename . ' - Error - ' . wfMsgForContent( 'watchlist' ) . ' [' . $wgContLanguageCode . ']';
- $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullUrl();
+ $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL();
$feedFormat = isset( $params['feedformat'] ) ? $params['feedformat'] : 'rss';
$feed = new $wgFeedClasses[$feedFormat] ( $feedTitle, htmlspecialchars( wfMsgForContent( 'watchlist' ) ), $feedUrl );
}
$errorText = $e->getMessage();
- $feedItems[] = new FeedItem( "Error ($errorCode)", $errorText, "", "", "" );
- ApiFormatFeedWrapper :: setResult( $this->getResult(), $feed, $feedItems );
+ $feedItems[] = new FeedItem( "Error ($errorCode)", $errorText, '', '', '' );
+ ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems );
}
}
private function createFeedItem( $info ) {
$titleStr = $info['title'];
- $title = Title :: newFromText( $titleStr );
- $titleUrl = $title->getFullUrl();
+ $title = Title::newFromText( $titleStr );
+ $titleUrl = $title->getFullURL();
$comment = isset( $info['comment'] ) ? $info['comment'] : null;
$timestamp = $info['timestamp'];
$user = $info['user'];
global $wgFeedClasses;
$feedFormatNames = array_keys( $wgFeedClasses );
return array (
- 'feedformat' => array (
- ApiBase :: PARAM_DFLT => 'rss',
- ApiBase :: PARAM_TYPE => $feedFormatNames
+ 'feedformat' => array(
+ ApiBase::PARAM_DFLT => 'rss',
+ ApiBase::PARAM_TYPE => $feedFormatNames
),
- 'hours' => array (
- ApiBase :: PARAM_DFLT => 24,
- ApiBase :: PARAM_TYPE => 'integer',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => 72,
+ 'hours' => array(
+ ApiBase::PARAM_DFLT => 24,
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => 72,
),
'allrev' => null,
- 'wlowner' => array (
- ApiBase :: PARAM_TYPE => 'user'
+ 'wlowner' => array(
+ ApiBase::PARAM_TYPE => 'user'
),
- 'wltoken' => array (
- ApiBase :: PARAM_TYPE => 'string'
+ 'wltoken' => array(
+ ApiBase::PARAM_TYPE => 'string'
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'feedformat' => 'The format of the feed',
'hours' => 'List pages modified within this many hours from now',
'allrev' => 'Include multiple revisions of the same page within given timeframe.',
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=feedwatchlist'
);
}
<?php
-/*
+/**
* Created on Sep 19, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
* @param $format string Format name
*/
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
$this->mIsHtml = ( substr( $format, - 2, 2 ) === 'fm' ); // ends with 'fm'
- if ( $this->mIsHtml )
+ if ( $this->mIsHtml ) {
$this->mFormat = substr( $format, 0, - 2 ); // remove ending 'fm'
- else
+ } else {
$this->mFormat = $format;
+ }
$this->mFormat = strtoupper( $this->mFormat );
$this->mCleared = false;
}
// Some printers (ex. Feed) do their own header settings,
// in which case $mime will be set to null
- if ( is_null( $mime ) )
+ if ( is_null( $mime ) ) {
return; // skip any initialization
+ }
header( "Content-Type: $mime; charset=utf-8" );
// For non-HTML output, clear all errors that might have been
// displayed if display_errors=On
// Do this only once, of course
- if ( !$this->mCleared )
- {
+ if ( !$this->mCleared ) {
ob_clean();
$this->mCleared = true;
}
}
/**
- * Prety-print various elements in HTML format, such as xml tags and
- * URLs. This method also escapes characters like <
- * @param $text string
- * @return string
- */
+ * Pretty-print various elements in HTML format, such as xml tags and
+ * URLs. This method also escapes characters like <
+ * @param $text string
+ * @return string
+ */
protected function formatHTML( $text ) {
global $wgUrlProtocols;
$text = preg_replace( "#\\$[^<>\n]+\\$#", '<b><i>\\0</i></b>', $text );
}
- /* Temporary fix for bad links in help messages. As a special case,
+ /**
+ * Temporary fix for bad links in help messages. As a special case,
* XML-escaped metachars are de-escaped one level in the help message
- * for legibility. Should be removed once we have completed a fully-html
- * version of the help message. */
- if ( $this->mUnescapeAmps )
+ * for legibility. Should be removed once we have completed a fully-HTML
+ * version of the help message.
+ */
+ if ( $this->mUnescapeAmps ) {
$text = preg_replace( '/&(amp|quot|lt|gt);/', '&\1;', $text );
+ }
return $text;
}
class ApiFormatFeedWrapper extends ApiFormatBase {
public function __construct( $main ) {
- parent :: __construct( $main, 'feed' );
+ parent::__construct( $main, 'feed' );
}
/**
*/
public function execute() {
$data = $this->getResultData();
- if ( isset ( $data['_feed'] ) && isset ( $data['_feeditems'] ) ) {
+ if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
$feed = $data['_feed'];
$items = $data['_feeditems'];
$feed->outHeader();
- foreach ( $items as & $item )
+ foreach ( $items as & $item ) {
$feed->outItem( $item );
+ }
$feed->outFooter();
} else {
// Error has occured, print something useful
<?php
-/*
+/**
* Created on Oct 22, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
class ApiFormatDbg extends ApiFormatBase {
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
}
public function getMimeType() {
}
public function getDescription() {
- return 'Output data in PHP\'s var_export() format' . parent :: getDescription();
+ return 'Output data in PHP\'s var_export() format' . parent::getDescription();
}
public function getVersion() {
<?php
-/*
+/**
* Created on Sep 19, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
private $mIsRaw;
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
$this->mIsRaw = ( $format === 'rawfm' );
}
}
public function execute() {
- $prefix = $suffix = "";
+ $prefix = $suffix = '';
$params = $this->extractRequestParams();
$callback = $params['callback'];
if ( !is_null( $callback ) ) {
- $prefix = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "(";
- $suffix = ")";
+ $prefix = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback ) . '(';
+ $suffix = ')';
}
$this->printText(
$prefix .
FormatJson::encode( $this->getResultData(), $this->getIsHtml() ) .
- $suffix );
+ $suffix
+ );
}
public function getAllowedParams() {
- return array (
+ return array(
'callback' => null,
);
}
public function getParamDescription() {
- return array (
+ return array(
'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
);
}
public function getDescription() {
- if ( $this->mIsRaw )
- return 'Output data with the debuging elements in JSON format' . parent :: getDescription();
- else
- return 'Output data in JSON format' . parent :: getDescription();
+ if ( $this->mIsRaw ) {
+ return 'Output data with the debuging elements in JSON format' . parent::getDescription();
+ } else {
+ return 'Output data in JSON format' . parent::getDescription();
+ }
}
public function getVersion() {
<?php
-/*
+/**
* Created on Oct 22, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
class ApiFormatPhp extends ApiFormatBase {
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
}
public function getMimeType() {
}
public function getDescription() {
- return 'Output data in serialized PHP format' . parent :: getDescription();
+ return 'Output data in serialized PHP format' . parent::getDescription();
}
public function getVersion() {
<?php
-/*
+/**
* Created on Feb 2, 2009
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
* @param $errorFallback Formatter object to fall back on for errors
*/
public function __construct( $main, $errorFallback ) {
- parent :: __construct( $main, 'raw' );
+ parent::__construct( $main, 'raw' );
$this->mErrorFallback = $errorFallback;
}
public function getMimeType() {
$data = $this->getResultData();
- if ( isset( $data['error'] ) )
+ if ( isset( $data['error'] ) ) {
return $this->mErrorFallback->getMimeType();
+ }
+
+ if ( !isset( $data['mime'] ) ) {
+ ApiBase::dieDebug( __METHOD__, 'No MIME type set for raw formatter' );
+ }
- if ( !isset( $data['mime'] ) )
- ApiBase::dieDebug( __METHOD__, "No MIME type set for raw formatter" );
-
return $data['mime'];
}
public function execute() {
$data = $this->getResultData();
- if ( isset( $data['error'] ) )
- {
+ if ( isset( $data['error'] ) ) {
$this->mErrorFallback->execute();
return;
}
-
- if ( !isset( $data['text'] ) )
- ApiBase::dieDebug( __METHOD__, "No text given for raw formatter" );
+
+ if ( !isset( $data['text'] ) ) {
+ ApiBase::dieDebug( __METHOD__, 'No text given for raw formatter' );
+ }
$this->printText( $data['text'] );
}
<?php
-/*
+/**
* Created on Oct 22, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
class ApiFormatTxt extends ApiFormatBase {
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
}
public function getMimeType() {
}
public function getDescription() {
- return 'Output data in PHP\'s print_r() format' . parent :: getDescription();
+ return 'Output data in PHP\'s print_r() format' . parent::getDescription();
}
public function getVersion() {
<?php
-/*
+/**
* Created on Oct 22, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
class ApiFormatWddx extends ApiFormatBase {
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
}
public function getMimeType() {
} else {
// Don't do newlines and indentation if we weren't asked
// for pretty output
- $nl = ( $this->getIsHtml() ? "" : "\n" );
- $indstr = " ";
+ $nl = ( $this->getIsHtml() ? '' : "\n" );
+ $indstr = ' ';
$this->printText( "<?xml version=\"1.0\"?>$nl" );
$this->printText( "<wddxPacket version=\"1.0\">$nl" );
$this->printText( "$indstr<header/>$nl" );
* Recursively go through the object and output its data in WDDX format.
*/
function slowWddxPrinter( $elemValue, $indent = 0 ) {
- $indstr = ( $this->getIsHtml() ? "" : str_repeat( ' ', $indent ) );
- $indstr2 = ( $this->getIsHtml() ? "" : str_repeat( ' ', $indent + 2 ) );
- $nl = ( $this->getIsHtml() ? "" : "\n" );
+ $indstr = ( $this->getIsHtml() ? '' : str_repeat( ' ', $indent ) );
+ $indstr2 = ( $this->getIsHtml() ? '' : str_repeat( ' ', $indent + 2 ) );
+ $nl = ( $this->getIsHtml() ? '' : "\n" );
switch ( gettype( $elemValue ) ) {
- case 'array' :
+ case 'array':
// Check whether we've got an associative array (<struct>)
// or a regular array (<array>)
$cnt = count( $elemValue );
// Regular array
$this->printText( $indstr . Xml::element( 'array', array(
'length' => $cnt ), null ) . $nl );
- foreach ( $elemValue as $subElemValue )
+ foreach ( $elemValue as $subElemValue ) {
$this->slowWddxPrinter( $subElemValue, $indent + 2 );
+ }
$this->printText( "$indstr</array>$nl" );
} else {
// Associative array (<struct>)
$this->printText( "$indstr</struct>$nl" );
}
break;
- case 'integer' :
- case 'double' :
+ case 'integer':
+ case 'double':
$this->printText( $indstr . Xml::element( 'number', null, $elemValue ) . $nl );
break;
- case 'string' :
+ case 'string':
$this->printText( $indstr . Xml::element( 'string', null, $elemValue ) . $nl );
break;
- default :
- ApiBase :: dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) );
+ default:
+ ApiBase::dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) );
}
}
public function getDescription() {
- return 'Output data in WDDX format' . parent :: getDescription();
+ return 'Output data in WDDX format' . parent::getDescription();
}
public function getVersion() {