本文整理汇总了PHP中WatchAction类的典型用法代码示例。如果您正苦于以下问题:PHP WatchAction类的具体用法?PHP WatchAction怎么用?PHP WatchAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WatchAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: formatResult
/**
* @param $skin Skin
* @param $result
* @return string
*/
function formatResult($skin, $result)
{
global $wgContLang;
$nt = Title::makeTitle($result->namespace, $result->title);
$text = $wgContLang->convert($nt->getPrefixedText());
$plink = Linker::linkKnown($nt, htmlspecialchars($text));
$token = WatchAction::getWatchToken($nt, $this->getUser());
$wlink = Linker::linkKnown($nt, wfMsgHtml('watch'), array(), array('action' => 'watch', 'token' => $token));
return $this->getLanguage()->specialList($plink, $wlink);
}
示例3: formatResult
/**
* @param Skin $skin
* @param object $result Result row
* @return string
*/
function formatResult($skin, $result)
{
global $wgContLang;
$nt = Title::makeTitleSafe($result->namespace, $result->title);
if (!$nt) {
return Html::element('span', array('class' => 'mw-invalidtitle'), Linker::getInvalidTitleDescription($this->getContext(), $result->namespace, $result->title));
}
$text = $wgContLang->convert($nt->getPrefixedText());
$plink = Linker::linkKnown($nt, htmlspecialchars($text));
$token = WatchAction::getWatchToken($nt, $this->getUser());
$wlink = Linker::linkKnown($nt, $this->msg('watch')->escaped(), array(), array('action' => 'watch', 'token' => $token));
return $this->getLanguage()->specialList($plink, $wlink);
}
示例4: execute
public function execute() {
$user = $this->getUser();
if ( !$user->isLoggedIn() ) {
$this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
}
if ( !$user->isAllowed( 'editmywatchlist' ) ) {
$this->dieUsage( 'You don\'t have permission to edit your watchlist', 'permissiondenied' );
}
$params = $this->extractRequestParams();
$title = Title::newFromText( $params['title'] );
if ( !$title || $title->isExternal() || !$title->canExist() ) {
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
}
$res = array( 'title' => $title->getPrefixedText() );
// Currently unnecessary, code to act as a safeguard against any change in current behavior of uselang
// Copy from ApiParse
$oldLang = null;
if ( isset( $params['uselang'] ) && $params['uselang'] != $this->getContext()->getLanguage()->getCode() ) {
$oldLang = $this->getContext()->getLanguage(); // Backup language
$this->getContext()->setLanguage( Language::factory( $params['uselang'] ) );
}
if ( $params['unwatch'] ) {
$res['unwatched'] = '';
$res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock();
$status = UnwatchAction::doUnwatch( $title, $user );
} else {
$res['watched'] = '';
$res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock();
$status = WatchAction::doWatch( $title, $user );
}
if ( !is_null( $oldLang ) ) {
$this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang
}
if ( !$status->isOK() ) {
$this->dieStatus( $status );
}
$this->getResult()->addValue( null, $this->getModuleName(), $res );
}
示例5: move
public function move($params)
{
global $wgUser;
$currentUser = $wgUser;
$wgUser = User::newFromId($this->createdBy);
$currentPageName = $this->title->getText();
if ($params['use_regex']) {
$newPageName = preg_replace("/{$params['target_str']}/U", $params['replacement_str'], $currentPageName);
} else {
$newPageName = str_replace($params['target_str'], $params['replacement_str'], $currentPageName);
}
$newTitle = Title::newFromText($newPageName, $this->title->getNamespace());
$result = $this->title->moveTo($newTitle, true, $params['edit_summary'], $params['create_redirect']);
if ($result == true && $params['watch_page']) {
WatchAction::doWatch($newTitle, $wgUser);
}
$wgUser = $currentUser;
return $result;
}
示例6: addUserToDefaultWatchlistTask
/**
* Adds a user to watchlists of all articles defined in the
* global $wgAutoFollowWatchlist variable.
* @param integer $iUserId The user's ID
*/
public function addUserToDefaultWatchlistTask($iUserId)
{
global $wgAutoFollowWatchlist;
if (!empty($wgAutoFollowWatchlist)) {
$oUser = \User::newFromId($iUserId);
$aWatchSuccess = $aWatchFail = [];
foreach ($wgAutoFollowWatchlist as $sTitleText) {
$oTitle = \Title::newFromText($sTitleText);
if ($oTitle instanceof \Title) {
\WatchAction::doWatch($oTitle, $oUser);
$aWatchSuccess[] = $sTitleText;
} else {
$aWatchFail[] = $sTitleText;
}
}
if (count($aWatchFail) === 0) {
$this->setFlag($oUser);
}
$this->logResults($oUser, $aWatchSuccess, $aWatchFail);
}
}
示例7: 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);
}
示例8: performUpload
/**
* Really perform the upload. Stores the file in the local repo, watches
* if necessary and runs the UploadComplete hook.
*
* @param $comment
* @param $pageText
* @param $watch
* @param $user User
*
* @return Status indicating the whether the upload succeeded.
*/
public function performUpload($comment, $pageText, $watch, $user)
{
wfProfileIn(__METHOD__);
$status = $this->getLocalFile()->upload($this->mTempPath, $comment, $pageText, File::DELETE_SOURCE, $this->mFileProps, false, $user);
if ($status->isGood()) {
if ($watch) {
WatchAction::doWatch($this->getLocalFile()->getTitle(), $user, WatchedItem::IGNORE_USER_RIGHTS);
}
wfRunHooks('UploadComplete', array(&$this));
}
wfProfileOut(__METHOD__);
return $status;
}
示例9: buildContentNavigationUrls
//.........这里部分代码省略.........
if ($title->quickUserCan('move', $user)) {
$moveTitle = SpecialPage::getTitleFor('Movepage', $title->getPrefixedDBkey());
$content_navigation['actions']['move'] = array('class' => $this->getTitle()->isSpecial('Movepage') ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-move", 'move')->setContext($this->getContext())->text(), 'href' => $moveTitle->getLocalURL());
}
} else {
// article doesn't exist or is deleted
if ($user->isAllowed('deletedhistory')) {
$n = $title->isDeleted();
if ($n) {
$undelTitle = SpecialPage::getTitleFor('Undelete', $title->getPrefixedDBkey());
// If the user can't undelete but can view deleted
// history show them a "View .. deleted" tab instead.
$msgKey = $user->isAllowed('undelete') ? 'undelete' : 'viewdeleted';
$content_navigation['actions']['undelete'] = array('class' => $this->getTitle()->isSpecial('Undelete') ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-{$msgKey}", "{$msgKey}_short")->setContext($this->getContext())->numParams($n)->text(), 'href' => $undelTitle->getLocalURL());
}
}
}
if ($title->quickUserCan('protect', $user) && $title->getRestrictionTypes() && MWNamespace::getRestrictionLevels($title->getNamespace(), $user) !== array('')) {
$mode = $title->isProtected() ? 'unprotect' : 'protect';
$content_navigation['actions'][$mode] = array('class' => $onPage && $action == $mode ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-{$mode}", $mode)->setContext($this->getContext())->text(), 'href' => $title->getLocalURL("action={$mode}"));
}
// Checks if the user is logged in
if ($this->loggedin && $user->isAllowedAll('viewmywatchlist', 'editmywatchlist')) {
/**
* The following actions use messages which, if made particular to
* the any specific skins, would break the Ajax code which makes this
* action happen entirely inline. OutputPage::getJSVars
* defines a set of messages in a javascript object - and these
* messages are assumed to be global for all skins. Without making
* a change to that procedure these messages will have to remain as
* the global versions.
*/
$mode = $user->isWatched($title) ? 'unwatch' : 'watch';
$token = WatchAction::getWatchToken($title, $user, $mode);
$content_navigation['actions'][$mode] = array('class' => $onPage && ($action == 'watch' || $action == 'unwatch') ? 'selected' : false, 'text' => $this->msg($mode)->text(), 'href' => $title->getLocalURL(array('action' => $mode, 'token' => $token)));
}
}
Hooks::run('SkinTemplateNavigation', array(&$this, &$content_navigation));
if ($userCanRead && !$wgDisableLangConversion) {
$pageLang = $title->getPageLanguage();
// Gets list of language variants
$variants = $pageLang->getVariants();
// Checks that language conversion is enabled and variants exist
// And if it is not in the special namespace
if (count($variants) > 1) {
// Gets preferred variant (note that user preference is
// only possible for wiki content language variant)
$preferred = $pageLang->getPreferredVariant();
if (Action::getActionName($this) === 'view') {
$params = $request->getQueryValues();
unset($params['title']);
} else {
$params = array();
}
// Loops over each variant
foreach ($variants as $code) {
// Gets variant name from language code
$varname = $pageLang->getVariantname($code);
// Appends variant link
$content_navigation['variants'][] = array('class' => $code == $preferred ? 'selected' : false, 'text' => $varname, 'href' => $title->getLocalURL(array('variant' => $code) + $params), 'lang' => wfBCP47($code), 'hreflang' => wfBCP47($code));
}
}
}
} else {
// If it's not content, it's got to be a special page
$content_navigation['namespaces']['special'] = array('class' => 'selected', 'text' => $this->msg('nstab-special')->text(), 'href' => $request->getRequestURL(), 'context' => 'subject');
示例10: 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());
}
示例11: doSubmit
//.........这里部分代码省略.........
$out->addWikiMsg($msgName);
Hooks::run('SpecialMovepageAfterMove', array(&$this, &$ot, &$nt));
# Now we move extra pages we've been asked to move: subpages and talk
# pages. First, if the old page or the new page is a talk page, we
# can't move any talk pages: cancel that.
if ($ot->isTalkPage() || $nt->isTalkPage()) {
$this->moveTalk = false;
}
if (count($ot->getUserPermissionsErrors('move-subpages', $user))) {
$this->moveSubpages = false;
}
# Next make a list of id's. This might be marginally less efficient
# than a more direct method, but this is not a highly performance-cri-
# tical code path and readable code is more important here.
#
# Note: this query works nicely on MySQL 5, but the optimizer in MySQL
# 4 might get confused. If so, consider rewriting as a UNION.
#
# If the target namespace doesn't allow subpages, moving with subpages
# would mean that you couldn't move them back in one operation, which
# is bad.
# @todo FIXME: A specific error message should be given in this case.
// @todo FIXME: Use Title::moveSubpages() here
$dbr = wfGetDB(DB_MASTER);
if ($this->moveSubpages && (MWNamespace::hasSubpages($nt->getNamespace()) || $this->moveTalk && MWNamespace::hasSubpages($nt->getTalkPage()->getNamespace()))) {
$conds = array('page_title' . $dbr->buildLike($ot->getDBkey() . '/', $dbr->anyString()) . ' OR page_title = ' . $dbr->addQuotes($ot->getDBkey()));
$conds['page_namespace'] = array();
if (MWNamespace::hasSubpages($nt->getNamespace())) {
$conds['page_namespace'][] = $ot->getNamespace();
}
if ($this->moveTalk && MWNamespace::hasSubpages($nt->getTalkPage()->getNamespace())) {
$conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
}
} elseif ($this->moveTalk) {
$conds = array('page_namespace' => $ot->getTalkPage()->getNamespace(), 'page_title' => $ot->getDBkey());
} else {
# Skip the query
$conds = null;
}
$extraPages = array();
if (!is_null($conds)) {
$extraPages = TitleArray::newFromResult($dbr->select('page', array('page_id', 'page_namespace', 'page_title'), $conds, __METHOD__));
}
$extraOutput = array();
$count = 1;
foreach ($extraPages as $oldSubpage) {
if ($ot->equals($oldSubpage) || $nt->equals($oldSubpage)) {
# Already did this one.
continue;
}
$newPageName = preg_replace('#^' . preg_quote($ot->getDBkey(), '#') . '#', StringUtils::escapeRegexReplacement($nt->getDBkey()), $oldSubpage->getDBkey());
if ($oldSubpage->isSubpage() && ($ot->isTalkPage() xor $nt->isTalkPage())) {
// Moving a subpage from a subject namespace to a talk namespace or vice-versa
$newNs = $nt->getNamespace();
} elseif ($oldSubpage->isTalkPage()) {
$newNs = $nt->getTalkPage()->getNamespace();
} else {
$newNs = $nt->getSubjectPage()->getNamespace();
}
# Bug 14385: we need makeTitleSafe because the new page names may
# be longer than 255 characters.
$newSubpage = Title::makeTitleSafe($newNs, $newPageName);
if (!$newSubpage) {
$oldLink = Linker::linkKnown($oldSubpage);
$extraOutput[] = $this->msg('movepage-page-unmoved')->rawParams($oldLink)->params(Title::makeName($newNs, $newPageName))->escaped();
continue;
}
# This was copy-pasted from Renameuser, bleh.
if ($newSubpage->exists() && !$oldSubpage->isValidMoveTarget($newSubpage)) {
$link = Linker::linkKnown($newSubpage);
$extraOutput[] = $this->msg('movepage-page-exists')->rawParams($link)->escaped();
} else {
$success = $oldSubpage->moveTo($newSubpage, true, $this->reason, $createRedirect);
if ($success === true) {
if ($this->fixRedirects) {
DoubleRedirectJob::fixRedirects('move', $oldSubpage, $newSubpage);
}
$oldLink = Linker::link($oldSubpage, null, array(), array('redirect' => 'no'));
$newLink = Linker::linkKnown($newSubpage);
$extraOutput[] = $this->msg('movepage-page-moved')->rawParams($oldLink, $newLink)->escaped();
++$count;
$maximumMovedPages = $this->getConfig()->get('MaximumMovedPages');
if ($count >= $maximumMovedPages) {
$extraOutput[] = $this->msg('movepage-max-pages')->numParams($maximumMovedPages)->escaped();
break;
}
} else {
$oldLink = Linker::linkKnown($oldSubpage);
$newLink = Linker::link($newSubpage);
$extraOutput[] = $this->msg('movepage-page-unmoved')->rawParams($oldLink, $newLink)->escaped();
}
}
}
if ($extraOutput !== array()) {
$out->addHTML("<ul>\n<li>" . implode("</li>\n<li>", $extraOutput) . "</li>\n</ul>");
}
# Deal with watches (we don't watch subpages)
WatchAction::doWatchOrUnwatch($this->watch, $ot, $user);
WatchAction::doWatchOrUnwatch($this->watch, $nt, $user);
}
示例12: 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();
}
}
示例13: watchThisPage
function watchThisPage()
{
global $wgOut, $wgUser;
++$this->mWatchLinkNum;
// Cache
$title = $this->getSkin()->getTitle();
if ($wgOut->isArticleRelated()) {
if ($wgUser->isWatched($title)) {
$text = wfMessage('unwatchthispage')->text();
$query = array('action' => 'unwatch', 'token' => UnwatchAction::getUnwatchToken($title, $wgUser));
$id = 'mw-unwatch-link' . $this->mWatchLinkNum;
} else {
$text = wfMessage('watchthispage')->text();
$query = array('action' => 'watch', 'token' => WatchAction::getWatchToken($title, $wgUser));
$id = 'mw-watch-link' . $this->mWatchLinkNum;
}
$s = Linker::linkKnown($title, $text, array('id' => $id), $query);
} else {
$s = wfMessage('notanarticle')->text();
}
return $s;
}
示例14: 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);
}
示例15: topLevelThreadCommands
/**
* @param $thread Thread
*/
function topLevelThreadCommands($thread)
{
$commands = array();
$commands['history'] = array('label' => wfMessage('history_short')->parse(), 'href' => self::permalinkUrl($thread, 'thread_history'), 'enabled' => true);
if ($this->user->isAllowed('move')) {
$move_href = SpecialPage::getTitleFor('MoveThread', $thread->title()->getPrefixedText())->getLocalURL();
$commands['move'] = array('label' => wfMessage('lqt-movethread')->parse(), 'href' => $move_href, 'enabled' => true);
}
if ($this->user->isAllowed('protect')) {
$protect_href = $thread->title()->getLocalURL('action=protect');
// Check if it's already protected
if (!$thread->title()->isProtected()) {
$label = wfMessage('protect')->parse();
} else {
$label = wfMessage('unprotect')->parse();
}
$commands['protect'] = array('label' => $label, 'href' => $protect_href, 'enabled' => true);
}
if (!$this->user->isAnon() && !$thread->title()->userIsWatching()) {
$commands['watch'] = array('label' => wfMessage('watch')->parse(), 'href' => self::permalinkUrlWithQuery($thread, array('action' => 'watch', 'token' => WatchAction::getWatchToken($thread->title(), $this->user, 'watch'))), 'enabled' => true);
} elseif (!$this->user->isAnon()) {
$commands['unwatch'] = array('label' => wfMessage('unwatch')->parse(), 'href' => self::permalinkUrlWithQuery($thread, array('action' => 'unwatch', 'token' => WatchAction::getWatchToken($thread->title(), $this->user, 'unwatch'))), 'enabled' => true);
}
if (LqtDispatch::isLqtPage($thread->getTitle())) {
$summarizeUrl = self::permalinkUrl($thread, 'summarize', $thread->id());
$commands['summarize'] = array('label' => wfMessage('lqt_summarize_link')->parse(), 'href' => $summarizeUrl, 'enabled' => true);
}
Hooks::run('LiquidThreadsTopLevelCommands', array($thread, &$commands));
return $commands;
}