/** * Look for the requested qrcode file. If we don't have the code on file, * first generate then publish it. */ public function showCode($label = false) { // Check for a provided label and use the page URL as default (but force protocol if requested) if ($label) { $this->_label = $label; // should we sanitize this? $this->_uploadComment = $label; } else { $url = parse_url($this->_title->getFullURL()); $url['scheme'] = $this->_scheme ? $this->_scheme : $url['scheme']; //$this->_label = http_build_url($url); // http_build_url is part of pecl_http >= 0.21.0 :( $this->_label = $url['scheme'] . '://' . $url['host'] . (isset($url['port']) ? $url['port'] : '') . (isset($url['path']) ? $url['path'] : '') . (isset($url['query']) ? '?' . $url['query'] : '') . (isset($url['fragment']) ? '#' . $url['fragment'] : ''); $this->_uploadComment = 'Encoded URL for ' . $this->_title->getFullText(); } // Use this page's title as part of the filename (Also regenerates qrcodes when the label changes). $this->_dstFileName = 'QR-' . md5($this->_label) . '.png'; $file = wfFindFile($this->_dstFileName); // Shortcut for RepoGroup::singleton()->findFile() if ($file && $file->isVisible()) { wfDebug("QrCode::showCode: Requested file " . $this->_dstFileName . " already exists. Displaying image.\n"); return $this->_displayImage($file); } else { wfDebug("QrCode::showCode: Requested file " . $this->_dstFileName . " is new and needs to be generated.\n"); $this->_generate(); return; } }
/** * Get the text to display in the language box for specific language and * level. * * @param $name string * @param $language String: Language code of language to use. * @param $level String: Level to use. * @return String: Text for display, in wikitext format. */ protected static function mGetText($name, $language, $level) { wfProfileIn(__METHOD__); global $wgBabelMainCategory, $wgBabelCategoryNames; if ($wgBabelCategoryNames[$level] === false) { $categoryLevel = self::$title->getFullText(); } else { $categoryLevel = ':Category:' . self::mReplaceCategoryVariables($wgBabelCategoryNames[$level], $language); } if ($wgBabelMainCategory === false) { $categoryMain = self::$title->getFullText(); } else { $categoryMain = ':Category:' . self::mReplaceCategoryVariables($wgBabelMainCategory, $language); } // Give grep a chance to find the usages: // babel-0-n, babel-1-n, babel-2-n, babel-3-n, babel-4-n, babel-5-n, babel-N-n $text = wfMessage("babel-{$level}-n", $categoryLevel, $categoryMain, '', self::$title->getDBkey())->inLanguage($language)->text(); $fallbackLanguage = Language::getFallbackfor($language); $fallback = wfMessage("babel-{$level}-n", $categoryLevel, $categoryMain, '', self::$title->getDBkey())->inLanguage($fallbackLanguage ? $fallbackLanguage : $language)->text(); // Give grep a chance to find the usages: // babel-0, babel-1, babel-2, babel-3, babel-4, babel-5, babel-N if ($text == $fallback) { $text = wfMessage("babel-{$level}", $categoryLevel, $categoryMain, $name, self::$title->getDBkey())->inLanguage($language)->text(); } wfProfileOut(__METHOD__); return $text; }
/** * Returns the data for the tag in an array, or false is there is no data. * * @since 0.1 * * @param Title $titleObject * @param string $tagName * * @return false or array */ protected static function getCurrentRatingForTag(Title $titleObject, $tagName) { $title = $titleObject->getFullText(); if (!array_key_exists($title, self::$pageRatings)) { self::$pageRatings[$title] = array(); // The keys are the tag ids, but they are not known here, so change to tag names, which are known. foreach (self::getPageRatings($titleObject) as $tagId => $tagData) { self::$pageRatings[$title][$tagData['name']] = array_merge(array('id' => $tagId), $tagData); } } return array_key_exists($tagName, self::$pageRatings[$title]) ? self::$pageRatings[$title][$tagName] : false; }
/** * Displays some shorts statistics about the dictionary page. * * @since 0.4 * * @param Article $article * @param Title $title */ protected static function displayDictionaryPage(Article &$article, Title $title) { global $wgOut, $wgLang, $wgUser, $egLiveTranslateLanguages; $dbr = wfGetDb(DB_SLAVE); $res = $dbr->select('live_translate_memories', array('memory_lang_count', 'memory_tu_count'), array('memory_location' => $title->getFullText()), array('LIMIT' => 1)); foreach ($res as $tm) { break; } if ($tm->memory_tu_count == 0) { $wgOut->addWikiMsg('livetranslate-dictionary-empty'); } else { $wgOut->addWikiMsg('livetranslate-dictionary-count', $wgLang->formatNum($tm->memory_tu_count), $wgLang->formatNum($tm->memory_lang_count)); /* $notAllowedLanguages = array(); foreach ( $tus[0]->getVariants() as $languageCode => $translations ) { $languageCode = strtolower( $languageCode ); $mappings = LiveTranslateFunctions::getInputLangMapping(); if ( array_key_exists( $languageCode, $mappings ) ) { $languageCode = $mappings[$languageCode]; } if ( !in_array( $languageCode, $egLiveTranslateLanguages ) ) { $notAllowedLanguages[] = $languageCode; } } if ( count( $notAllowedLanguages ) > 0 ) { $languages = Language::getLanguageNames( false ); foreach ( $notAllowedLanguages as &$notAllowedLang ) { if ( array_key_exists( $notAllowedLang, $languages ) ) { $notAllowedLang = $languages[$notAllowedLang]; } } $wgOut->addHTML( Html::element( 'span', array( 'style' => 'color:darkred' ), wfMsgExt( 'livetranslate-dictionary-unallowed-langs', 'parsemag', $wgLang->listToText( $notAllowedLanguages ), count( $notAllowedLanguages ) ) ) ); } */ } if ($wgUser->isAllowed('managetms')) { $wgOut->addHTML(Html::element('a', array('href' => Title::newFromText('Special:LiveTranslate')->getInternalURL()), wfMsg('livetranslate-dictionary-goto-edit'))); } }
/** * Returns a WikitextContent object representing a redirect to the given destination page. * * @param Title $destination The page to redirect to. * @param string $text Text to include in the redirect, if possible. * * @return Content * * @see ContentHandler::makeRedirectContent */ public function makeRedirectContent(Title $destination, $text = '') { $optionalColon = ''; if ($destination->getNamespace() == NS_CATEGORY) { $optionalColon = ':'; } else { $iw = $destination->getInterwiki(); if ($iw && Language::fetchLanguageName($iw, null, 'mw')) { $optionalColon = ':'; } } $mwRedir = MagicWord::get('redirect'); $redirectText = $mwRedir->getSynonym(0) . ' [[' . $optionalColon . $destination->getFullText() . ']]'; if ($text != '') { $redirectText .= "\n" . $text; } return new WikitextContent($redirectText); }
/** * Add redirect link to the article * @param Title $title * @param Title $newTitle * @return Status $status */ public function addRedirectLink($title, $newTitle) { wfProfileIn(__METHOD__); $article = new Article($title); $content = "#REDIRECT [[{$newTitle->getPrefixedText()}]]"; $summary = wfMessage('autoredircomment', $title->getFullText())->inContentLanguage()->text(); $status = $article->doEdit($content, $summary); wfProfileOut(__METHOD__); return $status; }
/** * @global bool $wgLanguageLinks; * @param Skin $skin * @param Title $target * @param string $text * @param array $customAttribs * @param array $query * @param array $options * @param mixed $ret default: null * @return bool */ public static function hookLinkBegin($skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret) { # first make link known. $brokenKey = array_search(self::LINK_OPTION_BROKEN, $options); if ($brokenKey !== false) { $options[$brokenKey] = self::LINK_OPTION_KNOWN; } else { if (array_search(self::LINK_OPTION_KNOWN, $options) === false) { $options[] = self::LINK_OPTION_KNOWN; } } $targetNamespace = $target->getNamespace(); if ($targetNamespace == NS_FILE || ${$targetNamespace} == NS_FILE_TALK) { global $wgFileLinks; return $wgFileLinks; } else { if ($targetNamespace == NS_CATEGORY || $targetNamespace == NS_CATEGORY_TALK) { global $wgCategoryLinks; return $wgCategoryLinks; } } # try detect language link $titleText = $target->getUserCaseDBKey(); #echo PHP_EOL . "TitleText: {$titleText} -- NameSpace: {$target->getNamespaceKey()}"; $titleExploded = explode(':', $titleText, 2); if (array_key_exists(1, $titleExploded)) { $languageKey = $titleExploded[0]; #echo PHP_EOL . "Title maybe a LanguageLink: {$languageKey}"; if (array_key_exists($languageKey, self::getLanguageNames())) { global $wgLanguageLinks; self::$detectedLanguageLinks[] = $target->getFullText(); #echo PHP_EOL . "LanguageLink detected: {$languageKey} $titleExploded[1]"; return $wgLanguageLinks; } else { return true; } } else { return true; } }
/** * Obtains the needed edit token by making an HTTP GET request * to the remote wikis API. * * @since 0.5 * * @param Title $title * @param string $target * * @return string or false */ protected function getEditToken(Title $title, $target) { $requestData = array('action' => 'query', 'format' => 'json', 'intoken' => 'edit', 'prop' => 'info', 'titles' => $title->getFullText()); $parts = array(); foreach ($requestData as $key => $value) { $parts[] = $key . '=' . urlencode($value); } $req = PushFunctions::getHttpRequest($target . '?' . implode('&', $parts), array('method' => 'GET', 'timeout' => 'default')); if (array_key_exists($target, $this->cookieJars)) { $req->setCookieJar($this->cookieJars[$target]); } $status = $req->execute(); $response = $status->isOK() ? FormatJson::decode($req->getContent()) : null; $token = false; if (!is_null($response) && property_exists($response, 'query') && property_exists($response->query, 'pages') && count($response->query->pages) > 0) { foreach ($response->query->pages as $key => $value) { $first = $key; break; } if (property_exists($response->query->pages->{$first}, 'edittoken')) { $token = $response->query->pages->{$first}->edittoken; } elseif (!is_null($response) && property_exists($response, 'query') && property_exists($response->query, 'error')) { $this->dieUsage($response->query->error->message, 'token-request-failed'); } else { $this->dieUsage(wfMsg('push-special-err-token-failed'), 'token-request-failed'); } } else { $this->dieUsage(wfMsg('push-special-err-token-failed'), 'token-request-failed'); } return $token; }
/** * Get some extra buttons for another footer * @param $title Title * @return string */ protected function getSecondFooter(Title $title) { $html = ''; if ($title->userCan('edit')) { $html .= new OOUI\ButtonWidget(['label' => wfMessage('collaborationkit-hub-manage')->inContentLanguage()->text(), 'href' => $title->getLocalURL(['action' => 'edit']), 'flags' => ['primary', 'progressive']]); // TODO make sure they have create permission, too $html .= new OOUI\ButtonWidget(['label' => wfMessage('collaborationkit-hub-addpage')->inContentLanguage()->text(), 'href' => SpecialPage::getTitleFor('CreateHubFeature')->getFullUrl(['collaborationhub' => $title->getFullText()]), 'flags' => ['primary', 'progressive']]); } return $html; }
public static function getInterWikiaURL(Title &$title, &$url, $query) { global $wgArticlePath, $wgScriptPath; if (in_array($title->mInterwiki, array('w', 'wikia', 'wikicities'))) { $aLinkParts = explode(':', $title->getFullText()); if ($aLinkParts[1] == 'c') { $iCityId = self::isWikiExists($aLinkParts[2]); if ($iCityId) { $sArticlePath = WikiFactory::getVarValueByName('wgArticlePath', $iCityId); //I've replaced wgArticlePath to hardcoded value in order to fix FogBug:3066 //This is a persistent issue with getting default value of variable that is not set in WikiFactory //Similar problem exists when displaying "default value" in WikiFactory - it's not the real default (taken from file) //it's value for current wiki (community for WikiFactory, www.wikia.com for 3066 bug) //anyway - current value in CommonSettings.php for wgArticlePath is '/wiki/$1' that's why this hardcoded //fix will work.. for now.. it would be nice to introduce some function to get REAL DEFAULT VALUE for any variable //Marooned $sArticlePath = !empty($sArticlePath) ? $sArticlePath : '/wiki/$1'; //$wgArticlePath; /* $wgScriptPath is already included in city_url $sScriptPath = WikiFactory::getVarValueByName('wgScriptPath', $iCityId); $sScriptPath = !empty($sScriptPath) ? $sScriptPath : $wgScriptPath; */ if (!empty($sArticlePath)) { $sArticleTitle = ''; for ($i = 3; $i < count($aLinkParts); $i++) { $sArticleTitle .= (!empty($sArticleTitle) ? ':' : '') . $aLinkParts[$i]; } //RT#54264,#41254 $sArticleTitle = str_replace(' ', '_', $sArticleTitle); $sArticleTitle = urlencode($sArticleTitle); $sCityUrl = self::getCityUrl($iCityId); if (!empty($sCityUrl)) { $url = str_replace('$1', $sArticleTitle, $sArticlePath); $url = $sCityUrl . $url; } } } } } return true; }
/** * Returns an array with details for a talk button. * @param Title $talkTitle Title object of the talk page * @param array $talkButton Array with data of desktop talk button * @return array */ protected function getTalkButton($talkTitle, $talkButton) { return array('attributes' => array('href' => $talkTitle->getLinkURL(), 'data-title' => $talkTitle->getFullText(), 'class' => MobileUI::iconClass('talk', 'before', 'talk')), 'label' => $talkButton['text']); }
/** * Provided a page, returns the string value of that page's title * This allows us to accommodate unconventional locations for titles * @param \Title $title * @return string */ protected function getTitleString(\Title $title) { wfProfileIn(__METHOD__); if (in_array($title->getNamespace(), array(NS_WIKIA_FORUM_BOARD_THREAD, NS_USER_WALL_MESSAGE))) { $wm = \WallMessage::newFromId($title->getArticleID()); if ($wm) { $wm->load(); if (!$wm->isMain() && ($main = $wm->getTopParentObj()) && !empty($main)) { $main->load(); $wm = $main; } wfProfileOut(__METHOD__); return (string) $wm->getMetaTitle(); } else { \Wikia\Logger\WikiaLogger::instance()->warning('Null WallMessage', ['message_id' => $title->getArticleID()]); } } wfProfileOut(__METHOD__); return $title->getFullText(); }
/** * @param Title $title * @param bool $parser * * @return array */ static function statelessFetchTemplate($title, $parser = false) { $text = "Content of ''" . $title->getFullText() . "''"; $deps = []; return ['text' => $text, 'finalTitle' => $title, 'deps' => $deps]; }
/** * Initialize a new instance from a database row. * * @access public * @param array Database Row * @param object \DPL\Parameters Object * @param object Mediawiki Title Object * @param integer Page Namespace ID * @param string Page Title as Selected from Query * @return object \DPL\Article Object */ public static function newFromRow($row, Parameters $parameters, \Title $title, $pageNamespace, $pageTitle) { global $wgLang, $wgContLang; $article = new Article($title, $pageNamespace); $titleText = $title->getText(); if ($parameters->getParameter('shownamespace') === true) { $titleText = $title->getPrefixedText(); } if ($parameters->getParameter('replaceintitle') !== null) { $titleText = preg_replace($parameters->getParameter('replaceintitle')[0], $parameters->getParameter('replaceintitle')[1], $titleText); } //Chop off title if longer than the 'titlemaxlen' parameter. if ($parameters->getParameter('titlemaxlen') !== null && strlen($titleText) > $parameters->getParameter('titlemaxlen')) { $titleText = substr($titleText, 0, $parameters->getParameter('titlemaxlen')) . '...'; } if ($parameters->getParameter('showcurid') === true && isset($row['page_id'])) { $articleLink = '[' . $title->getLinkURL(['curid' => $row['page_id']]) . ' ' . htmlspecialchars($titleText) . ']'; } else { $articleLink = '[[' . ($parameters->getParameter('escapelinks') && ($pageNamespace == NS_CATEGORY || $pageNamespace == NS_FILE) ? ':' : '') . $title->getFullText() . '|' . htmlspecialchars($titleText) . ']]'; } $article->mLink = $articleLink; //get first char used for category-style output if (isset($row['sortkey'])) { $article->mStartChar = $wgContLang->convert($wgContLang->firstChar($row['sortkey'])); } else { $article->mStartChar = $wgContLang->convert($wgContLang->firstChar($pageTitle)); } $article->mID = intval($row['page_id']); //External link if (isset($row['el_to'])) { $article->mExternalLink = $row['el_to']; } //SHOW PAGE_COUNTER if (isset($row['page_counter'])) { $article->mCounter = $row['page_counter']; } //SHOW PAGE_SIZE if (isset($row['page_len'])) { $article->mSize = $row['page_len']; } //STORE initially selected PAGE if (count($parameters->getParameter('linksto')) || count($parameters->getParameter('linksfrom'))) { if (!isset($row['sel_title'])) { $article->mSelTitle = 'unknown page'; $article->mSelNamespace = 0; } else { $article->mSelTitle = $row['sel_title']; $article->mSelNamespace = $row['sel_ns']; } } //STORE selected image if (count($parameters->getParameter('imageused')) > 0) { if (!isset($row['image_sel_title'])) { $article->mImageSelTitle = 'unknown image'; } else { $article->mImageSelTitle = $row['image_sel_title']; } } if ($parameters->getParameter('goal') != 'categories') { //REVISION SPECIFIED if ($parameters->getParameter('lastrevisionbefore') || $parameters->getParameter('allrevisionsbefore') || $parameters->getParameter('firstrevisionsince') || $parameters->getParameter('allrevisionssince')) { $article->mRevision = $row['rev_id']; $article->mUser = $row['rev_user_text']; $article->mDate = $row['rev_timestamp']; $article->mComment = $row['rev_comment']; } //SHOW "PAGE_TOUCHED" DATE, "FIRSTCATEGORYDATE" OR (FIRST/LAST) EDIT DATE if ($parameters->getParameter('addpagetoucheddate')) { $article->mDate = $row['page_touched']; } elseif ($parameters->getParameter('addfirstcategorydate')) { $article->mDate = $row['cl_timestamp']; } elseif ($parameters->getParameter('addeditdate') && isset($row['rev_timestamp'])) { $article->mDate = $row['rev_timestamp']; } elseif ($parameters->getParameter('addeditdate') && isset($row['page_touched'])) { $article->mDate = $row['page_touched']; } //Time zone adjustment if ($article->mDate) { $article->mDate = $wgLang->userAdjust($article->mDate); } if ($article->mDate && $parameters->getParameter('userdateformat')) { //Apply the userdateformat $article->myDate = gmdate($parameters->getParameter('userdateformat'), wfTimeStamp(TS_UNIX, $article->mDate)); } // CONTRIBUTION, CONTRIBUTOR if ($parameters->getParameter('addcontribution')) { $article->mContribution = $row['contribution']; $article->mContributor = $row['contributor']; $article->mContrib = substr('*****************', 0, round(log($row['contribution']))); } //USER/AUTHOR(S) // because we are going to do a recursive parse at the end of the output phase // we have to generate wiki syntax for linking to a user´s homepage if ($parameters->getParameter('adduser') || $parameters->getParameter('addauthor') || $parameters->getParameter('addlasteditor')) { $article->mUserLink = '[[User:'******'rev_user_text'] . '|' . $row['rev_user_text'] . ']]'; $article->mUser = $row['rev_user_text']; } //CATEGORY LINKS FROM CURRENT PAGE if ($parameters->getParameter('addcategories') && $row['cats']) { $artCatNames = explode(' | ', $row['cats']); foreach ($artCatNames as $artCatName) { $article->mCategoryLinks[] = '[[:Category:' . $artCatName . '|' . str_replace('_', ' ', $artCatName) . ']]'; $article->mCategoryTexts[] = str_replace('_', ' ', $artCatName); } } // PARENT HEADING (category of the page, editor (user) of the page, etc. Depends on ordermethod param) if ($parameters->getParameter('headingmode') != 'none') { switch ($parameters->getParameter('ordermethod')[0]) { case 'category': //Count one more page in this heading self::$headings[$row['cl_to']] = isset(self::$headings[$row['cl_to']]) ? self::$headings[$row['cl_to']] + 1 : 1; if ($row['cl_to'] == '') { //uncategorized page (used if ordermethod=category,...) $article->mParentHLink = '[[:Special:Uncategorizedpages|' . wfMsg('uncategorizedpages') . ']]'; } else { $article->mParentHLink = '[[:Category:' . $row['cl_to'] . '|' . str_replace('_', ' ', $row['cl_to']) . ']]'; } break; case 'user': self::$headings[$row['rev_user_text']] = isset(self::$headings[$row['rev_user_text']]) ? self::$headings[$row['rev_user_text']] + 1 : 1; if ($row['rev_user'] == 0) { //anonymous user $article->mParentHLink = '[[User:'******'rev_user_text'] . '|' . $row['rev_user_text'] . ']]'; } else { $article->mParentHLink = '[[User:'******'rev_user_text'] . '|' . $row['rev_user_text'] . ']]'; } break; } } } return $article; }
/** * Gets nice HTML text for title object containing the link to article page * and also into edit, delete and article history pages. */ function getSlackTitleText(Title $title) { global $wgWikiUrl, $wgWikiUrlEnding, $wgWikiUrlEndingEditArticle, $wgWikiUrlEndingDeleteArticle, $wgWikiUrlEndingHistory; $titleName = $title->getFullText(); return sprintf("%s (%s | %s | %s)", "<" . $wgWikiUrl . $wgWikiUrlEnding . $titleName . "|" . $titleName . ">", "<" . $wgWikiUrl . $wgWikiUrlEnding . $titleName . "&" . $wgWikiUrlEndingEditArticle . "|edit>", "<" . $wgWikiUrl . $wgWikiUrlEnding . $titleName . "&" . $wgWikiUrlEndingDeleteArticle . "|delete>", "<" . $wgWikiUrl . $wgWikiUrlEnding . $titleName . "&" . $wgWikiUrlEndingHistory . "|history>"); }
/** * @see Content::updateRedirect() * * This implementation replaces the first link on the page with the given new target * if this Content object is a redirect. Otherwise, this method returns $this. * * @since 1.21 * * @param Title $target * * @return Content a new Content object with the updated redirect (or $this if this Content object isn't a redirect) */ public function updateRedirect(Title $target) { if (!$this->isRedirect()) { return $this; } # Fix the text # Remember that redirect pages can have categories, templates, etc., # so the regex has to be fairly general $newText = preg_replace('/ \\[ \\[ [^\\]]* \\] \\] /x', '[[' . $target->getFullText() . ']]', $this->getNativeData(), 1); return new WikitextContent($newText); }
/** * Builds a set of locations with the provided title, text and icon. * * @since 1.0 * * @param MapsLocation[] $locations * @param string $text * @param string $icon * @param array $properties * @param Title|null $title * * @return MapsLocation[] */ protected function buildLocationsList(array $locations, $text, $icon, array $properties, Title $title = null) { if ($this->template) { global $wgParser; $parser = $wgParser; } else { $text .= implode('<br />', $properties); } if ($title === null) { $titleOutput = ''; } else { $titleOutput = $this->hideNamespace ? $title->getText() : $title->getFullText(); } foreach ($locations as &$location) { if ($this->template) { $segments = array_merge(array($this->template, 'title=' . $titleOutput, 'latitude=' . $location->getLatitude(), 'longitude=' . $location->getLongitude()), $properties); $text .= $parser->parse('{{' . implode('|', $segments) . '}}', $parser->getTitle(), new ParserOptions())->getText(); } $location->setTitle($titleOutput); $location->setText($text); $location->setIcon($icon); } return $locations; }
/** * Pushes the page content to the specified wiki. * * @since 0.3 * * @param Title $title * @param array $revision * @param string $target * @param string $token */ protected function pushToTarget(Title $title, array $revision, $target, $token) { global $wgSitename; $summary = wfMsgExt('push-import-revision-message', 'parsemag', $wgSitename); $requestData = array('action' => 'edit', 'title' => $title->getFullText(), 'format' => 'json', 'summary' => $summary, 'text' => $revision['*'], 'token' => $token); $req = PushFunctions::getHttpRequest($target, array('method' => 'POST', 'timeout' => 'default', 'postData' => $requestData)); if (array_key_exists($target, $this->cookieJars)) { $req->setCookieJar($this->cookieJars[$target]); } $status = $req->execute(); if ($status->isOK()) { $response = $req->getContent(); $this->editResponses[] = $response; Hooks::run('PushAPIAfterPush', array($title, $revision, $target, $token, $response)); } else { $this->dieUsage(wfMsg('push-special-err-push-failed'), 'page-push-failed'); } }
/** * Edit a Collaboration Hub via the edit API * @param $title Title * @param $displayName string * @param $icon string * @param $colour string * @param $introduction string * @param $footer string * @param $content array * @param $summary string Message key for edit summary * @param $context IContextSource The calling context * @return Status */ public static function edit(Title $title, $displayName, $image, $colour, $introduction, $footer, $content, $summary, IContextSource $context) { $contentBlock = ['display_name' => $displayName, 'introduction' => $introduction, 'footer' => $footer, 'image' => $image, 'colour' => $colour, 'content' => $content]; // TODO Do content $jsonText = FormatJson::encode($contentBlock); if ($jsonText === null) { return Status::newFatal('collaborationkit-hub-edit-tojsonerror'); } // Ensure that a valid context is provided to the API in unit tests $der = new DerivativeContext($context); $request = new DerivativeRequest($context->getRequest(), ['action' => 'edit', 'title' => $title->getFullText(), 'contentmodel' => 'CollaborationHubContent', 'text' => $jsonText, 'summary' => $summary, 'token' => $context->getUser()->getEditToken()], true); $der->setRequest($request); try { $api = new ApiMain($der, true); $api->execute(); } catch (UsageException $e) { return Status::newFatal($context->msg('collaborationkit-hub-edit-apierror', $e->getCodeString())); } return Status::newGood(); }
/** * Returns an array with details for a talk button. * @param Title $talkTitle Title object of the talk page * @param array $talkButton Array with data of desktop talk button * @return array */ protected function getTalkButton($talkTitle, $talkButton) { return array('attributes' => array('href' => $talkTitle->getLinkURL(), 'data-title' => $talkTitle->getFullText(), 'class' => 'talk'), 'label' => $talkButton['text']); }
/** * @param $title Title * @param $summary string * @param $context IContextSource * @todo rework this to use a generic CollaborationList editor function once it exists */ public static function postMemberList(Title $title, $summary, IContextSource $context) { $username = $context->getUser()->getName(); $collabList = self::makeMemberList($username, $context->msg('collaborationkit-hub-members-description')); // Ensure that a valid context is provided to the API in unit tests $der = new DerivativeContext($context); $request = new DerivativeRequest($context->getRequest(), ['action' => 'edit', 'title' => $title->getFullText(), 'contentmodel' => 'CollaborationListContent', 'contentformat' => 'application/json', 'text' => $collabList->serialize(), 'summary' => $summary, 'token' => $context->getUser()->getEditToken()], true); $der->setRequest($request); try { $api = new ApiMain($der, true); $api->execute(); } catch (UsageException $e) { return Status::newFatal($context->msg('collaborationkit-hub-edit-apierror', $e->getCodeString())); } return Status::newGood(); }