/** * factory method, create either Item or List object from title * * @author ADi * @param Title $title * @return TopListBase */ public static function newFromTitle(Title $title) { $object = null; if ($title->getNamespace() == NS_TOPLIST) { if (!$title->isSubpage()) { $object = TopList::newFromTitle($title); } else { $object = TopListItem::newFromTitle($title); } } return $object; }
/** * @author Federico "Lox" Lucignano * * Factory method * * @param Title $title a Title class instance for the article * @param boolean $skipPhalanxCheck a flag informs to check Phalanx or not * * @return TopList|bool|mixed a TopList instance, false in case $title is not in the NS_TOPLIST namespace */ public static function newFromTitle(Title $title, $skipPhalanxCheck = false) { global $wgMemc; $notPhalanxBlocked = true; //FB#16388: we don't need to check Phalanx blocks while deleting if (!$skipPhalanxCheck) { //FB#8083: blocked titles are not being filtered, this should be handled automatically by Phalanx though... $error_msg = ''; if (!wfRunHooks("PageTitleFilter", array($title, &$error_msg))) { $notPhalanxBlocked = false; } } if ($title->getNamespace() == NS_TOPLIST && !$title->isSubpage() && $notPhalanxBlocked) { $list = new self(); $list->mTitle = $title; //needed to let getItems fetch fresh data when instantiating more tha once with the same title object $wgMemc->set($list->_getNeedRefreshCacheKey(), true); return $list; } return false; }
/** * Show the form * * @param array $err Error messages. Each item is an error message. * It may either be a string message name or array message name and * parameters, like the second argument to OutputPage::wrapWikiMsg(). */ function showForm($err) { global $wgContLang; $this->getSkin()->setRelevantTitle($this->oldTitle); $oldTitleLink = Linker::link($this->oldTitle); $out = $this->getOutput(); $out->setPageTitle($this->msg('move-page', $this->oldTitle->getPrefixedText())); $out->addModules('mediawiki.special.movePage'); $out->addModuleStyles('mediawiki.special.movePage.styles'); $this->addHelpLink('Help:Moving a page'); $newTitle = $this->newTitle; if (!$newTitle) { # Show the current title as a default # when the form is first opened. $newTitle = $this->oldTitle; } elseif (!count($err)) { # If a title was supplied, probably from the move log revert # link, check for validity. We can then show some diagnostic # information and save a click. $newerr = $this->oldTitle->isValidMoveOperation($newTitle); if (is_array($newerr)) { $err = $newerr; } } $user = $this->getUser(); if (count($err) == 1 && isset($err[0][0]) && $err[0][0] == 'articleexists' && $newTitle->quickUserCan('delete', $user)) { $out->addWikiMsg('delete_and_move_text', $newTitle->getPrefixedText()); $movepagebtn = $this->msg('delete_and_move')->text(); $submitVar = 'wpDeleteAndMove'; $confirm = true; $err = array(); } else { if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage()) { $out->wrapWikiMsg("<div class=\"error mw-moveuserpage-warning\">\n\$1\n</div>", 'moveuserpage-warning'); } elseif ($this->oldTitle->getNamespace() == NS_CATEGORY) { $out->wrapWikiMsg("<div class=\"error mw-movecategorypage-warning\">\n\$1\n</div>", 'movecategorypage-warning'); } $out->addWikiMsg($this->getConfig()->get('FixDoubleRedirects') ? 'movepagetext' : 'movepagetext-noredirectfixer'); $movepagebtn = $this->msg('movepagebtn')->text(); $submitVar = 'wpMove'; $confirm = false; } if (count($err) == 1 && isset($err[0][0]) && $err[0][0] == 'file-exists-sharedrepo' && $user->isAllowed('reupload-shared')) { $out->addWikiMsg('move-over-sharedrepo', $newTitle->getPrefixedText()); $submitVar = 'wpMoveOverSharedFile'; $err = array(); } $oldTalk = $this->oldTitle->getTalkPage(); $oldTitleSubpages = $this->oldTitle->hasSubpages(); $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages(); $canMoveSubpage = ($oldTitleSubpages || $oldTitleTalkSubpages) && !count($this->oldTitle->getUserPermissionsErrors('move-subpages', $user)); # We also want to be able to move assoc. subpage talk-pages even if base page # has no associated talk page, so || with $oldTitleTalkSubpages. $considerTalk = !$this->oldTitle->isTalkPage() && ($oldTalk->exists() || $oldTitleTalkSubpages && $canMoveSubpage); $dbr = wfGetDB(DB_SLAVE); if ($this->getConfig()->get('FixDoubleRedirects')) { $hasRedirects = $dbr->selectField('redirect', '1', array('rd_namespace' => $this->oldTitle->getNamespace(), 'rd_title' => $this->oldTitle->getDBkey()), __METHOD__); } else { $hasRedirects = false; } if ($considerTalk) { $out->addWikiMsg('movepagetalktext'); } if (count($err)) { $out->addHTML("<div class='error'>\n"); $action_desc = $this->msg('action-move')->plain(); $out->addWikiMsg('permissionserrorstext-withaction', count($err), $action_desc); if (count($err) == 1) { $errMsg = $err[0]; $errMsgName = array_shift($errMsg); if ($errMsgName == 'hookaborted') { $out->addHTML("<p>{$errMsg[0]}</p>\n"); } else { $out->addWikiMsgArray($errMsgName, $errMsg); } } else { $errStr = array(); foreach ($err as $errMsg) { if ($errMsg[0] == 'hookaborted') { $errStr[] = $errMsg[1]; } else { $errMsgName = array_shift($errMsg); $errStr[] = $this->msg($errMsgName, $errMsg)->parse(); } } $out->addHTML('<ul><li>' . implode("</li>\n<li>", $errStr) . "</li></ul>\n"); } $out->addHTML("</div>\n"); } if ($this->oldTitle->isProtected('move')) { # Is the title semi-protected? if ($this->oldTitle->isSemiProtected('move')) { $noticeMsg = 'semiprotectedpagemovewarning'; $classes[] = 'mw-textarea-sprotected'; } else { # Then it must be protected based on static groups (regular) $noticeMsg = 'protectedpagemovewarning'; $classes[] = 'mw-textarea-protected'; } $out->addHTML("<div class='mw-warning-with-logexcerpt'>\n"); $out->addWikiMsg($noticeMsg); LogEventsList::showLogExtract($out, 'protect', $this->oldTitle, '', array('lim' => 1)); $out->addHTML("</div>\n"); } // Byte limit (not string length limit) for wpReason and wpNewTitleMain // is enforced in the mediawiki.special.movePage module $immovableNamespaces = array(); foreach (array_keys($this->getLanguage()->getNamespaces()) as $nsId) { if (!MWNamespace::isMovable($nsId)) { $immovableNamespaces[] = $nsId; } } $handler = ContentHandler::getForTitle($this->oldTitle); $out->enableOOUI(); $fields = array(); $fields[] = new OOUI\FieldLayout(new OOUI\LabelWidget(array('label' => new OOUI\HtmlSnippet("<strong>{$oldTitleLink}</strong>"))), array('label' => $this->msg('movearticle')->text(), 'align' => 'top')); $fields[] = new OOUI\FieldLayout(new MediaWiki\Widget\ComplexTitleInputWidget(array('id' => 'wpNewTitle', 'namespace' => array('id' => 'wpNewTitleNs', 'name' => 'wpNewTitleNs', 'value' => $newTitle->getNamespace(), 'exclude' => $immovableNamespaces), 'title' => array('id' => 'wpNewTitleMain', 'name' => 'wpNewTitleMain', 'value' => $wgContLang->recodeForEdit($newTitle->getText()), 'suggestions' => false), 'infusable' => true)), array('label' => $this->msg('newtitle')->text(), 'align' => 'top')); $fields[] = new OOUI\FieldLayout(new OOUI\TextInputWidget(array('name' => 'wpReason', 'id' => 'wpReason', 'maxLength' => 200, 'infusable' => true, 'value' => $this->reason)), array('label' => $this->msg('movereason')->text(), 'align' => 'top')); if ($considerTalk) { $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpMovetalk', 'id' => 'wpMovetalk', 'value' => '1', 'selected' => $this->moveTalk)), array('label' => $this->msg('movetalk')->text(), 'align' => 'inline')); } if ($user->isAllowed('suppressredirect')) { if ($handler->supportsRedirects()) { $isChecked = $this->leaveRedirect; $isDisabled = false; } else { $isChecked = false; $isDisabled = true; } $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpLeaveRedirect', 'id' => 'wpLeaveRedirect', 'value' => '1', 'selected' => $isChecked, 'disabled' => $isDisabled)), array('label' => $this->msg('move-leave-redirect')->text(), 'align' => 'inline')); } if ($hasRedirects) { $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpFixRedirects', 'id' => 'wpFixRedirects', 'value' => '1', 'selected' => $this->fixRedirects)), array('label' => $this->msg('fix-double-redirects')->text(), 'align' => 'inline')); } if ($canMoveSubpage) { $maximumMovedPages = $this->getConfig()->get('MaximumMovedPages'); $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpMovesubpages', 'id' => 'wpMovesubpages', 'value' => '1', 'selected' => $this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk))), array('label' => new OOUI\HtmlSnippet($this->msg($this->oldTitle->hasSubpages() ? 'move-subpages' : 'move-talk-subpages')->numParams($maximumMovedPages)->params($maximumMovedPages)->parse()), 'align' => 'inline')); } # Don't allow watching if user is not logged in if ($user->isLoggedIn()) { $watchChecked = $user->isLoggedIn() && ($this->watch || $user->getBoolOption('watchmoves') || $user->isWatched($this->oldTitle)); $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpWatch', 'id' => 'watch', 'value' => '1', 'selected' => $watchChecked)), array('label' => $this->msg('move-watch')->text(), 'align' => 'inline')); } if ($confirm) { $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpConfirm', 'id' => 'wpConfirm', 'value' => '1')), array('label' => $this->msg('delete_and_move_confirm')->text(), 'align' => 'inline')); } $fields[] = new OOUI\FieldLayout(new OOUI\ButtonInputWidget(array('name' => $submitVar, 'value' => $movepagebtn, 'label' => $movepagebtn, 'flags' => array('constructive', 'primary'), 'type' => 'submit')), array('align' => 'top')); $fieldset = new OOUI\FieldsetLayout(array('label' => $this->msg('move-page-legend')->text(), 'id' => 'mw-movepage-table', 'items' => $fields)); $form = new OOUI\FormLayout(array('method' => 'post', 'action' => $this->getPageTitle()->getLocalURL('action=submit'), 'id' => 'movepage')); $form->appendContent($fieldset, new OOUI\HtmlSnippet(Html::hidden('wpOldTitle', $this->oldTitle->getPrefixedText()) . Html::hidden('wpEditToken', $user->getEditToken()))); $out->addHTML(new OOUI\PanelLayout(array('classes' => array('movepage-wrapper'), 'expanded' => false, 'padded' => true, 'framed' => true, 'content' => $form))); $this->showLogFragment($this->oldTitle); $this->showSubpages($this->oldTitle); }
/** * Convert talk page links to wall page links for wall enabled wikis * * @param Title $title * @param Title $talkPageTitle * * @return bool */ public static function onGetTalkPage(Title $title, Title &$talkPageTitle) { if (!empty(F::app()->wg->EnableWallExt) && !$title->isSubpage() && $title->getNamespace() == NS_USER) { $talkPageTitle = Title::makeTitle(NS_USER_WALL, $title->getDBkey()); } return true; }
/** * Hook-Handler for 'userCan', prevents foreign access to a users sidebar settings * @param Title $oTitle Title object being checked against * @param User $oUser Current user object * @param string $sAction Action being checked * @param bool $bResult Pointer to result returned if hook returns false. If null is returned, userCan checks are continued by internal code. * @return bool false if the user accesses a UserSidebar Title of another user, true in all other cases. */ public function onUserCan($oTitle, $oUser, $sAction, $bResult) { if ($sAction != 'edit') { return true; } if ($oTitle->getNamespace() != NS_USER || !$oTitle->isSubpage()) { return true; } if (strcasecmp($oTitle->getSubpageText(), 'Sidebar') == 0) { $oBasePage = Title::newFromText($oTitle->getBaseText(), NS_USER); if (!$oBasePage->equals($oUser->getUserPage())) { $bResult = false; return false; } } return true; }
protected function isWAMFAQPage(Title $title) { return $title->isSubpage() && $title->getDBKey() == self::WAM_FAQ_PAGE_NAME; }
/** * Checks if the Title object is a Draft subpage of a template * * @param Title $title * @return bool */ public static function isTitleDraft(Title $title) { return $title->getNamespace() === NS_TEMPLATE && $title->isSubpage() && ($title->getSubpageText() === wfMessage('templatedraft-subpage')->inContentLanguage()->escaped() || $title->getSubpageText() === wfMessage('templatedraft-subpage')->inLanguage('en')->escaped()); }
/** * Adds additional data to links generated by the framework. This allows us * to add more functionality to the UI. * @param SkinTemplate $skin * @param Title $target * @param array $options * @param string $html * @param array $attribs * @param string $ret * @return boolean Always true to keep hook running */ public function onLinkEnd($skin, $target, $options, &$html, &$attribs, &$ret) { if ($target->getNamespace() == NS_USER && $target->isSubpage() === false) { $oUser = User::newFromName($target->getText()); if ($oUser instanceof User) { $sMailAddress = $oUser->getEmail(); $attribs['data-bs-user-has-email'] = empty($sMailAddress) ? false : true; //This is already in BSF, but it is only included when the anchor //content is the same as the username $attribs['data-bs-username'] = $target->getText(); } } if ($target->getNamespace() >= 0 && $target->isContentPage()) { $attribs['data-bs-is-contentpage'] = true; } if ($target->getNamespace() === NS_FILE) { $oFile = wfFindFile($target); if ($oFile instanceof File) { $attribs['data-bs-filename'] = $oFile->getName(); if ($oFile->exists()) { $attribs['data-bs-fileurl'] = $oFile->getUrl(); } } } return true; }