Permalink
Browse files

Merge pull request #73 from MW-Peachy/master

Merge to stable
  • Loading branch information...
cyberpower678 committed Jun 15, 2014
2 parents 2908db4 + d02c536 commit 4e3812696b5245b9896ae660e67876f21cbb201f
@@ -107,11 +107,11 @@ function rglob( $pattern = '*', $flags = 0, $path = '' ) {
* @access public
* @param Wiki $wiki Wiki class
* @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)
* @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( in_string( "{{nobots}}", $text ) ) return true;
@@ -121,7 +121,7 @@ function checkExclusion( Wiki $wiki, $text = '', $username = null, $optout = nul
if( $allow[1] == "all" ) return false;
if( $allow[1] == "none" ) return true;
$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 true;
@@ -131,7 +131,7 @@ function checkExclusion( Wiki $wiki, $text = '', $username = null, $optout = nul
if( $deny[2] == "all" ) return true;
if( $deny[2] == "none" ) return false;
$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 false;
@@ -180,8 +180,8 @@ function outputText( $text, $cat = 0, $func = 'echo' ) {
* @return void
*/
function pecho( $text, $cat = 0, $func = 'echo' ) {
global $webOutput;
if( $webOutput ) $text = str_replace( "\n", "<br>", $text );
global $pgWebOutput;
if( $pgWebOutput ) $text = str_replace( "\n", "<br>", $text );
outputText( $text, $cat, $func );
}
@@ -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
* @package initFunctions
*/
function &initUser( $username ) {
function &initUser( $pgUsername ) {
$wiki = getSiteObject();
if( !$wiki ) return false;
$user = new User( $wiki, $username );
$user = new User( $wiki, $pgUsername );
return $user;
}
@@ -31,10 +31,10 @@
protected $commits;
function __construct( $http ) {
global $pgIP, $experimentalupdates;
global $pgIP, $pgExperimentalupdates;
$this->http = $http;
$this->repository = ( $experimentalupdates ? 'master' : 'stable' );
$this->logfile = ( $experimentalupdates ? 'Update.log' : 'StableUpdate.log' );
$this->repository = ( $pgExperimentalupdates ? 'master' : 'stable' );
$this->logfile = ( $pgExperimentalupdates ? 'Update.log' : 'StableUpdate.log' );
$this->lastused = ( file_exists( $pgIP . 'Includes/updateversion' ) ? unserialize( file_get_contents( $pgIP . 'Includes/updateversion' ) ) : 'Unknown' );
}
@@ -45,9 +45,9 @@ function __construct( $http ) {
* @return bool
*/
public function Checkforupdate() {
global $pgIP, $experimentalupdates;
global $pgIP, $pgExperimentalupdates;
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 );
$this->commits = $data;
/*if( strstr( $this->http->getLastHeader(), 'Status: 304 Not Modified') ) {
@@ -60,7 +60,7 @@ public function Checkforupdate() {
}
$this->cacheLastGithubETag();
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;
}
if( file_exists( $pgIP . 'Includes' . DIRECTORY_SEPARATOR . $this->logfile ) ) {
@@ -112,7 +112,7 @@ private function getLocalPath( $fullUpdatePath ) {
* @return boolean|null
*/
public function updatePeachy() {
global $pgIP, $experimentalupdates;
global $pgIP, $pgExperimentalupdates;
$gitZip = $pgIP . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'gitUpdate.zip';
if( file_exists( $gitZip ) ) {
unlink( $gitZip );
@@ -131,7 +131,7 @@ public function updatePeachy() {
$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 );
@@ -5,6 +5,7 @@
'User' => 'Includes/User.php',
'Page' => 'Includes/Page.php',
'Image' => 'Includes/Image.php',
'XMLParse' => 'Includes/XMLParse.php',
'Script' => 'Script.php',
'UtfNormal' => 'Plugins/normalize/UtfNormal.php',
@@ -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
*
@@ -154,9 +168,9 @@ public function __construct( $title ) {
*/
class UserBlocked extends Exception {
public function __construct( $username = "User" ) {
public function __construct( $pgUsername = "User" ) {
parent::__construct(
$username . " is currently blocked."
$pgUsername . " is currently blocked."
);
}
@@ -249,8 +249,8 @@ public function __construct( Wiki $wikiClass, $title = null, $pageid = null, $fo
if( !is_string( $title ) && !is_null( $title ) ) {
throw new InvalidArgumentException( '$title must be a string or null' );
}
if( !is_int( $pageid ) && !is_null( $pageid ) ) {
throw new InvalidArgumentException( '$pageid must be a int or null' );
if( !is_int( $pageid ) && !is_null( $pageid ) && !is_string( $pageid ) ) {
throw new InvalidArgumentException( '$pageid must be a int, string, or null' );
}
if( !is_bool( $followRedir ) ) {
throw new InvalidArgumentException( '$followRedir must be a bool' );
@@ -1156,10 +1156,7 @@ public function edit(
if( !$notag ) $summary .= $tag;
if( $tokens['edit'] == '+\\' ) {
pecho( "User has logged out.\n\n", PECHO_FATAL );
return false;
} elseif( $tokens['edit'] == '' ) {
if( $tokens['edit'] == '' ) {
pecho( "User is not allowed to edit {$this->title}\n\n", PECHO_FATAL );
return false;
}
@@ -1177,8 +1174,7 @@ public function edit(
'token' => $tokens['edit'],
'basetimestamp' => $this->lastedit,
'md5' => md5( $text ),
'text' => $text,
'assert' => 'user',
'text' => $text
);
if( !is_null( $this->starttimestamp ) ) $editarray['starttimestamp'] = $this->starttimestamp;
if( !is_null( $section ) ) {
@@ -1349,8 +1345,7 @@ public function undo( $summary = null, $revisions = 1, $force = false, $watch =
'token' => $tokens['edit'],
'basetimestamp' => $this->lastedit,
'undo' => $oldrev,
'undoafter' => $newrev,
'assert' => 'user',
'undoafter' => $newrev
);
if( !is_null( $this->starttimestamp ) ) $params['starttimestamp'] = $this->starttimestamp;
if( !is_null( $summary ) ) {
@@ -12,15 +12,15 @@ class Peachy {
* @access public
*
* @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 $base_url URL to api.php if no config file specified. Defaults to English Wikipedia's API.
* @param string $classname
*
* @throws LoginError
* @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 );
/*$updater = new AutoUpdate();
$Uptodate = $updater->Checkforupdate();
@@ -31,7 +31,7 @@ public static function newWiki( $config_name = null, $username = null, $password
} else {
$config_params = array(
'username' => $username,
'username' => $pgUsername,
'password' => $password,
'baseurl' => $base_url
);
@@ -46,7 +46,7 @@ public static function newWiki( $config_name = null, $username = null, $password
$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 ) );
Oops, something went wrong.

0 comments on commit 4e38126

Please sign in to comment.