本文整理匯總了PHP中MWNamespace::getRestrictionLevels方法的典型用法代碼示例。如果您正苦於以下問題:PHP MWNamespace::getRestrictionLevels方法的具體用法?PHP MWNamespace::getRestrictionLevels怎麽用?PHP MWNamespace::getRestrictionLevels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MWNamespace
的用法示例。
在下文中一共展示了MWNamespace::getRestrictionLevels方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: buildSelector
/**
* Build protection level selector
*
* @param string $action action to protect
* @param string $selected current protection level
* @return String: HTML fragment
*/
function buildSelector($action, $selected)
{
global $wgUser;
// If the form is disabled, display all relevant levels. Otherwise,
// just show the ones this user can use.
$levels = MWNamespace::getRestrictionLevels($this->mTitle->getNamespace(), $this->disabled ? null : $wgUser);
$id = 'mwProtect-level-' . $action;
$attribs = array('id' => $id, 'name' => $id, 'size' => count($levels), 'onchange' => 'ProtectionForm.updateLevels(this)') + $this->disabledAttrib;
$out = Xml::openElement('select', $attribs);
foreach ($levels as $key) {
$out .= Xml::option($this->getOptionLabel($key), $key, $key == $selected);
}
$out .= Xml::closeElement('select');
return $out;
}
示例2: buildContentNavigationUrls
//.........這裏部分代碼省略.........
// Adds new section link
//$content_navigation['actions']['addsection']
$content_navigation['views']['addsection'] = array('class' => $isEditing && $section == 'new' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-addsection", 'addsection')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL('action=edit§ion=new'));
}
// Checks if the page has some kind of viewable content
} elseif ($title->hasSourceText()) {
// Adds view source view link
$content_navigation['views']['viewsource'] = array('class' => $onPage && $action == 'edit' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-viewsource", 'viewsource')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL($this->editUrlOptions()), 'primary' => true);
}
// Checks if the page exists
if ($title->exists()) {
// Adds history view link
$content_navigation['views']['history'] = array('class' => $onPage && $action == 'history' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-view-history", 'history_short')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL('action=history'));
if ($title->quickUserCan('delete', $user)) {
$content_navigation['actions']['delete'] = array('class' => $onPage && $action == 'delete' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-delete", 'delete')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL('action=delete'));
}
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();
示例3: execute
public function execute()
{
$user = $this->getUser();
$params = $this->extractRequestParams();
$title = Title::newFromText($params['page']);
if (!$title) {
$this->dieUsageMsg('invalidtitle', $params['page']);
}
$isSafeAction = in_array($params['paction'], self::$SAFE_ACTIONS, true);
$availableNamespaces = $this->veConfig->get('VisualEditorAvailableNamespaces');
if (!$isSafeAction && (!isset($availableNamespaces[$title->getNamespace()]) || !$availableNamespaces[$title->getNamespace()])) {
$this->dieUsage("VisualEditor is not enabled in namespace " . $title->getNamespace(), 'novenamespace');
}
$parserParams = array();
if (isset($params['oldid'])) {
$parserParams['oldid'] = $params['oldid'];
}
$html = $params['html'];
if (substr($html, 0, 11) === 'rawdeflate,') {
$deflated = base64_decode(substr($html, 11));
wfSuppressWarnings();
$html = gzinflate($deflated);
wfRestoreWarnings();
if ($deflated === $html || $html === false) {
$this->dieUsage("HTML provided is not properly deflated", 'invaliddeflate');
}
}
wfDebugLog('visualeditor', "called on '{$title}' with paction: '{$params['paction']}'");
switch ($params['paction']) {
case 'parse':
case 'metadata':
// Dirty hack to provide the correct context for edit notices
global $wgTitle;
// FIXME NOOOOOOOOES
$wgTitle = $title;
RequestContext::getMain()->setTitle($title);
// Get information about current revision
if ($title->exists()) {
$latestRevision = Revision::newFromTitle($title);
if ($latestRevision === null) {
$this->dieUsage('Could not find latest revision for title', 'latestnotfound');
}
$revision = null;
if (!isset($parserParams['oldid']) || $parserParams['oldid'] === 0) {
$parserParams['oldid'] = $latestRevision->getId();
$revision = $latestRevision;
} else {
$revision = Revision::newFromId($parserParams['oldid']);
if ($revision === null) {
$this->dieUsage('Could not find revision ID ' . $parserParams['oldid'], 'oldidnotfound');
}
}
$restoring = $revision && !$revision->isCurrent();
$baseTimestamp = $latestRevision->getTimestamp();
$oldid = intval($parserParams['oldid']);
// If requested, request HTML from Parsoid/RESTBase
if ($params['paction'] === 'parse') {
$content = $this->requestRestbase('GET', 'page/html/' . urlencode($title->getPrefixedDBkey()) . '/' . $oldid, array());
if ($content === false) {
$this->dieUsage('Error contacting the document server', 'docserver');
}
}
} else {
$content = '';
$baseTimestamp = wfTimestampNow();
$oldid = 0;
$restoring = false;
}
// Get edit notices
$notices = $title->getEditNotices();
// Anonymous user notice
if ($user->isAnon()) {
$notices[] = $this->msg('anoneditwarning', '{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}', '{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}')->parseAsBlock();
}
// Old revision notice
if ($restoring) {
$notices[] = $this->msg('editingold')->parseAsBlock();
}
// New page notices
if (!$title->exists()) {
$notices[] = $this->msg($user->isLoggedIn() ? 'newarticletext' : 'newarticletextanon', wfExpandUrl(Skin::makeInternalOrExternalUrl($this->msg('helppage')->inContentLanguage()->text())))->parseAsBlock();
// Page protected from creation
if ($title->getRestrictions('create')) {
$notices[] = $this->msg('titleprotectedwarning')->parseAsBlock();
}
}
// Look at protection status to set up notices + surface class(es)
$protectedClasses = array();
if (MWNamespace::getRestrictionLevels($title->getNamespace()) !== array('')) {
// Page protected from editing
if ($title->isProtected('edit')) {
# Is the title semi-protected?
if ($title->isSemiProtected()) {
$protectedClasses[] = 'mw-textarea-sprotected';
$noticeMsg = 'semiprotectedpagewarning';
} else {
$protectedClasses[] = 'mw-textarea-protected';
# Then it must be protected based on static groups (regular)
$noticeMsg = 'protectedpagewarning';
}
//.........這裏部分代碼省略.........
示例4: buildSelector
/**
* Build protection level selector
*
* @param string $action Action to protect
* @param string $selected Current protection level
* @return string HTML fragment
*/
function buildSelector($action, $selected)
{
// If the form is disabled, display all relevant levels. Otherwise,
// just show the ones this user can use.
$levels = MWNamespace::getRestrictionLevels($this->mTitle->getNamespace(), $this->disabled ? null : $this->mContext->getUser());
$id = 'mwProtect-level-' . $action;
$select = new XmlSelect($id, $id, $selected);
$select->setAttribute('size', count($levels));
if ($this->disabled) {
$select->setAttribute('disabled', 'disabled');
}
foreach ($levels as $key) {
$select->addOption($this->getOptionLabel($key), $key);
}
return $select->getHTML();
}
示例5: showTextbox1
/**
* Method to output wpTextbox1
* The $textoverride method can be used by subclasses overriding showContentForm
* to pass back to this method.
*
* @param array $customAttribs Array of html attributes to use in the textarea
* @param string $textoverride Optional text to override $this->textarea1 with
*/
protected function showTextbox1($customAttribs = null, $textoverride = null)
{
if ($this->wasDeletedSinceLastEdit() && $this->formtype == 'save') {
$attribs = array('style' => 'display:none;');
} else {
$classes = array();
// Textarea CSS
if ($this->mTitle->isProtected('edit') && MWNamespace::getRestrictionLevels($this->mTitle->getNamespace()) !== array('')) {
# Is the title semi-protected?
if ($this->mTitle->isSemiProtected()) {
$classes[] = 'mw-textarea-sprotected';
} else {
# Then it must be protected based on static groups (regular)
$classes[] = 'mw-textarea-protected';
}
# Is the title cascade-protected?
if ($this->mTitle->isCascadeProtected()) {
$classes[] = 'mw-textarea-cprotected';
}
}
$attribs = array('tabindex' => 1);
if (is_array($customAttribs)) {
$attribs += $customAttribs;
}
if (count($classes)) {
if (isset($attribs['class'])) {
$classes[] = $attribs['class'];
}
$attribs['class'] = implode(' ', $classes);
}
}
$this->showTextbox($textoverride !== null ? $textoverride : $this->textbox1, 'wpTextbox1', $attribs);
}
示例6: execute
public function execute()
{
global $wgVisualEditorNamespaces, $wgVisualEditorParsoidURL, $wgVisualEditorParsoidTimeout, $wgDevelEnvironment;
$user = $this->getUser();
$params = $this->extractRequestParams();
$page = Title::newFromText($params['page']);
if (!$page) {
$this->dieUsageMsg('invalidtitle', $params['page']);
}
if (!in_array($page->getNamespace(), $wgVisualEditorNamespaces)) {
$this->dieUsage("VisualEditor is not enabled in namespace " . $page->getNamespace(), 'novenamespace');
}
$parserParams = array();
if (isset($params['oldwt'])) {
$parserParams['oldwt'] = $params['oldwt'];
} else {
if (isset($params['oldid'])) {
$parserParams['oldid'] = $params['oldid'];
}
}
switch ($params['paction']) {
case 'parsewt':
// FIXME: Perhaps requestParsoid method should be used here
$postData = array('wt' => $params['wikitext']);
$content = Http::post($wgVisualEditorParsoidURL . '/' . urlencode($this->getApiSource()) . '/' . urlencode($page->getPrefixedDBkey()), array('postData' => $postData, 'timeout' => $wgVisualEditorParsoidTimeout, 'noProxy' => !empty($wgDevelEnvironment)));
$result = array('result' => 'success', 'content' => $content);
break;
case 'parse':
$parsed = $this->getHTML($page, $parserParams);
// Dirty hack to provide the correct context for edit notices
global $wgTitle;
// FIXME NOOOOOOOOES
$wgTitle = $page;
RequestContext::getMain()->setTitle($page);
// TODO: In MW 1.19.7 method getEditNotices does not exist so for now fallback to just an empty
// but in future figure out what's the proper backward compatibility solution.
// #back-compat
// $notices = $page->getEditNotices();
$notices = array();
$anoneditwarning = false;
$anoneditwarningMessage = $this->msg('VisualEditor-anoneditwarning');
if ($user->isAnon() && $anoneditwarningMessage->exists()) {
$notices[] = $anoneditwarningMessage->parseAsBlock();
$anoneditwarning = true;
}
if ($parsed && $parsed['restoring']) {
$notices[] = $this->msg('editingold')->parseAsBlock();
}
// Creating new page
if (!$page->exists()) {
$notices[] = $this->msg($user->isLoggedIn() ? 'newarticletext' : 'newarticletextanon', Skin::makeInternalOrExternalUrl($this->msg('helppage')->inContentLanguage()->text()))->parseAsBlock();
// Page protected from creation
if ($page->getRestrictions('create')) {
$notices[] = $this->msg('titleprotectedwarning')->parseAsBlock();
}
}
// Look at protection status to set up notices + surface class(es)
$protectedClasses = array();
if (MWNamespace::getRestrictionLevels($page->getNamespace()) !== array('')) {
// Page protected from editing
if ($page->isProtected('edit')) {
# Is the title semi-protected?
if ($page->isSemiProtected()) {
$protectedClasses[] = 'mw-textarea-sprotected';
$noticeMsg = 'semiprotectedpagewarning';
} else {
$protectedClasses[] = 'mw-textarea-protected';
# Then it must be protected based on static groups (regular)
$noticeMsg = 'protectedpagewarning';
}
$notices[] = $this->msg($noticeMsg)->parseAsBlock();
}
// Deal with cascading edit protection
list($sources, $restrictions) = $page->getCascadeProtectionSources();
if (isset($restrictions['edit'])) {
$protectedClasses[] = ' mw-textarea-cprotected';
$notice = $this->msg('cascadeprotectedwarning')->parseAsBlock() . '<ul>';
// Unfortunately there's no nice way to get only the pages which cause
// editing to be restricted
foreach ($sources as $source) {
$notice .= "<li>" . Linker::link($source) . "</li>";
}
$notice .= '</ul>';
$notices[] = $notice;
}
}
// Show notice when editing user / user talk page of a user that doesn't exist
// or who is blocked
// HACK of course this code is partly duplicated from EditPage.php :(
if ($page->getNamespace() == NS_USER || $page->getNamespace() == NS_USER_TALK) {
$parts = explode('/', $page->getText(), 2);
$targetUsername = $parts[0];
$targetUser = User::newFromName($targetUsername, false);
if (!($targetUser && $targetUser->isLoggedIn()) && !User::isIP($targetUsername)) {
// User does not exist
$notices[] = "<div class=\"mw-userpage-userdoesnotexist error\">\n" . $this->msg('userpage-userdoesnotexist', wfEscapeWikiText($targetUsername)) . "\n</div>";
}
// Some upstream code is deleted from here, more information:
// https://github.com/Wikia/app/commit/d54b481d3f6e5b092b212a2c98b2cb5452bee26c
// https://github.com/Wikia/app/commit/681e7437078206460f7c0cb1837095e656d8ba85
//.........這裏部分代碼省略.........