Skip to content

Commit

Permalink
Merge pull request #73 from MW-Peachy/master
Browse files Browse the repository at this point in the history
Merge to stable
  • Loading branch information
cyberpower678 committed Jun 15, 2014
2 parents 2908db4 + d02c536 commit 4e38126
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 1,668 deletions.
20 changes: 10 additions & 10 deletions GenFunctions.php
Expand Up @@ -107,11 +107,11 @@ function rglob( $pattern = '*', $flags = 0, $path = '' ) {
* @access public * @access public
* @param Wiki $wiki Wiki class * @param Wiki $wiki Wiki class
* @param string $text Text of the page to check (default: '') * @param string $text Text of the page to check (default: '')
* @param string $username Username to search for in the template (default: null) * @param string $pgUsername Username to search for in the template (default: null)
* @param string $optout Text to search for in the optout= parameter. (default: null) * @param string $optout Text to search for in the optout= parameter. (default: null)
* @return bool True on match of an appropriate nobots template * @return bool True on match of an appropriate nobots template
*/ */
function checkExclusion( Wiki $wiki, $text = '', $username = null, $optout = null ) { function checkExclusion( Wiki $wiki, $text = '', $pgUsername = null, $optout = null ) {
if( !$wiki->get_nobots() ) return false; if( !$wiki->get_nobots() ) return false;


if( in_string( "{{nobots}}", $text ) ) return true; if( in_string( "{{nobots}}", $text ) ) return true;
Expand All @@ -121,7 +121,7 @@ function checkExclusion( Wiki $wiki, $text = '', $username = null, $optout = nul
if( $allow[1] == "all" ) return false; if( $allow[1] == "all" ) return false;
if( $allow[1] == "none" ) return true; if( $allow[1] == "none" ) return true;
$allow = array_map( 'trim', explode( ',', $allow[1] ) ); $allow = array_map( 'trim', explode( ',', $allow[1] ) );
if( !is_null( $username ) && in_array( trim( $username ), $allow ) ) { if( !is_null( $pgUsername ) && in_array( trim( $pgUsername ), $allow ) ) {
return false; return false;
} }
return true; return true;
Expand All @@ -131,7 +131,7 @@ function checkExclusion( Wiki $wiki, $text = '', $username = null, $optout = nul
if( $deny[2] == "all" ) return true; if( $deny[2] == "all" ) return true;
if( $deny[2] == "none" ) return false; if( $deny[2] == "none" ) return false;
$allow = array_map( 'trim', explode( ',', $deny[2] ) ); $allow = array_map( 'trim', explode( ',', $deny[2] ) );
if( !is_null( $username ) && in_array( trim( $username ), $allow ) ) { if( !is_null( $pgUsername ) && in_array( trim( $pgUsername ), $allow ) ) {
return true; return true;
} }
return false; return false;
Expand Down Expand Up @@ -180,8 +180,8 @@ function outputText( $text, $cat = 0, $func = 'echo' ) {
* @return void * @return void
*/ */
function pecho( $text, $cat = 0, $func = 'echo' ) { function pecho( $text, $cat = 0, $func = 'echo' ) {
global $webOutput; global $pgWebOutput;
if( $webOutput ) $text = str_replace( "\n", "<br>", $text ); if( $pgWebOutput ) $text = str_replace( "\n", "<br>", $text );
outputText( $text, $cat, $func ); outputText( $text, $cat, $func );
} }


Expand Down Expand Up @@ -287,17 +287,17 @@ function &initPage( $title = null, $pageid = null, $followRedir = true, $normali
} }


/** /**
* Returns an instance of the User class as specified by $username * Returns an instance of the User class as specified by $pgUsername
* *
* @param mixed $username Username * @param mixed $pgUsername Username
* @return User * @return User
* @package initFunctions * @package initFunctions
*/ */
function &initUser( $username ) { function &initUser( $pgUsername ) {
$wiki = getSiteObject(); $wiki = getSiteObject();
if( !$wiki ) return false; if( !$wiki ) return false;


$user = new User( $wiki, $username ); $user = new User( $wiki, $pgUsername );
return $user; return $user;
} }


Expand Down
16 changes: 8 additions & 8 deletions Includes/AutoUpdate.php
Expand Up @@ -31,10 +31,10 @@
protected $commits; protected $commits;


function __construct( $http ) { function __construct( $http ) {
global $pgIP, $experimentalupdates; global $pgIP, $pgExperimentalupdates;
$this->http = $http; $this->http = $http;
$this->repository = ( $experimentalupdates ? 'master' : 'stable' ); $this->repository = ( $pgExperimentalupdates ? 'master' : 'stable' );
$this->logfile = ( $experimentalupdates ? 'Update.log' : 'StableUpdate.log' ); $this->logfile = ( $pgExperimentalupdates ? 'Update.log' : 'StableUpdate.log' );
$this->lastused = ( file_exists( $pgIP . 'Includes/updateversion' ) ? unserialize( file_get_contents( $pgIP . 'Includes/updateversion' ) ) : 'Unknown' ); $this->lastused = ( file_exists( $pgIP . 'Includes/updateversion' ) ? unserialize( file_get_contents( $pgIP . 'Includes/updateversion' ) ) : 'Unknown' );
} }


Expand All @@ -45,9 +45,9 @@ function __construct( $http ) {
* @return bool * @return bool
*/ */
public function Checkforupdate() { public function Checkforupdate() {
global $pgIP, $experimentalupdates; global $pgIP, $pgExperimentalupdates;
pecho( "Checking for updates...\n\n", PECHO_NORMAL ); pecho( "Checking for updates...\n\n", PECHO_NORMAL );
if( $experimentalupdates ) pecho( "Warning: You have experimental updates switched on.\nExperimental updates are not fully tested and can cause problems,\nsuch as, bot misbehaviors up to complete crashes.\nUse at your own risk.\nPeachy will not revert back to a stable release until switched off.\n\n", PECHO_NOTICE ); if( $pgExperimentalupdates ) pecho( "Warning: You have experimental updates switched on.\nExperimental updates are not fully tested and can cause problems,\nsuch as, bot misbehaviors up to complete crashes.\nUse at your own risk.\nPeachy will not revert back to a stable release until switched off.\n\n", PECHO_NOTICE );
$data = json_decode( $this->http->get( 'https://api.github.com/repos/MW-Peachy/Peachy/branches/' . $this->repository, null, array(), false ), true ); $data = json_decode( $this->http->get( 'https://api.github.com/repos/MW-Peachy/Peachy/branches/' . $this->repository, null, array(), false ), true );
$this->commits = $data; $this->commits = $data;
/*if( strstr( $this->http->getLastHeader(), 'Status: 304 Not Modified') ) { /*if( strstr( $this->http->getLastHeader(), 'Status: 304 Not Modified') ) {
Expand All @@ -60,7 +60,7 @@ public function Checkforupdate() {
} }
$this->cacheLastGithubETag(); $this->cacheLastGithubETag();
if( $this->lastused !== $this->repository ) { if( $this->lastused !== $this->repository ) {
pecho( "Changing Peachy version to run using " . ( $experimentalupdates ? "experimental" : "stable" ) . " updates.\n\n", PECHO_NOTICE ); pecho( "Changing Peachy version to run using " . ( $pgExperimentalupdates ? "experimental" : "stable" ) . " updates.\n\n", PECHO_NOTICE );
return false; return false;
} }
if( file_exists( $pgIP . 'Includes' . DIRECTORY_SEPARATOR . $this->logfile ) ) { if( file_exists( $pgIP . 'Includes' . DIRECTORY_SEPARATOR . $this->logfile ) ) {
Expand Down Expand Up @@ -112,7 +112,7 @@ private function getLocalPath( $fullUpdatePath ) {
* @return boolean|null * @return boolean|null
*/ */
public function updatePeachy() { public function updatePeachy() {
global $pgIP, $experimentalupdates; global $pgIP, $pgExperimentalupdates;
$gitZip = $pgIP . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'gitUpdate.zip'; $gitZip = $pgIP . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'gitUpdate.zip';
if( file_exists( $gitZip ) ) { if( file_exists( $gitZip ) ) {
unlink( $gitZip ); unlink( $gitZip );
Expand All @@ -131,7 +131,7 @@ public function updatePeachy() {


$this->copyOverGitFiles( $gitFolder . DIRECTORY_SEPARATOR . 'Peachy-' . $this->repository ); $this->copyOverGitFiles( $gitFolder . DIRECTORY_SEPARATOR . 'Peachy-' . $this->repository );


file_put_contents( $pgIP . 'Includes' . DIRECTORY_SEPARATOR . 'updateversion', serialize( ( $experimentalupdates ? 'master' : 'stable' ) ) ); file_put_contents( $pgIP . 'Includes' . DIRECTORY_SEPARATOR . 'updateversion', serialize( ( $pgExperimentalupdates ? 'master' : 'stable' ) ) );


pecho( "Peachy Updated! Changes will go into effect on the next run.\n\n", PECHO_NOTICE ); pecho( "Peachy Updated! Changes will go into effect on the next run.\n\n", PECHO_NOTICE );


Expand Down
1 change: 1 addition & 0 deletions Includes/Autoloader.php
Expand Up @@ -5,6 +5,7 @@
'User' => 'Includes/User.php', 'User' => 'Includes/User.php',
'Page' => 'Includes/Page.php', 'Page' => 'Includes/Page.php',
'Image' => 'Includes/Image.php', 'Image' => 'Includes/Image.php',
'XMLParse' => 'Includes/XMLParse.php',
'Script' => 'Script.php', 'Script' => 'Script.php',
'UtfNormal' => 'Plugins/normalize/UtfNormal.php', 'UtfNormal' => 'Plugins/normalize/UtfNormal.php',


Expand Down
18 changes: 16 additions & 2 deletions Includes/Exceptions.php
Expand Up @@ -36,6 +36,20 @@ public function __construct( $code, $text ) {
} }
} }


/**
* Assertation error bot
*
* @package Exceptions
*/
class AssertFailure extends Exception {

public function __contstruct( $type ) {
parent::__construct(
"Assert Failure: ".( $type == "bot" ? "Bot is no longer flagged as a bot" : "User is logged out" )
);
}
}

/** /**
* Generic API Error * Generic API Error
* *
Expand Down Expand Up @@ -154,9 +168,9 @@ public function __construct( $title ) {
*/ */
class UserBlocked extends Exception { class UserBlocked extends Exception {


public function __construct( $username = "User" ) { public function __construct( $pgUsername = "User" ) {
parent::__construct( parent::__construct(
$username . " is currently blocked." $pgUsername . " is currently blocked."
); );


} }
Expand Down
15 changes: 5 additions & 10 deletions Includes/Page.php
Expand Up @@ -249,8 +249,8 @@ public function __construct( Wiki $wikiClass, $title = null, $pageid = null, $fo
if( !is_string( $title ) && !is_null( $title ) ) { if( !is_string( $title ) && !is_null( $title ) ) {
throw new InvalidArgumentException( '$title must be a string or null' ); throw new InvalidArgumentException( '$title must be a string or null' );
} }
if( !is_int( $pageid ) && !is_null( $pageid ) ) { if( !is_int( $pageid ) && !is_null( $pageid ) && !is_string( $pageid ) ) {
throw new InvalidArgumentException( '$pageid must be a int or null' ); throw new InvalidArgumentException( '$pageid must be a int, string, or null' );
} }
if( !is_bool( $followRedir ) ) { if( !is_bool( $followRedir ) ) {
throw new InvalidArgumentException( '$followRedir must be a bool' ); throw new InvalidArgumentException( '$followRedir must be a bool' );
Expand Down Expand Up @@ -1156,10 +1156,7 @@ public function edit(


if( !$notag ) $summary .= $tag; if( !$notag ) $summary .= $tag;


if( $tokens['edit'] == '+\\' ) { if( $tokens['edit'] == '' ) {
pecho( "User has logged out.\n\n", PECHO_FATAL );
return false;
} elseif( $tokens['edit'] == '' ) {
pecho( "User is not allowed to edit {$this->title}\n\n", PECHO_FATAL ); pecho( "User is not allowed to edit {$this->title}\n\n", PECHO_FATAL );
return false; return false;
} }
Expand All @@ -1177,8 +1174,7 @@ public function edit(
'token' => $tokens['edit'], 'token' => $tokens['edit'],
'basetimestamp' => $this->lastedit, 'basetimestamp' => $this->lastedit,
'md5' => md5( $text ), 'md5' => md5( $text ),
'text' => $text, 'text' => $text
'assert' => 'user',
); );
if( !is_null( $this->starttimestamp ) ) $editarray['starttimestamp'] = $this->starttimestamp; if( !is_null( $this->starttimestamp ) ) $editarray['starttimestamp'] = $this->starttimestamp;
if( !is_null( $section ) ) { if( !is_null( $section ) ) {
Expand Down Expand Up @@ -1349,8 +1345,7 @@ public function undo( $summary = null, $revisions = 1, $force = false, $watch =
'token' => $tokens['edit'], 'token' => $tokens['edit'],
'basetimestamp' => $this->lastedit, 'basetimestamp' => $this->lastedit,
'undo' => $oldrev, 'undo' => $oldrev,
'undoafter' => $newrev, 'undoafter' => $newrev
'assert' => 'user',
); );
if( !is_null( $this->starttimestamp ) ) $params['starttimestamp'] = $this->starttimestamp; if( !is_null( $this->starttimestamp ) ) $params['starttimestamp'] = $this->starttimestamp;
if( !is_null( $summary ) ) { if( !is_null( $summary ) ) {
Expand Down
8 changes: 4 additions & 4 deletions Includes/Peachy.php
Expand Up @@ -12,15 +12,15 @@ class Peachy {
* @access public * @access public
* *
* @param string $config_name Name of the config file stored in the Configs directory, minus the .cfg extension. Default null * @param string $config_name Name of the config file stored in the Configs directory, minus the .cfg extension. Default null
* @param string $username Username to log in if no config file specified. Default null * @param string $pgUsername Username to log in if no config file specified. Default null
* @param string $password Password to log in with if no config file specified. Default null * @param string $password Password to log in with if no config file specified. Default null
* @param string $base_url URL to api.php if no config file specified. Defaults to English Wikipedia's API. * @param string $base_url URL to api.php if no config file specified. Defaults to English Wikipedia's API.
* @param string $classname * @param string $classname
* *
* @throws LoginError * @throws LoginError
* @return Wiki Instance of the Wiki class, where most functions are stored * @return Wiki Instance of the Wiki class, where most functions are stored
*/ */
public static function newWiki( $config_name = null, $username = null, $password = null, $base_url = 'http://en.wikipedia.org/w/api.php', $classname = 'Wiki' ) { public static function newWiki( $config_name = null, $pgUsername = null, $password = null, $base_url = 'http://en.wikipedia.org/w/api.php', $classname = 'Wiki' ) {
pecho( "Loading Peachy (version " . PEACHYVERSION . ")...\n\n", PECHO_NORMAL ); pecho( "Loading Peachy (version " . PEACHYVERSION . ")...\n\n", PECHO_NORMAL );
/*$updater = new AutoUpdate(); /*$updater = new AutoUpdate();
$Uptodate = $updater->Checkforupdate(); $Uptodate = $updater->Checkforupdate();
Expand All @@ -31,7 +31,7 @@ public static function newWiki( $config_name = null, $username = null, $password


} else { } else {
$config_params = array( $config_params = array(
'username' => $username, 'username' => $pgUsername,
'password' => $password, 'password' => $password,
'baseurl' => $base_url 'baseurl' => $base_url
); );
Expand All @@ -46,7 +46,7 @@ public static function newWiki( $config_name = null, $username = null, $password
$config_params['nologin'] = true; $config_params['nologin'] = true;
} }


list( $version, $extensions ) = Peachy::wikiChecks( $config_params['baseurl'] ); list( $version, $extensions ) = self::wikiChecks( $config_params['baseurl'] );


Hooks::runHook( 'StartLogin', array( &$config_params, &$extensions ) ); Hooks::runHook( 'StartLogin', array( &$config_params, &$extensions ) );


Expand Down

0 comments on commit 4e38126

Please sign in to comment.