public static function PlusoHeader(&$article, &$outputDone, &$pcache) { global $wgOut, $wgPlusoUserID, $wgPlusoHeader, $wgPlusoMain, $wgPlusoBackgroundHeader, $wgPlusoThemeHeader, $wgPlusoServicesHeader; # Check if page is in content namespace and the setting to enable/disable article header tooblar either on the main page or at all if (!MWNamespace::isContent($article->getTitle()->getNamespace()) || !$wgPlusoHeader || $article->getTitle()->equals(Title::newMainPage()) && !$wgPlusoMain) { return true; } /* Output Pluso header in <h1> */ $wgOut->addHTML(' <script type="text/javascript"> (function() { if (window.pluso)if (typeof window.pluso.start == "function") return; if (window.ifpluso==undefined) { window.ifpluso = 1; var d = document, s = d.createElement("script"), g = "getElementsByTagName"; s.type = "text/javascript"; s.charset="UTF-8"; s.async = true; s.src = ("https:" == window.location.protocol ? "https" : "http") + "://share.pluso.ru/pluso-like.js"; var h=d[g]("body")[0]; h.appendChild(s); } })(); jQuery(document).ready(function() { var title = jQuery("#firstHeading").html(); jQuery("#firstHeading").html(title + \'<div data-user="******" class="pluso" style="float: right;right: 10px;" data-background="' . $wgPlusoBackgroundHeader . '" data-options="medium,round,line,horizontal,counter,theme=' . $wgPlusoThemeHeader . '" data-services="' . $wgPlusoServicesHeader . '"></div>\'); });</script>'); return true; }
/** * Article::view() hook * * @param Article $article * @return bool */ public static function viewHook($article) { global $wgOut; $title = $article->getTitle(); if (MWNamespace::isContent($title->getNamespace())) { $wgOut->addHTML(self::buildLinks($title)); $wgOut->addHeadItem('backandforth', self::buildHeadItem()); } return true; }
function register() { global $wgContLang, $wgNamespaceAliases, $wgNonincludableNamespaces; $lib = array('loadSiteStats' => array($this, 'loadSiteStats'), 'getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup')); $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion()); if (!self::$namespacesCache) { $namespaces = array(); $namespacesByName = array(); foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) { $canonical = MWNamespace::getCanonicalName($ns); $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !($wgNonincludableNamespaces && in_array($ns, $wgNonincludableNamespaces)), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'aliases' => array()); if ($ns >= NS_MAIN) { $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns); $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns); $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns); } else { $namespaces[$ns]['subject'] = $ns; } $namespacesByName[strtr($title, ' ', '_')] = $ns; if ($canonical) { $namespacesByName[$canonical] = $ns; } } $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases()); foreach ($aliases as $title => $ns) { if (!isset($namespacesByName[$title])) { $ct = count($namespaces[$ns]['aliases']); $namespaces[$ns]['aliases'][$ct + 1] = $title; $namespacesByName[$title] = $ns; } } $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->text(); self::$namespacesCache = $namespaces; } $info['namespaces'] = self::$namespacesCache; if (self::$siteStatsLoaded) { $stats = $this->loadSiteStats(); $info['stats'] = $stats[0]; } $this->getEngine()->registerInterface('mw.site.lua', $lib, $info); }
function register() { global $wgContLang, $wgNamespaceAliases, $wgDisableCounters; $lib = array('getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'), 'interwikiMap' => array($this, 'interwikiMap')); $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion()); if (!self::$namespacesCache || self::$namespacesCacheLang !== $wgContLang->getCode()) { $namespaces = array(); $namespacesByName = array(); foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) { $canonical = MWNamespace::getCanonicalName($ns); $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !MWNamespace::isNonincludable($ns), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'defaultContentModel' => MWNamespace::getNamespaceContentModel($ns), 'aliases' => array()); if ($ns >= NS_MAIN) { $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns); $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns); $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns); } else { $namespaces[$ns]['subject'] = $ns; } $namespacesByName[strtr($title, ' ', '_')] = $ns; if ($canonical) { $namespacesByName[$canonical] = $ns; } } $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases()); foreach ($aliases as $title => $ns) { if (!isset($namespacesByName[$title]) && isset($namespaces[$ns])) { $ct = count($namespaces[$ns]['aliases']); $namespaces[$ns]['aliases'][$ct + 1] = $title; $namespacesByName[$title] = $ns; } } $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->inContentLanguage()->text(); self::$namespacesCache = $namespaces; self::$namespacesCacheLang = $wgContLang->getCode(); } $info['namespaces'] = self::$namespacesCache; $info['stats'] = array('pages' => (int) SiteStats::pages(), 'articles' => (int) SiteStats::articles(), 'files' => (int) SiteStats::images(), 'edits' => (int) SiteStats::edits(), 'views' => $wgDisableCounters ? null : (int) SiteStats::views(), 'users' => (int) SiteStats::users(), 'activeUsers' => (int) SiteStats::activeUsers(), 'admins' => (int) SiteStats::numberingroup('sysop')); return $this->getEngine()->registerInterface('mw.site.lua', $lib, $info); }
/** * Function for article header toolbar * * @param $article Article * @param $outputDone * @param $pcache * @return bool|bool */ public static function AddThisHeader(&$article, &$outputDone, &$pcache) { global $wgOut, $wgAddThispubid, $wgAddThis, $wgAddThisHeader, $wgAddThisMain, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder; # Check if page is in content namespace and the setting to enable/disable article header tooblar either on the main page or at all if (!MWNamespace::isContent($article->getTitle()->getNamespace()) || !$wgAddThisHeader || $article->getTitle()->equals(Title::newMainPage()) && !$wgAddThisMain) { return true; } # Localisation for "Share" $share = wfMessage('addthis')->escaped(); # Output AddThis widget $wgOut->addHTML('<!-- AddThis Button BEGIN --> <div class="addthis_toolbox addthis_default_style" id="addthistoolbar" style="background:' . $wgAddThisBackground . '; border-color:' . $wgAddThisBorder . ';"> <a href="//www.addthis.com/bookmark.php?v=250&pubid=' . $wgAddThispubid . '" class="addthis_button_compact"> ' . $share . '</a><span class="addthis_separator"> </span>'); $wgOut->addHTML(self::makeLinks($wgAddThisHServ)); $wgOut->addHTML('</div> <script type="text/javascript" src="//s7.addthis.com/js/250/addthis_widget.js#pubid=' . $wgAddThispubid . '"></script>'); # Output AddThis Address Bar Sharing script, if enabled if ($wgAddThis['addressbarsharing']) { $wgOut->addHTML('<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>'); } return true; }
/** * Is this Title in a namespace which contains content? * In other words, is this a content page, for the purposes of calculating * statistics, etc? * * @return bool */ public function isContentPage() { return MWNamespace::isContent($this->getNamespace()); }
protected function appendNamespaces($property) { global $wgContLang; $data = array(); foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) { $data[$ns] = array('id' => intval($ns), 'case' => MWNamespace::isCapitalized($ns) ? 'first-letter' : 'case-sensitive'); ApiResult::setContent($data[$ns], $title); $canonical = MWNamespace::getCanonicalName($ns); if (MWNamespace::hasSubpages($ns)) { $data[$ns]['subpages'] = ''; } if ($canonical) { $data[$ns]['canonical'] = strtr($canonical, '_', ' '); } if (MWNamespace::isContent($ns)) { $data[$ns]['content'] = ''; } } $this->getResult()->setIndexedTagName($data, 'ns'); return $this->getResult()->addValue('query', $property, $data); }
protected function appendNamespaces($property) { global $wgContLang; $data = array(ApiResult::META_TYPE => 'assoc'); foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) { $data[$ns] = array('id' => intval($ns), 'case' => MWNamespace::isCapitalized($ns) ? 'first-letter' : 'case-sensitive'); ApiResult::setContentValue($data[$ns], 'name', $title); $canonical = MWNamespace::getCanonicalName($ns); $data[$ns]['subpages'] = MWNamespace::hasSubpages($ns); if ($canonical) { $data[$ns]['canonical'] = strtr($canonical, '_', ' '); } $data[$ns]['content'] = MWNamespace::isContent($ns); $data[$ns]['nonincludable'] = MWNamespace::isNonincludable($ns); $contentmodel = MWNamespace::getNamespaceContentModel($ns); if ($contentmodel) { $data[$ns]['defaultcontentmodel'] = $contentmodel; } } ApiResult::setIndexedTagName($data, 'ns'); return $this->getResult()->addValue('query', $property, $data); }
/** * Replace <!--LINK--> link placeholders with actual links, in the buffer * Placeholders created in Skin::makeLinkObj() * Returns an array of links found, indexed by PDBK: * 0 - broken * 1 - normal link * 2 - stub * $options is a bit field, RLH_FOR_UPDATE to select for update */ function replaceLinkHolders(&$text, $options = 0) { global $wgUser; global $wgContLang; $fname = 'Parser::replaceLinkHolders'; wfProfileIn($fname); $pdbks = array(); $colours = array(); $sk = $this->mOptions->getSkin(); $linkCache = LinkCache::singleton(); if (!empty($this->mLinkHolders['namespaces'])) { wfProfileIn($fname . '-check'); $dbr = wfGetDB(DB_SLAVE); $page = $dbr->tableName('page'); $threshold = $wgUser->getOption('stubthreshold'); # Sort by namespace asort($this->mLinkHolders['namespaces']); # Generate query $query = false; $current = null; foreach ($this->mLinkHolders['namespaces'] as $key => $ns) { # Make title object $title = $this->mLinkHolders['titles'][$key]; # Skip invalid entries. # Result will be ugly, but prevents crash. if (is_null($title)) { continue; } $pdbk = $pdbks[$key] = $title->getPrefixedDBkey(); # Check if it's a static known link, e.g. interwiki if ($title->isAlwaysKnown()) { $colours[$pdbk] = 1; } elseif (($id = $linkCache->getGoodLinkID($pdbk)) != 0) { $colours[$pdbk] = 1; $this->mOutput->addLink($title, $id); } elseif ($linkCache->isBadLink($pdbk)) { $colours[$pdbk] = 0; } elseif ($title->getNamespace() == NS_SPECIAL && !SpecialPage::exists($pdbk)) { $colours[$pdbk] = 0; } else { # Not in the link cache, add it to the query if (!isset($current)) { $current = $ns; $query = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect"; $query .= " FROM {$page} WHERE (page_namespace={$ns} AND page_title IN("; } elseif ($current != $ns) { $current = $ns; $query .= ")) OR (page_namespace={$ns} AND page_title IN("; } else { $query .= ', '; } $query .= $dbr->addQuotes($this->mLinkHolders['dbkeys'][$key]); } } if ($query) { $query .= '))'; if ($options & RLH_FOR_UPDATE) { $query .= ' FOR UPDATE'; } $res = $dbr->query($query, $fname); # Fetch data and form into an associative array # non-existent = broken # 1 = known # 2 = stub while ($s = $dbr->fetchObject($res)) { $title = Title::makeTitle($s->page_namespace, $s->page_title); $pdbk = $title->getPrefixedDBkey(); $linkCache->addGoodLinkObj($s->page_id, $title, $s->page_len, $s->page_is_redirect); $this->mOutput->addLink($title, $s->page_id); $colours[$pdbk] = $threshold == 0 || ($s->page_len >= $threshold || $s->page_is_redirect || !MWNamespace::isContent($s->page_namespace)) ? 1 : 2; } } wfProfileOut($fname . '-check'); # Do a second query for different language variants of links and categories if ($wgContLang->hasVariants()) { $linkBatch = new LinkBatch(); $variantMap = array(); // maps $pdbkey_Variant => $keys (of link holders) $categoryMap = array(); // maps $category_variant => $category (dbkeys) $varCategories = array(); // category replacements oldDBkey => newDBkey $categories = $this->mOutput->getCategoryLinks(); // Add variants of links to link batch foreach ($this->mLinkHolders['namespaces'] as $key => $ns) { $title = $this->mLinkHolders['titles'][$key]; if (is_null($title)) { continue; } $pdbk = $title->getPrefixedDBkey(); $titleText = $title->getText(); // generate all variants of the link title text $allTextVariants = $wgContLang->convertLinkToAllVariants($titleText); // if link was not found (in first query), add all variants to query if (!isset($colours[$pdbk])) { foreach ($allTextVariants as $textVariant) { if ($textVariant != $titleText) { $variantTitle = Title::makeTitle($ns, $textVariant); if (is_null($variantTitle)) { continue; } $linkBatch->addObj($variantTitle); $variantMap[$variantTitle->getPrefixedDBkey()][] = $key; } } } } // process categories, check if a category exists in some variant foreach ($categories as $category) { $variants = $wgContLang->convertLinkToAllVariants($category); foreach ($variants as $variant) { if ($variant != $category) { $variantTitle = Title::newFromDBkey(Title::makeName(NS_CATEGORY, $variant)); if (is_null($variantTitle)) { continue; } $linkBatch->addObj($variantTitle); $categoryMap[$variant] = $category; } } } if (!$linkBatch->isEmpty()) { // construct query $titleClause = $linkBatch->constructSet('page', $dbr); $variantQuery = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect"; $variantQuery .= " FROM {$page} WHERE {$titleClause}"; if ($options & RLH_FOR_UPDATE) { $variantQuery .= ' FOR UPDATE'; } $varRes = $dbr->query($variantQuery, $fname); // for each found variants, figure out link holders and replace while ($s = $dbr->fetchObject($varRes)) { $variantTitle = Title::makeTitle($s->page_namespace, $s->page_title); $varPdbk = $variantTitle->getPrefixedDBkey(); $vardbk = $variantTitle->getDBkey(); $holderKeys = array(); if (isset($variantMap[$varPdbk])) { $holderKeys = $variantMap[$varPdbk]; $linkCache->addGoodLinkObj($s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect); $this->mOutput->addLink($variantTitle, $s->page_id); } // loop over link holders foreach ($holderKeys as $key) { $title = $this->mLinkHolders['titles'][$key]; if (is_null($title)) { continue; } $pdbk = $title->getPrefixedDBkey(); if (!isset($colours[$pdbk])) { // found link in some of the variants, replace the link holder data $this->mLinkHolders['titles'][$key] = $variantTitle; $this->mLinkHolders['dbkeys'][$key] = $variantTitle->getDBkey(); // set pdbk and colour $pdbks[$key] = $varPdbk; if ($threshold > 0) { $size = $s->page_len; if ($s->page_is_redirect || $s->page_namespace != 0 || $size >= $threshold) { $colours[$varPdbk] = 1; } else { $colours[$varPdbk] = 2; } } else { $colours[$varPdbk] = 1; } } } // check if the object is a variant of a category if (isset($categoryMap[$vardbk])) { $oldkey = $categoryMap[$vardbk]; if ($oldkey != $vardbk) { $varCategories[$oldkey] = $vardbk; } } } // rebuild the categories in original order (if there are replacements) if (count($varCategories) > 0) { $newCats = array(); $originalCats = $this->mOutput->getCategories(); foreach ($originalCats as $cat => $sortkey) { // make the replacement if (array_key_exists($cat, $varCategories)) { $newCats[$varCategories[$cat]] = $sortkey; } else { $newCats[$cat] = $sortkey; } } $this->mOutput->setCategoryLinks($newCats); } } } # Construct search and replace arrays wfProfileIn($fname . '-construct'); $replacePairs = array(); foreach ($this->mLinkHolders['namespaces'] as $key => $ns) { $pdbk = $pdbks[$key]; $searchkey = "<!--LINK {$key}-->"; $title = $this->mLinkHolders['titles'][$key]; if (empty($colours[$pdbk])) { $linkCache->addBadLinkObj($title); $colours[$pdbk] = 0; $this->mOutput->addLink($title, 0); $replacePairs[$searchkey] = $sk->makeBrokenLinkObj($title, $this->mLinkHolders['texts'][$key], $this->mLinkHolders['queries'][$key]); } elseif ($colours[$pdbk] == 1) { $replacePairs[$searchkey] = $sk->makeKnownLinkObj($title, $this->mLinkHolders['texts'][$key], $this->mLinkHolders['queries'][$key]); } elseif ($colours[$pdbk] == 2) { $replacePairs[$searchkey] = $sk->makeStubLinkObj($title, $this->mLinkHolders['texts'][$key], $this->mLinkHolders['queries'][$key]); } } $replacer = new HashtableReplacer($replacePairs, 1); wfProfileOut($fname . '-construct'); # Do the thing wfProfileIn($fname . '-replace'); $text = preg_replace_callback('/(<!--LINK .*?-->)/', $replacer->cb(), $text); wfProfileOut($fname . '-replace'); } # Now process interwiki link holders # This is quite a bit simpler than internal links if (!empty($this->mInterwikiLinkHolders['texts'])) { wfProfileIn($fname . '-interwiki'); # Make interwiki link HTML $replacePairs = array(); foreach ($this->mInterwikiLinkHolders['texts'] as $key => $link) { $title = $this->mInterwikiLinkHolders['titles'][$key]; $replacePairs[$key] = $sk->makeLinkObj($title, $link); } $replacer = new HashtableReplacer($replacePairs, 1); $text = preg_replace_callback('/<!--IWLINK (.*?)-->/', $replacer->cb(), $text); wfProfileOut($fname . '-interwiki'); } wfProfileOut($fname); return $colours; }
/** * Return the CSS colour of a known link * * @param mixed $s * @param integer $threshold user defined threshold * @return string CSS class */ function getLinkColour($s, $threshold) { if ($s === false) { return ''; } $colour = ''; if (!empty($s->page_is_redirect)) { # Page is a redirect $colour = 'mw-redirect'; } elseif ($threshold > 0 && $s->page_len < $threshold && MWNamespace::isContent($s->page_namespace)) { # Page is a stub $colour = 'stub'; } return $colour; }
/** * Return the CSS colour of a known link * * @param Title $t * @param integer $threshold user defined threshold * @return string CSS class */ function getLinkColour($t, $threshold) { $colour = ''; if ($t->isRedirect()) { # Page is a redirect $colour = 'mw-redirect'; } elseif ($threshold > 0 && $t->exists() && $t->getLength() < $threshold && MWNamespace::isContent($t->getNamespace())) { # Page is a stub $colour = 'stub'; } return $colour; }
/** * Function for tweeting edited articles * * @param $article Article * @param $user User * @param $text string * @param $summary string * @param $minoredit bool * @param $watchthis * @param $sectionanchor * @param $flags * @param $revision * @param $status * @param $baseRevId * @return bool */ public static function TweetANewEditMade( &$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId ) { global $wgTweetANewTweet, $wgTweetANewText, $wgRequest; # Check if $wgTweetANewTweet['Edit'] is enabled or the Tweet checkbox was selected on the edit page if ( $wgRequest->getCheck( 'wpTweetANewEdit' ) || $wgTweetANewTweet['Edit'] ) { # Unless the tweet checkbox is selected, only proceeds if page is outside content namespace # and if a minor edit, checks $wgTweetANewTweet['SkipMinor'] # Also prevents new articles from processing as TweetANewNewArticle function is used instead if ( ( !MWNamespace::isContent( $article->getTitle()->getNamespace() ) || ( $minoredit !== 0 && $wgTweetANewTweet['SkipMinor'] ) && !$wgRequest->getCheck( 'wpTweetANewEdit' ) ) || $article->estimateRevisionCount() == 1 ) { return true; } # Determine the time and date of last modification - exit if newer than $wgTweetANewTweet['LessMinutesOld'] # ToDo - there must be a cleaner way of doing this $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'revision', array( 'rev_timestamp' ), array( 'rev_page' => $article->getId() ), __METHOD__, array( 'ORDER BY' => 'rev_id DESC', 'LIMIT' => '2' ) ); $edittime = array(); foreach ( $res as $row ) { $edittime[] = $row->rev_timestamp; } $edittimenow = mktime( substr( $edittime[0], 8, 2 ), substr( $edittime[0], 10, 2 ), substr( $edittime[0], 12 ), substr( $edittime[0], 4, 2 ), substr( $edittime[0], 6, 2 ), substr( $edittime[0], 0, 4 ) ); $edittimelast = mktime( substr( $edittime[1], 8, 2 ), substr( $edittime[1], 10, 2 ), substr( $edittime[1], 12 ), substr( $edittime[1], 4, 2 ), substr( $edittime[1], 6, 2 ), substr( $edittime[1], 0, 4 ) ); $edittimediv = $edittimenow - $edittimelast; if ( $edittimediv < ( $wgTweetANewTweet['LessMinutesOld'] * 60 ) ) { return true; } # Generate final url $finalurl = self::makeFinalUrl( $article->getTitle()->getFullURL() ); # Generate $author based on $wgTweetANewText['RealName'] if ( $wgTweetANewText['RealName'] ) { $author = $user->getRealName(); } else { $author = $user->getName(); } $tweet_text = ''; # Add prefix indication that edit is minor if enabled by $wgTweetANewText['Minor'] if ( $minoredit !== 0 && $wgTweetANewText['Minor'] ) { $tweet_text = wfMsg( 'tweetanew-minoredit' ); # Add a space after the indicator if $wgTweetANewText['MinorSpace'] is true if ( $minoredit !== 0 && $wgTweetANewText['MinorSpace'] ) { $tweet_text .= ' '; } } # Generate a random tweet texts based if $wgTweetANewText['EditRandom'] is true if ( $wgTweetANewText['EditRandom'] ) { # Setup switcher using max number set by $wgTweetANewText['EditRandomMax'] $switcher = rand( 1, $wgTweetANewText['EditRandomMax'] ); # Parse random text $tweet_text .= wfMsg( 'tweetanew-edit' . $switcher, array( $article->getTitle()->getText(), $finalurl ) ); } else { # Use default tweet message format $tweet_body = wfMsg( 'tweetanew-editdefault', array( $article->getTitle()->getText(), $finalurl ) ); $tweet_text .= $tweet_body; } # Add author info if $wgTweetANewText['EditAuthor'] is true if ( $wgTweetANewText['EditAuthor'] ) { $tweet_text .= ' ' . wfMsg( 'tweetanew-authorcredit' ) . ' ' . $author; } # Add summary if $wgTweetANewText['EditSummary'] is true and summary text is entered if ( $summary && $wgTweetANewText['EditSummary'] ) { $tweet_text .= ' - ' . $summary; } # Call to function for preparing and sending tweet self::makeSendTweet( $tweet_text, $finalurl ); } return true; }
/** * Handler for LinksUpdateAfterInsert hook. * @see http://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateAfterInsert * @param $linksUpdate LinksUpdate * @param $table string * @param $insertions array * @return bool */ public static function onLinksUpdateAfterInsert($linksUpdate, $table, $insertions) { global $wgRequest, $wgUser; // Rollback or undo should not trigger link notification // @Todo Implement a better solution so it doesn't depend on the checking of // a specific set of request variables if ($wgRequest->getVal('wpUndidRevision') || $wgRequest->getVal('action') == 'rollback') { return true; } // Handle only // 1. inserts to pagelinks table && // 2. content namespace pages && // 3. non-transcluding pages && // 4. non-redirect pages if ($table !== 'pagelinks' || !MWNamespace::isContent($linksUpdate->mTitle->getNamespace()) || !$linksUpdate->mRecursive || $linksUpdate->mTitle->isRedirect()) { return true; } // link notification is boundless as you can include infinite number of links in a page // db insert is expensive, limit it to a reasonable amount, we can increase this limit // once the storage is on Redis $max = 10; // Only create notifications for links to content namespace pages // @Todo - use one big insert instead of individual insert inside foreach loop foreach ($insertions as $key => $page) { if (MWNamespace::isContent($page['pl_namespace'])) { $title = Title::makeTitle($page['pl_namespace'], $page['pl_title']); if ($title->isRedirect()) { continue; } EchoEvent::create(array('type' => 'page-linked', 'title' => $title, 'agent' => $wgUser, 'extra' => array('link-from-page-id' => $linksUpdate->mTitle->getArticleId()))); $max--; } if ($max < 0) { break; } } return true; }
/** * Return the CSS colour of a known link * * @since 1.16.3 * @param LinkTarget $t * @param int $threshold User defined threshold * @return string CSS class */ public static function getLinkColour(LinkTarget $t, $threshold) { $linkCache = MediaWikiServices::getInstance()->getLinkCache(); // Make sure the target is in the cache $id = $linkCache->addLinkObj($t); if ($id == 0) { // Doesn't exist return ''; } if ($linkCache->getGoodLinkFieldObj($t, 'redirect')) { # Page is a redirect return 'mw-redirect'; } elseif ($threshold > 0 && MWNamespace::isContent($t->getNamespace()) && $linkCache->getGoodLinkFieldObj($t, 'length') < $threshold) { # Page is a stub return 'stub'; } return ''; }
/** * Similar to testIsContent() but alters the $wgContentNamespaces * global variable. */ public function testIsContentWithAdditionsInWgContentNamespaces() { // NS_MAIN is a content namespace per DefaultSettings.php // and per function definition. $this->assertTrue(MWNamespace::isContent(NS_MAIN)); // Tests that user defined namespace #252 is not content: $this->assertFalse(MWNamespace::isContent(252)); # @todo FIXME: Is global saving really required for PHPUnit? // Bless namespace # 252 as a content namespace global $wgContentNamespaces; $savedGlobal = $wgContentNamespaces; $wgContentNamespaces[] = 252; $this->assertTrue(MWNamespace::isContent(252)); // Makes sure NS_MAIN was not impacted $this->assertTrue(MWNamespace::isContent(NS_MAIN)); // Restore global $wgContentNamespaces = $savedGlobal; // Verify namespaces after global restauration $this->assertTrue(MWNamespace::isContent(NS_MAIN)); $this->assertFalse(MWNamespace::isContent(252)); }