コード例 #1
0
ファイル: SiteMatrix.php プロジェクト: emijrp/Peachy
 /**
  * Loads list of all SiteMatrix wikis
  *
  * @static
  * @access public
  * @param  Wiki &$wikiClass The Wiki class object
  * @return array List of all wikis
  * @throws AssertFailure
  * @throws DependencyError
  * @throws LoggedOut
  * @throws MWAPIError
  */
 public static function load(Wiki &$wikiClass)
 {
     if (!array_key_exists('SiteMatrix', $wikiClass->get_extensions())) {
         throw new DependencyError("SiteMatrix");
     }
     $SMres = $wikiClass->apiQuery(array('action' => 'sitematrix'));
     $wikis = $SMres['sitematrix'];
     //return $wikis;
     $retarray = array('raw' => $wikis, 'urls' => array(), 'langs' => array(), 'names' => array(), 'privates' => array());
     foreach ($wikis as $site) {
         if (is_array($site)) {
             if (isset($site['site'])) {
                 $retarray['langs'][] = $site['code'];
                 $retarray['names'][$site['code']] = $site['name'];
                 foreach ($site['site'] as $site2) {
                     $retarray['urls'][] = $site2['url'];
                     if (isset($site2['private'])) {
                         $retarray['privates'][] = $site2;
                     }
                 }
             } else {
                 foreach ($site as $site2) {
                     $sites2['urls'][] = $site2['url'];
                     if (isset($site2['private'])) {
                         $retarray['privates'][] = $site2;
                     }
                 }
             }
         }
     }
     return $retarray;
 }
コード例 #2
0
ファイル: User.php プロジェクト: emijrp/Peachy
 public function userrights($add = array(), $remove = array(), $reason = '')
 {
     global $pgNotag, $pgTag;
     $tokens = $this->wiki->get_tokens();
     if (!$pgNotag) {
         $reason .= $pgTag;
     }
     $apiArr = array('action' => 'userrights', 'user' => $this->username, 'token' => $tokens['userrights'], 'add' => implode('|', $add), 'remove' => implode('|', $remove), 'reason' => $reason);
     Hooks::runHook('StartUserrights', array(&$apiArr));
     pecho("Assigning user rights to {$this->username}...\n\n", PECHO_NOTICE);
     try {
         $this->preEditChecks("Rights");
     } catch (EditError $e) {
         pecho("Error: {$e}\n\n", PECHO_FATAL);
         return false;
     }
     $result = $this->wiki->apiQuery($apiArr, true);
     if (isset($result['userrights'])) {
         if (isset($result['userrights']['user'])) {
             $this->__construct($this->wiki, $this->username);
             return true;
         } else {
             pecho("Userrights error...\n\n" . print_r($result['userrights'], true) . "\n\n", PECHO_FATAL);
             return false;
         }
     } else {
         pecho("Userrights error...\n\n" . print_r($result, true), PECHO_FATAL);
         return false;
     }
 }
コード例 #3
0
ファイル: GlobalUserInfo.php プロジェクト: emijrp/Peachy
 /**
  * Construction method for the GlobalUserInfo class
  *
  * @access public
  * @param Wiki &$wikiClass The Wiki class object
  * @param mixed $pgUsername Username
  * @throws APIError
  * @throws AssertFailure
  * @throws DependencyError
  * @throws LoggedOut
  * @throws MWAPIError
  */
 function __construct(Wiki &$wikiClass, $pgUsername)
 {
     if (!array_key_exists('Central Auth', $wikiClass->get_extensions())) {
         throw new DependencyError("CentralAuth", "http://www.mediawiki.org/wiki/Extension:CentralAuth");
     }
     $this->username = ucfirst($pgUsername);
     $this->wiki = $wikiClass;
     $guiRes = $this->wiki->apiQuery(array('action' => 'query', 'meta' => 'globaluserinfo', 'guiuser' => ucfirst($pgUsername), 'guiprop' => 'groups|merged|unattached'), false, false);
     if (!isset($guiRes['query']['globaluserinfo'])) {
         $this->exists = false;
         if (isset($guiRes['error']) && $guiRes['error']['code'] != 'guinosuchuser') {
             throw new MWAPIError($guiRes['error']);
         } elseif (@$guiRes['error']['code'] != 'guinosuchuser') {
             throw new MWAPIError(array('code' => 'UnknownError', 'info' => 'Unknown API Error'));
         }
     } else {
         $this->groups = $guiRes['query']['globaluserinfo']['groups'];
         $this->merged = $guiRes['query']['globaluserinfo']['merged'];
         $this->merged = $guiRes['query']['globaluserinfo']['unattached'];
         $this->id = $guiRes['query']['globaluserinfo']['id'];
         $this->registration = $guiRes['query']['globaluserinfo']['registration'];
     }
 }
コード例 #4
0
ファイル: RPED.php プロジェクト: emijrp/Peachy
 /**
  * Delete a page title from the rped_page table
  *
  * @static
  * @access public
  * @param string $page
  * @return void
  */
 public function delete($page)
 {
     $this->wiki->apiQuery(array('action' => 'rped', 'delete' => $page), true);
 }
コード例 #5
0
ファイル: Image.php プロジェクト: emijrp/Peachy
 /**
  * Upload an image to the wiki using api.php
  *
  * @access public
  * @param mixed $file Absolute path to the image, a URL, or an array containing file chunks for a chunk upload.
  * @param string $text Text on the image file page (default: '')
  * @param string $comment Comment for inthe upload in logs (default: '')
  * @param bool $watch Should the upload be added to the watchlist (default: false)
  * @param bool $ignorewarnings Ignore warnings about the upload (default: true)
  * @param bool $async Make potentially large file operations asynchronous when possible.  Default false.
  * @param string $filekey Key that identifies a previous upload that was stashed temporarily. Default null.
  * @notice This feature is not yet fully developed.  Manual stashing is not allowed at this time.  This will be corrected during the final release of Peachy 2.
  * @return bool
  */
 public function api_upload($file, $text = '', $comment = '', $watch = null, $ignorewarnings = true, $async = false, $filekey = null)
 {
     $tokens = $this->wiki->get_tokens();
     $apiArr = array('action' => 'upload', 'filename' => $this->rawtitle, 'comment' => $comment, 'text' => $text, 'token' => $tokens['edit'], 'ignorewarnings' => intval($ignorewarnings));
     if (!is_null($filekey)) {
         $apiArr['filekey'] = $filekey;
     }
     if (!is_null($watch)) {
         if ($watch) {
             $apiArr['watchlist'] = 'watch';
         } elseif (!$watch) {
             $apiArr['watchlist'] = 'nochange';
         } elseif (in_array($watch, array('watch', 'unwatch', 'preferences', 'nochange'))) {
             $apiArr['watchlist'] = $watch;
         } else {
             pecho("Watch parameter set incorrectly.  Omitting...\n\n", PECHO_WARN);
         }
     }
     if (!is_array($file)) {
         if (is_file($file)) {
             if ($async) {
                 $apiArr['async'] = 'yes';
             }
             $localfile = $file;
             $apiArr['file'] = "@{$localfile}";
         } else {
             $apiArr['url'] = $file;
             if ($async) {
                 $apiArr['asyncdownload'] = 'yes';
                 $apiArr['leavemessage'] = 'yes';
             }
         }
     } else {
         $apiArr['stash'] = 'yes';
         $apiArr['offset'] = 0;
         $apiArr['filesize'] = 0;
         foreach ($file as $chunk) {
             $apiArr['filesize'] = $apiArr['filesize'] + filesize($chunk);
         }
         foreach ($file as $chunk) {
             $apiArr['chunk'] = "@{$chunk}";
             pecho("Uploading {$chunk}\n\n", PECHO_NOTICE);
             $result = $this->wiki->apiQuery($apiArr, true);
             if (isset($result['upload']['result']) && $result['upload']['result'] == "Continue") {
                 $apiArr['filekey'] = $result['upload']['filekey'];
                 $apiArr['offset'] = $result['upload']['offset'];
             } elseif (isset($result['upload']['result']) && $result['upload']['result'] == "Success") {
                 $apiArr['filekey'] = $result['upload']['filekey'];
                 unset($apiArr['offset']);
                 unset($apiArr['chunk']);
                 unset($apiArr['stash']);
                 unset($apiArr['filesize']);
                 pecho("Chunks uploaded successfully!\n\n", PECHO_NORMAL);
                 break;
             } else {
                 pecho("Upload error...\n\n" . print_r($result, true) . "\n\n", PECHO_FATAL);
                 return false;
             }
         }
     }
     Hooks::runHook('APIUpload', array(&$apiArr));
     $result = $this->wiki->apiQuery($apiArr, true);
     if (isset($result['upload'])) {
         if (isset($result['upload']['result']) && $result['upload']['result'] == "Success") {
             $this->__construct($this->wiki, $this->title);
             return true;
         } else {
             pecho("Upload error...\n\n" . print_r($result['upload'], true) . "\n\n", PECHO_FATAL);
             return false;
         }
     } else {
         pecho("Upload error...\n\n" . print_r($result, true), PECHO_FATAL);
         return false;
     }
 }
コード例 #6
0
ファイル: Page.php プロジェクト: emijrp/Peachy
 public function rollback($force = false, $summary = null, $markbot = false, $watch = null)
 {
     global $pgNotag, $pgTag;
     if (!in_array('rollback', $this->wiki->get_userrights())) {
         pecho("User is not allowed to rollback edits", PECHO_FATAL);
         return false;
     }
     if (!$force) {
         try {
             $this->preEditChecks();
         } catch (EditError $e) {
             pecho("Error: {$e}\n\n", PECHO_FATAL);
             return false;
         }
     }
     $history = $this->history(1, 'older', false, null, true);
     $params = array('action' => 'rollback', 'title' => $this->title, 'user' => $history[0]['user'], 'token' => $history[0]['rollbacktoken']);
     if (!is_null($summary)) {
         if (mb_strlen($summary, '8bit') > 255) {
             pecho("Summary is over 255 bytes, the maximum allowed.\n\n", PECHO_FATAL);
             return false;
         }
         if (!$pgNotag) {
             $summary .= $pgTag;
         }
         $params['summary'] = $summary;
     }
     if ($markbot) {
         $params['markbot'] = 'yes';
     }
     if (!is_null($watch)) {
         if ($watch) {
             $params['watchlist'] = 'watch';
         } elseif (!$watch) {
             $params['watchlist'] = 'nochange';
         } elseif (in_array($watch, array('watch', 'unwatch', 'preferences', 'nochange'))) {
             $params['watchlist'] = $watch;
         } else {
             pecho("Watch parameter set incorrectly.  Omitting...\n\n", PECHO_WARN);
         }
     }
     try {
         $this->preEditChecks("Rollback");
     } catch (EditError $e) {
         pecho("Error: {$e}\n\n", PECHO_FATAL);
         return false;
     }
     Hooks::runHook('PreRollback', array(&$params));
     pecho("Rolling back {$this->title}...\n\n", PECHO_NOTICE);
     $result = $this->wiki->apiQuery($params, true);
     if (isset($result['rollback'])) {
         if (isset($result['rollback']['title'])) {
             $this->__construct($this->wiki, $this->title);
             return true;
         } else {
             pecho("Rollback error...\n\n" . print_r($result['rollback'], true) . "\n\n", PECHO_FATAL);
             return false;
         }
     } else {
         pecho("Rollback error...\n\n" . print_r($result, true), PECHO_FATAL);
         return false;
     }
 }