本文整理汇总了PHP中WatchAction::doUnwatch方法的典型用法代码示例。如果您正苦于以下问题:PHP WatchAction::doUnwatch方法的具体用法?PHP WatchAction::doUnwatch怎么用?PHP WatchAction::doUnwatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WatchAction
的用法示例。
在下文中一共展示了WatchAction::doUnwatch方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
global $wgUser;
if (!$wgUser->isLoggedIn()) {
$this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
}
$params = $this->extractRequestParams();
$title = Title::newFromText($params['title']);
if (!$title || $title->getNamespace() < 0) {
$this->dieUsageMsg(array('invalidtitle', $params['title']));
}
$article = new Article($title, 0);
$res = array('title' => $title->getPrefixedText());
if ($params['unwatch']) {
$res['unwatched'] = '';
$res['message'] = wfMsgExt('removedwatchtext', array('parse'), $title->getPrefixedText());
$success = WatchAction::doUnwatch($title, $wgUser);
} else {
$res['watched'] = '';
$res['message'] = wfMsgExt('addedwatchtext', array('parse'), $title->getPrefixedText());
$success = UnwatchAction::doWatch($title, $wgUser);
}
if (!$success) {
$this->dieUsageMsg('hookaborted');
}
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例2: delete
function delete()
{
global $wgUser, $wgOut, $wgRequest;
$confirm = $wgRequest->wasPosted() && $wgUser->matchEditToken($wgRequest->getVal('wpEditToken'));
$reason = $wgRequest->getText('wpReason');
# This code desperately needs to be totally rewritten
# Check permissions
$permission_errors = $this->mTitle->getUserPermissionsErrors('mv_delete_mvd', $wgUser);
if (count($permission_errors) > 0) {
$wgOut->showPermissionsErrorPage($permission_errors);
return;
}
$wgOut->setPagetitle(wfMsg('confirmdelete'));
# Better double-check that it hasn't been deleted yet!
$dbw = wfGetDB(DB_MASTER);
$conds = $this->mTitle->pageCond();
$latest = $dbw->selectField('page', 'page_latest', $conds, __METHOD__);
if ($latest === false) {
$wgOut->showFatalError(wfMsg('cannotdelete'));
return;
}
if ($confirm) {
$this->doDelete($reason);
if ($wgRequest->getCheck('wpWatch')) {
WatchAction::doWatch($this->mTitle, $wgUser);
} elseif ($this->mTitle->userIsWatching()) {
WatchAction::doUnwatch($this->mTitle, $wgUser);
}
return;
}
// Generate deletion reason
$hasHistory = false;
$reason = $this->generateReason($hasHistory);
// If the page has a history, insert a warning
if ($hasHistory && !$confirm) {
$skin = $wgUser->getSkin();
$wgOut->addHTML('<strong>' . wfMsg('historywarning') . ' ' . $skin->historyLink() . '</strong>');
}
return $this->confirmDelete('', $reason);
}
示例3: doUnwatch
/**
* Stop watching a page
* @return bool true on successful unwatch
* @deprecated since 1.18
*/
public function doUnwatch()
{
wfDeprecated(__METHOD__, '1.18');
return WatchAction::doUnwatch($this->getTitle(), $this->getContext()->getUser());
}
示例4: commitWatch
/**
* Commit the change of watch status
*/
protected function commitWatch()
{
global $wgUser;
if ($this->watchthis xor $this->mTitle->userIsWatching()) {
$dbw = wfGetDB(DB_MASTER);
$dbw->begin();
if ($this->watchthis) {
WatchAction::doWatch($this->mTitle, $wgUser);
} else {
WatchAction::doUnwatch($this->mTitle, $wgUser);
}
$dbw->commit();
}
}
示例5: setWatch
/**
* Set a watch (or unwatch) based the based on a watchlist parameter.
* @param $watch String Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
* @param $titleObj Title the article's title to change
* @param $userOption String The user option to consider when $watch=preferences
*/
protected function setWatch($watch, $titleObj, $userOption = null)
{
$value = $this->getWatchlistValue($watch, $titleObj, $userOption);
if ($value === null) {
return;
}
$user = $this->getUser();
if ($value) {
WatchAction::doWatch($titleObj, $user);
} else {
WatchAction::doUnwatch($titleObj, $user);
}
}
示例6: doDelete
/**
* Really delete the file
*
* @param $title Title object
* @param $file File object
* @param $oldimage String: archive name
* @param $reason String: reason of the deletion
* @param $suppress Boolean: whether to mark all deleted versions as restricted
*/
public static function doDelete(&$title, &$file, &$oldimage, $reason, $suppress)
{
global $wgUser;
$article = null;
$status = Status::newFatal('error');
if ($oldimage) {
$status = $file->deleteOld($oldimage, $reason, $suppress);
if ($status->ok) {
// Need to do a log item
$log = new LogPage('delete');
$logComment = wfMsgForContent('deletedrevision', $oldimage);
if (trim($reason) != '') {
$logComment .= wfMsgForContent('colon-separator') . $reason;
}
$log->addEntry('delete', $title, $logComment);
}
} else {
$id = $title->getArticleID(Title::GAID_FOR_UPDATE);
$article = new Article($title);
$dbw = wfGetDB(DB_MASTER);
try {
// delete the associated article first
if ($article->doDeleteArticle($reason, $suppress, $id, false)) {
global $wgRequest;
if ($wgRequest->getCheck('wpWatch') && $wgUser->isLoggedIn()) {
WatchAction::doWatch($title, $wgUser);
} elseif ($title->userIsWatching()) {
WatchAction::doUnwatch($title, $wgUser);
}
$status = $file->delete($reason, $suppress);
if ($status->ok) {
$dbw->commit();
} else {
$dbw->rollback();
}
}
} catch (MWException $e) {
// rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?"
$dbw->rollback();
throw $e;
}
}
if ($status->isGood()) {
wfRunHooks('FileDeleteComplete', array(&$file, &$oldimage, &$article, &$wgUser, &$reason));
}
return $status;
}
示例7: updateWatchlist
/**
* Register the change of watch status
*/
protected function updateWatchlist()
{
global $wgUser;
if ($wgUser->isLoggedIn() && $this->watchthis != $wgUser->isWatched($this->mTitle)) {
$fname = __METHOD__;
$title = $this->mTitle;
$watch = $this->watchthis;
// Do this in its own transaction to reduce contention...
$dbw = wfGetDB(DB_MASTER);
$dbw->onTransactionIdle(function () use($dbw, $title, $watch, $wgUser, $fname) {
$dbw->begin($fname);
if ($watch) {
WatchAction::doWatch($title, $wgUser);
} else {
WatchAction::doUnwatch($title, $wgUser);
}
$dbw->commit($fname);
});
}
}
示例8: doUnwatch
/**
* Stop watching a page
* @return bool true on successful unwatch
* @deprecated since 1.18
*/
public function doUnwatch()
{
global $wgUser;
wfDeprecated(__METHOD__, '1.18');
return WatchAction::doUnwatch($this->getTitle(), $wgUser);
}
示例9: execute
/**
* Fulfil the request; shows the form or deletes the file,
* pending authentication, confirmation, etc.
*/
public function execute()
{
global $wgOut, $wgRequest, $wgUser, $wgUploadMaintenance;
$permissionErrors = $this->title->getUserPermissionsErrors('delete', $wgUser);
if (count($permissionErrors)) {
throw new PermissionsError('delete', $permissionErrors);
}
if (wfReadOnly()) {
throw new ReadOnlyError();
}
if ($wgUploadMaintenance) {
throw new ErrorPageError('filedelete-maintenance-title', 'filedelete-maintenance');
}
$this->setHeaders();
$this->oldimage = $wgRequest->getText('oldimage', false);
$token = $wgRequest->getText('wpEditToken');
# Flag to hide all contents of the archived revisions
$suppress = $wgRequest->getVal('wpSuppress') && $wgUser->isAllowed('suppressrevision');
if ($this->oldimage) {
$this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($this->title, $this->oldimage);
}
if (!self::haveDeletableFile($this->file, $this->oldfile, $this->oldimage)) {
$wgOut->addHTML($this->prepareMessage('filedelete-nofile'));
$wgOut->addReturnTo($this->title);
return;
}
// Perform the deletion if appropriate
if ($wgRequest->wasPosted() && $wgUser->matchEditToken($token, $this->oldimage)) {
$deleteReasonList = $wgRequest->getText('wpDeleteReasonList');
$deleteReason = $wgRequest->getText('wpReason');
if ($deleteReasonList == 'other') {
$reason = $deleteReason;
} elseif ($deleteReason != '') {
// Entry from drop down menu + additional comment
$reason = $deleteReasonList . wfMessage('colon-separator')->inContentLanguage()->text() . $deleteReason;
} else {
$reason = $deleteReasonList;
}
$status = self::doDelete($this->title, $this->file, $this->oldimage, $reason, $suppress, $wgUser);
if (!$status->isGood()) {
$wgOut->addHTML('<h2>' . $this->prepareMessage('filedeleteerror-short') . "</h2>\n");
$wgOut->addWikiText('<div class="error">' . $status->getWikiText('filedeleteerror-short', 'filedeleteerror-long') . '</div>');
}
if ($status->ok) {
$wgOut->setPageTitle(wfMessage('actioncomplete'));
$wgOut->addHTML($this->prepareMessage('filedelete-success'));
// Return to the main page if we just deleted all versions of the
// file, otherwise go back to the description page
$wgOut->addReturnTo($this->oldimage ? $this->title : Title::newMainPage());
if ($wgUser->isLoggedIn() && $wgRequest->getCheck('wpWatch') != $wgUser->isWatched($this->title)) {
if ($wgRequest->getCheck('wpWatch')) {
WatchAction::doWatch($this->title, $wgUser);
} else {
WatchAction::doUnwatch($this->title, $wgUser);
}
}
}
return;
}
$this->showForm();
$this->showLogEntries();
}
示例10: save
/**
* Save submitted protection form
*
* @return Boolean: success
*/
function save()
{
global $wgRequest, $wgUser;
# Permission check!
if ($this->disabled) {
$this->show();
return false;
}
$token = $wgRequest->getVal('wpEditToken');
if (!$wgUser->matchEditToken($token)) {
$this->show(wfMsg('sessionfailure'));
return false;
}
# Create reason string. Use list and/or custom string.
$reasonstr = $this->mReasonSelection;
if ($reasonstr != 'other' && $this->mReason != '') {
// Entry from drop down menu + additional comment
$reasonstr .= wfMsgForContent('colon-separator') . $this->mReason;
} elseif ($reasonstr == 'other') {
$reasonstr = $this->mReason;
}
$expiry = array();
foreach ($this->mApplicableTypes as $action) {
$expiry[$action] = $this->getExpiry($action);
if (empty($this->mRestrictions[$action])) {
continue;
}
// unprotected
if (!$expiry[$action]) {
$this->show(wfMsg('protect_expiry_invalid'));
return false;
}
if ($expiry[$action] < wfTimestampNow()) {
$this->show(wfMsg('protect_expiry_old'));
return false;
}
}
# They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied
# to a semi-protected page.
global $wgGroupPermissions;
$edit_restriction = isset($this->mRestrictions['edit']) ? $this->mRestrictions['edit'] : '';
$this->mCascade = $wgRequest->getBool('mwProtect-cascade');
if ($this->mCascade && $edit_restriction != 'protect' && !(isset($wgGroupPermissions[$edit_restriction]['protect']) && $wgGroupPermissions[$edit_restriction]['protect'])) {
$this->mCascade = false;
}
if ($this->mTitle->exists()) {
$ok = $this->mArticle->updateRestrictions($this->mRestrictions, $reasonstr, $this->mCascade, $expiry);
} else {
$ok = $this->mTitle->updateTitleProtection($this->mRestrictions['create'], $reasonstr, $expiry['create']);
}
if (!$ok) {
throw new FatalError("Unknown error at restriction save time.");
}
$errorMsg = '';
# Give extensions a change to handle added form items
if (!wfRunHooks('ProtectionForm::save', array($this->mArticle, &$errorMsg))) {
throw new FatalError("Unknown hook error at restriction save time.");
}
if ($errorMsg != '') {
$this->show($errorMsg);
return false;
}
if ($wgRequest->getCheck('mwProtectWatch') && $wgUser->isLoggedIn()) {
WatchAction::doWatch($this->mTitle, $wgUser);
} elseif ($this->mTitle->userIsWatching()) {
WatchAction::doUnwatch($this->mTitle, $wgUser);
}
return $ok;
}
示例11: save
/**
* Save submitted protection form
*
* @return Boolean: success
*/
function save()
{
global $wgRequest, $wgUser, $wgOut;
# Permission check!
if ($this->disabled) {
$this->show();
return false;
}
$token = $wgRequest->getVal('wpEditToken');
if (!$wgUser->matchEditToken($token, array('protect', $this->mTitle->getPrefixedDBkey()))) {
$this->show(array('sessionfailure'));
return false;
}
# Create reason string. Use list and/or custom string.
$reasonstr = $this->mReasonSelection;
if ($reasonstr != 'other' && $this->mReason != '') {
// Entry from drop down menu + additional comment
$reasonstr .= wfMessage('colon-separator')->text() . $this->mReason;
} elseif ($reasonstr == 'other') {
$reasonstr = $this->mReason;
}
$expiry = array();
foreach ($this->mApplicableTypes as $action) {
$expiry[$action] = $this->getExpiry($action);
if (empty($this->mRestrictions[$action])) {
continue;
}
// unprotected
if (!$expiry[$action]) {
$this->show(array('protect_expiry_invalid'));
return false;
}
if ($expiry[$action] < wfTimestampNow()) {
$this->show(array('protect_expiry_old'));
return false;
}
}
# They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied
# to a semi-protected page.
global $wgGroupPermissions;
$edit_restriction = isset($this->mRestrictions['edit']) ? $this->mRestrictions['edit'] : '';
$this->mCascade = $wgRequest->getBool('mwProtect-cascade');
if ($this->mCascade && $edit_restriction != 'protect' && !(isset($wgGroupPermissions[$edit_restriction]['protect']) && $wgGroupPermissions[$edit_restriction]['protect'])) {
$this->mCascade = false;
}
$status = $this->mArticle->doUpdateRestrictions($this->mRestrictions, $expiry, $this->mCascade, $reasonstr, $wgUser);
if (!$status->isOK()) {
$this->show($wgOut->parseInline($status->getWikiText()));
return false;
}
/**
* Give extensions a change to handle added form items
*
* @since 1.19 you can (and you should) return false to abort saving;
* you can also return an array of message name and its parameters
*/
$errorMsg = '';
if (!wfRunHooks('ProtectionForm::save', array($this->mArticle, &$errorMsg))) {
if ($errorMsg == '') {
$errorMsg = array('hookaborted');
}
}
if ($errorMsg != '') {
$this->show($errorMsg);
return false;
}
if ($wgUser->isLoggedIn() && $wgRequest->getCheck('mwProtectWatch') != $wgUser->isWatched($this->mTitle)) {
if ($wgRequest->getCheck('mwProtectWatch')) {
WatchAction::doWatch($this->mTitle, $wgUser);
} else {
WatchAction::doUnwatch($this->mTitle, $wgUser);
}
}
return true;
}
示例12: commitWatch
/**
* Commit the change of watch status
*/
protected function commitWatch()
{
global $wgUser;
if ($wgUser->isLoggedIn() && $this->watchthis != $wgUser->isWatched($this->mTitle)) {
$dbw = wfGetDB(DB_MASTER);
$dbw->begin(__METHOD__);
if ($this->watchthis) {
WatchAction::doWatch($this->mTitle, $wgUser);
} else {
WatchAction::doUnwatch($this->mTitle, $wgUser);
}
$dbw->commit(__METHOD__);
}
}
示例13: doUnwatch
/**
* Stop watching a page
* @return bool true on successful unwatch
* @deprecated since 1.18
*/
public function doUnwatch()
{
global $wgUser;
return WatchAction::doUnwatch($this->getTitle(), $wgUser);
}