本文整理汇总了PHP中Wiki::get_tokens方法的典型用法代码示例。如果您正苦于以下问题:PHP Wiki::get_tokens方法的具体用法?PHP Wiki::get_tokens怎么用?PHP Wiki::get_tokens使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Wiki
的用法示例。
在下文中一共展示了Wiki::get_tokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: userrights
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;
}
}
示例2: unwatch
/**
* Removes the page to the logged in user's watchlist
*
* @param string $lang The code for the language to show any error message in (default: user preference)
* @return bool True on sucecess
*/
public function unwatch($lang = null)
{
Hooks::runHook('StartUnwatch');
pecho("Unwatching {$this->title}...\n\n", PECHO_NOTICE);
$tokens = $this->wiki->get_tokens();
if ($tokens['watch'] == '+\\') {
pecho("User has logged out.\n\n", PECHO_FATAL);
return false;
}
$apiArray = array('action' => 'watch', 'token' => $tokens['watch'], 'title' => $this->title, 'unwatch' => 'yes');
if (!is_null($lang)) {
$apiArray['uselang'] = $lang;
}
$result = $this->wiki->apiQuery($apiArray, true);
if (isset($result['watch'])) {
if (isset($result['watch']['unwatched'])) {
return true;
} else {
pecho("Unwatch error...\n\n" . print_r($result['watch'], true) . "\n\n", PECHO_FATAL);
return false;
}
} else {
pecho("Unwatch error...\n\n" . print_r($result, true), PECHO_FATAL);
return false;
}
}
示例3: api_upload
/**
* 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;
}
}