/** * Get the footer with user information (when joined, how * many edits/uploads, visit user page and talk page) * @return string */ protected function getUserFooterData() { $fromDate = $this->targetUser->getRegistration(); $ts = new MWTimestamp(wfTimestamp(TS_UNIX, $fromDate)); $diff = $ts->diff(new MWTimestamp()); if ($fromDate === null) { // User was registered in pre-historic times when registration wasn't recorded $msg = 'mobile-frontend-profile-footer-ancient'; $units = 0; $fromDate = '20010115000000'; // No users before that date } elseif ($diff->y) { $msg = 'mobile-frontend-profile-footer-years'; $units = $diff->y; } elseif ($diff->m) { $msg = 'mobile-frontend-profile-footer-months'; $units = $diff->m; } else { $msg = 'mobile-frontend-profile-footer-days'; $units = $diff->d; } $editCount = $this->targetUser->getEditCount(); $uploadCount = $this->userInfo->countRecentUploads($fromDate); // Ensure that the upload count is compatible with the i18n message if ($uploadCount > 500) { $uploadCount = 500; } $username = $this->targetUser->getName(); return array('editsSummary' => $this->msg($msg, $username)->numParams($units, $editCount, $uploadCount)->parse(), 'linkUserPage' => Linker::link($this->targetUser->getUserPage(), $this->msg('mobile-frontend-profile-userpage-link', $username)->escaped()), 'linkTalk' => $this->getTalkLink()); }
/** * As recCheckCondition, but *not* recursive. The only valid conditions * are those whose first element is APCOND_EMAILCONFIRMED/APCOND_EDITCOUNT/ * APCOND_AGE. Other types will throw an exception if no extension evalu- * ates them. * * @param $cond Array: A condition, which must not contain other conditions * @param $user User The user to check the condition against * @return bool Whether the condition is true for the user */ private static function checkCondition($cond, User $user) { global $wgEmailAuthentication, $wgEnableEditCountLocal; if (count($cond) < 1) { return false; } switch ($cond[0]) { case APCOND_EMAILCONFIRMED: if (Sanitizer::validateEmail($user->getEmail())) { if ($wgEmailAuthentication) { return (bool) $user->getEmailAuthenticationTimestamp(); } else { return true; } } return false; case APCOND_EDITCOUNT: if (!empty($wgEnableEditCountLocal)) { return $user->getEditCountLocal() >= $cond[1]; } else { return $user->getEditCount() >= $cond[1]; } case APCOND_AGE: $age = time() - wfTimestampOrNull(TS_UNIX, $user->getRegistration()); return $age >= $cond[1]; case APCOND_AGE_FROM_EDIT: $age = time() - wfTimestampOrNull(TS_UNIX, $user->getFirstEditTimestamp()); return $age >= $cond[1]; case APCOND_INGROUPS: $groups = array_slice($cond, 1); return count(array_intersect($groups, $user->getGroups())) == count($groups); case APCOND_ISIP: return $cond[1] == $user->getRequest()->getIP(); case APCOND_IPINRANGE: return IP::isInRange($user->getRequest()->getIP(), $cond[1]); case APCOND_BLOCKED: return $user->isBlocked(); case APCOND_ISBOT: return in_array('bot', User::getGroupPermissions($user->getGroups())); default: $result = null; wfRunHooks('AutopromoteCondition', array($cond[0], array_slice($cond, 1), $user, &$result)); if ($result === null) { throw new MWException("Unrecognized condition {$cond[0]} for autopromotion!"); } return (bool) $result; } }
/** * @param User $user * @param IContextSource $context * @param array $defaultPreferences * @return void */ static function profilePreferences($user, IContextSource $context, &$defaultPreferences) { global $wgAuth, $wgContLang, $wgParser; $config = $context->getConfig(); // retrieving user name for GENDER and misc. $userName = $user->getName(); # # User info ##################################### // Information panel $defaultPreferences['username'] = array('type' => 'info', 'label-message' => array('username', $userName), 'default' => $userName, 'section' => 'personal/info'); # Get groups to which the user belongs $userEffectiveGroups = $user->getEffectiveGroups(); $userGroups = $userMembers = array(); foreach ($userEffectiveGroups as $ueg) { if ($ueg == '*') { // Skip the default * group, seems useless here continue; } $groupName = User::getGroupName($ueg); $userGroups[] = User::makeGroupLinkHTML($ueg, $groupName); $memberName = User::getGroupMember($ueg, $userName); $userMembers[] = User::makeGroupLinkHTML($ueg, $memberName); } asort($userGroups); asort($userMembers); $lang = $context->getLanguage(); $defaultPreferences['usergroups'] = array('type' => 'info', 'label' => $context->msg('prefs-memberingroups')->numParams(count($userGroups))->params($userName)->parse(), 'default' => $context->msg('prefs-memberingroups-type')->rawParams($lang->commaList($userGroups), $lang->commaList($userMembers))->escaped(), 'raw' => true, 'section' => 'personal/info'); $editCount = Linker::link(SpecialPage::getTitleFor("Contributions", $userName), $lang->formatNum($user->getEditCount())); $defaultPreferences['editcount'] = array('type' => 'info', 'raw' => true, 'label-message' => 'prefs-edits', 'default' => $editCount, 'section' => 'personal/info'); if ($user->getRegistration()) { $displayUser = $context->getUser(); $userRegistration = $user->getRegistration(); $defaultPreferences['registrationdate'] = array('type' => 'info', 'label-message' => 'prefs-registration', 'default' => $context->msg('prefs-registration-date-time', $lang->userTimeAndDate($userRegistration, $displayUser), $lang->userDate($userRegistration, $displayUser), $lang->userTime($userRegistration, $displayUser))->parse(), 'section' => 'personal/info'); } $canViewPrivateInfo = $user->isAllowed('viewmyprivateinfo'); $canEditPrivateInfo = $user->isAllowed('editmyprivateinfo'); // Actually changeable stuff $defaultPreferences['realname'] = array('type' => $canEditPrivateInfo && $wgAuth->allowPropChange('realname') ? 'text' : 'info', 'default' => $user->getRealName(), 'section' => 'personal/info', 'label-message' => 'yourrealname', 'help-message' => 'prefs-help-realname'); if ($canEditPrivateInfo && $wgAuth->allowPasswordChange()) { $link = Linker::link(SpecialPage::getTitleFor('ChangePassword'), $context->msg('prefs-resetpass')->escaped(), array(), array('returnto' => SpecialPage::getTitleFor('Preferences')->getPrefixedText())); $defaultPreferences['password'] = array('type' => 'info', 'raw' => true, 'default' => $link, 'label-message' => 'yourpassword', 'section' => 'personal/info'); } // Only show prefershttps if secure login is turned on if ($config->get('SecureLogin') && wfCanIPUseHTTPS($context->getRequest()->getIP())) { $defaultPreferences['prefershttps'] = array('type' => 'toggle', 'label-message' => 'tog-prefershttps', 'help-message' => 'prefs-help-prefershttps', 'section' => 'personal/info'); } // Language $languages = Language::fetchLanguageNames(null, 'mw'); $languageCode = $config->get('LanguageCode'); if (!array_key_exists($languageCode, $languages)) { $languages[$languageCode] = $languageCode; } ksort($languages); $options = array(); foreach ($languages as $code => $name) { $display = wfBCP47($code) . ' - ' . $name; $options[$display] = $code; } $defaultPreferences['language'] = array('type' => 'select', 'section' => 'personal/i18n', 'options' => $options, 'label-message' => 'yourlanguage'); $defaultPreferences['gender'] = array('type' => 'radio', 'section' => 'personal/i18n', 'options' => array($context->msg('parentheses')->params($context->msg('gender-unknown')->plain())->escaped() => 'unknown', $context->msg('gender-female')->escaped() => 'female', $context->msg('gender-male')->escaped() => 'male'), 'label-message' => 'yourgender', 'help-message' => 'prefs-help-gender'); // see if there are multiple language variants to choose from if (!$config->get('DisableLangConversion')) { foreach (LanguageConverter::$languagesWithVariants as $langCode) { if ($langCode == $wgContLang->getCode()) { $variants = $wgContLang->getVariants(); if (count($variants) <= 1) { continue; } $variantArray = array(); foreach ($variants as $v) { $v = str_replace('_', '-', strtolower($v)); $variantArray[$v] = $lang->getVariantname($v, false); } $options = array(); foreach ($variantArray as $code => $name) { $display = wfBCP47($code) . ' - ' . $name; $options[$display] = $code; } $defaultPreferences['variant'] = array('label-message' => 'yourvariant', 'type' => 'select', 'options' => $options, 'section' => 'personal/i18n', 'help-message' => 'prefs-help-variant'); } else { $defaultPreferences["variant-{$langCode}"] = array('type' => 'api'); } } } // Stuff from Language::getExtraUserToggles() // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language $toggles = $wgContLang->getExtraUserToggles(); foreach ($toggles as $toggle) { $defaultPreferences[$toggle] = array('type' => 'toggle', 'section' => 'personal/i18n', 'label-message' => "tog-{$toggle}"); } // show a preview of the old signature first $oldsigWikiText = $wgParser->preSaveTransform('~~~', $context->getTitle(), $user, ParserOptions::newFromContext($context)); $oldsigHTML = $context->getOutput()->parseInline($oldsigWikiText, true, true); $defaultPreferences['oldsig'] = array('type' => 'info', 'raw' => true, 'label-message' => 'tog-oldsig', 'default' => $oldsigHTML, 'section' => 'personal/signature'); $defaultPreferences['nickname'] = array('type' => $wgAuth->allowPropChange('nickname') ? 'text' : 'info', 'maxlength' => $config->get('MaxSigChars'), 'label-message' => 'yournick', 'validation-callback' => array('Preferences', 'validateSignature'), 'section' => 'personal/signature', 'filter-callback' => array('Preferences', 'cleanSignature')); $defaultPreferences['fancysig'] = array('type' => 'toggle', 'label-message' => 'tog-fancysig', 'help-message' => 'prefs-help-signature', 'section' => 'personal/signature'); # # Email stuff if ($config->get('EnableEmail')) { if ($canViewPrivateInfo) { $helpMessages[] = $config->get('EmailConfirmToEdit') ? 'prefs-help-email-required' : 'prefs-help-email'; if ($config->get('EnableUserEmail')) { // additional messages when users can send email to each other $helpMessages[] = 'prefs-help-email-others'; } $emailAddress = $user->getEmail() ? htmlspecialchars($user->getEmail()) : ''; if ($canEditPrivateInfo && $wgAuth->allowPropChange('emailaddress')) { $link = Linker::link(SpecialPage::getTitleFor('ChangeEmail'), $context->msg($user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail')->escaped(), array(), array('returnto' => SpecialPage::getTitleFor('Preferences')->getPrefixedText())); $emailAddress .= $emailAddress == '' ? $link : $context->msg('word-separator')->escaped() . $context->msg('parentheses')->rawParams($link)->escaped(); } $defaultPreferences['emailaddress'] = array('type' => 'info', 'raw' => true, 'default' => $emailAddress, 'label-message' => 'youremail', 'section' => 'personal/email', 'help-messages' => $helpMessages); } $disableEmailPrefs = false; if ($config->get('EmailAuthentication')) { $emailauthenticationclass = 'mw-email-not-authenticated'; if ($user->getEmail()) { if ($user->getEmailAuthenticationTimestamp()) { // date and time are separate parameters to facilitate localisation. // $time is kept for backward compat reasons. // 'emailauthenticated' is also used in SpecialConfirmemail.php $displayUser = $context->getUser(); $emailTimestamp = $user->getEmailAuthenticationTimestamp(); $time = $lang->userTimeAndDate($emailTimestamp, $displayUser); $d = $lang->userDate($emailTimestamp, $displayUser); $t = $lang->userTime($emailTimestamp, $displayUser); $emailauthenticated = $context->msg('emailauthenticated', $time, $d, $t)->parse() . '<br />'; $disableEmailPrefs = false; $emailauthenticationclass = 'mw-email-authenticated'; } else { $disableEmailPrefs = true; $emailauthenticated = $context->msg('emailnotauthenticated')->parse() . '<br />' . Linker::linkKnown(SpecialPage::getTitleFor('Confirmemail'), $context->msg('emailconfirmlink')->escaped()) . '<br />'; $emailauthenticationclass = "mw-email-not-authenticated"; } } else { $disableEmailPrefs = true; $emailauthenticated = $context->msg('noemailprefs')->escaped(); $emailauthenticationclass = 'mw-email-none'; } if ($canViewPrivateInfo) { $defaultPreferences['emailauthentication'] = array('type' => 'info', 'raw' => true, 'section' => 'personal/email', 'label-message' => 'prefs-emailconfirm-label', 'default' => $emailauthenticated, 'cssclass' => $emailauthenticationclass); } } if ($config->get('EnableUserEmail') && $user->isAllowed('sendemail')) { $defaultPreferences['disablemail'] = array('type' => 'toggle', 'invert' => true, 'section' => 'personal/email', 'label-message' => 'allowemail', 'disabled' => $disableEmailPrefs); $defaultPreferences['ccmeonemails'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-ccmeonemails', 'disabled' => $disableEmailPrefs); } if ($config->get('EnotifWatchlist')) { $defaultPreferences['enotifwatchlistpages'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifwatchlistpages', 'disabled' => $disableEmailPrefs); } if ($config->get('EnotifUserTalk')) { $defaultPreferences['enotifusertalkpages'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifusertalkpages', 'disabled' => $disableEmailPrefs); } if ($config->get('EnotifUserTalk') || $config->get('EnotifWatchlist')) { $defaultPreferences['enotifminoredits'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifminoredits', 'disabled' => $disableEmailPrefs); if ($config->get('EnotifRevealEditorAddress')) { $defaultPreferences['enotifrevealaddr'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifrevealaddr', 'disabled' => $disableEmailPrefs); } } } }
private function displayNABConsole(&$dbw, &$dbr, $target) { global $wgOut, $wgRequest, $wgUser, $wgParser; $not_found = false; $title = Title::newFromURL($target); if (!$title || !$title->exists()) { $articleName = $title ? $title->getFullText() : $target; $wgOut->addHTML("<p>Error: Article “{$articleName}” not found. Return to <a href='/Special:Newarticleboost'>New Article Boost</a> instead.</p>"); $not_found = true; } if (!$not_found) { $rev = Revision::newFromTitle($title); if (!$rev) { $wgOut->addHTML("<p>Error: No revision for “{$title->getFullText()}”. Return to <a href='/Special:Newarticleboost'>New Article Boost</a> instead.</p>"); $not_found = true; } } if (!$not_found) { $in_nab = $dbr->selectField('newarticlepatrol', 'count(*)', array('nap_page' => $title->getArticleID()), __METHOD__) > 0; if (!$in_nab) { $wgOut->addHTML("<p>Error: This article is not in the NAB list.</p>"); $not_found = true; } } if ($not_found) { $pageid = $wgRequest->getVal('page'); if (strpos($target, ':') !== false && $pageid) { $wgOut->addHTML('<p>We can to try to <a href="/Special:NABClean/' . $pageid . '">delete this title</a> if you know this title exists in NAB yet is likely bad data.</p>'); } return; } $locked = false; $min_timestamp = $dbr->selectField("revision", "min(rev_timestamp)", "rev_page=" . $title->getArticleId(), __METHOD__); $first_user = $dbr->selectField("revision", "rev_user_text", array("rev_page=" . $title->getArticleId(), 'rev_timestamp' => $min_timestamp), __METHOD__); $first_user_id = $dbr->selectField("revision", "rev_user", array("rev_page=" . $title->getArticleId(), 'rev_timestamp' => $min_timestamp), __METHOD__); $user = new User(); if ($first_user_id) { $user->setId($first_user_id); $user->loadFromDatabase(); } else { $user->setName($first_user); } $user_talk = $user->getTalkPage(); $ut_id = $user_talk->getArticleID(); $display_name = $user->getRealName() ? $user->getRealName() : $user->getName(); $wgOut->setPageTitle(wfMsg('nap_title', $title->getFullText())); $count = $dbr->selectField('suggested_titles', array('count(*)'), array('st_title' => $title->getDBKey()), __METHOD__); $extra = $count > 0 ? ' - from Suggested Titles database' : ''; $wgOut->addWikiText(wfMsg('nap_writtenby', $user->getName(), $display_name, $extra)); $wgOut->addHTML(wfMsgExt('nap_quicklinks', 'parseinline', $this->me->getFullText() . "/" . $title->getFullText())); /// CHECK TO SEE IF ARTICLE IS LOCKED OR ALREADY PATROLLED $aid = $title->getArticleID(); $half_hour_ago = wfTimestamp(TS_MW, time() - 30 * 60); $patrolled = $dbr->selectField('newarticlepatrol', 'nap_patrolled', array("nap_page={$aid}"), __METHOD__); if ($patrolled) { $locked = true; $wgOut->addHTML(wfMsgExt("nap_patrolled", 'parse')); } else { $user_co = $dbr->selectField('newarticlepatrol', 'nap_user_co', array("nap_page={$aid}", "nap_timestamp_co > '{$half_hour_ago}'"), __METHOD__); if ($user_co != '' && $user_co != 0 && $user_co != $wgUser->getId()) { $x = User::newFromId($user_co); $wgOut->addHTML(wfMsgExt("nap_usercheckedout", 'parse', $x->getName())); $locked = true; } else { // CHECK OUT THE ARTICLE TO THIS USER $ts = wfTimestampNow(); $dbw->update('newarticlepatrol', array('nap_timestamp_co' => $ts, 'nap_user_co' => $wgUser->getId()), array("nap_page = {$aid}"), __METHOD__); } } $expandSpan = '<span class="nap_expand">▼</span>'; $externalLinkImg = '<img src="' . wfGetPad('/skins/common/images/external.png') . '"/>'; /// SIMILAR RESULT $wgOut->addHTML("<div class='nap_section minor_section'>"); $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_similarresults') . "</h2>"); $wgOut->addHTML("<div class='nap_body section_text'>"); $count = 0; $l = new LSearch(); $hits = $l->googleSearchResultTitles($title->getFullText(), 0, 5); if (sizeof($hits) > 0) { $html = ""; foreach ($hits as $hit) { $t1 = $hit; $id = rand(0, 500); if ($t1 == null || $t1->getFullURL() == $title->getFullURL() || $t1->getNamespace() != NS_MAIN || !$t1->exists()) { continue; } $safe_title = htmlspecialchars(str_replace("'", "'", $t1->getText())); $html .= "<tr><td>" . $this->skin->makeLinkObj($t1, wfMsg('howto', $t1->getText())) . "</td><td style='text-align:right; width: 200px;'>[<a href='#action' onclick='nap_Merge(\"{$safe_title}\");'>" . wfMsg('nap_merge') . "</a>] " . " [<a href='#action' onclick='javascript:nap_Dupe(\"{$safe_title}\");'>" . wfMsg('nap_duplicate') . "</a>] " . " <span id='mr_{$id}'>[<a onclick='javascript:nap_MarkRelated({$id}, {$t1->getArticleID()}, {$title->getArticleID()});'>" . wfMsg('nap_related') . "</a>]</span> " . "</td></tr>"; $count++; } } if ($count == 0) { $wgOut->addHTML(wfMsg('nap_no-related-topics')); } else { $wgOut->addHTML(wfMsg('nap_already-related-topics') . "<table style='width:100%;'>{$html}</table>"); } $wgOut->addHTML(wfMsg('nap_othersearches', urlencode($title->getFullText()))); $wgOut->addHTML("</div>"); $wgOut->addHTML("</div>"); /// COPYRIGHT CHECKER $cc_check = SpecialPage::getTitleFor('Copyrightchecker', $title->getText()); $wgOut->addHTML("<script type='text/javascript'>window.onload = nap_cCheck; var nap_cc_url = \"{$cc_check->getFullURL()}\";</script>"); $wgOut->addHTML("<div class='nap_section minor_section'>"); $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_copyrightchecker') . "</h2>"); $wgOut->addHTML("<div class='nap_body section_text'>"); $wgOut->addHTML("<div id='nap_copyrightresults'><center><img src='/extensions/wikihow/rotate.gif' alt='loading...'/></center></div>"); $wgOut->addHTML("<center><input type='button' class='button primary' onclick='nap_cCheck();' value='Check'/></center>"); $wgOut->addHTML("</div>"); $wgOut->addHTML("</div>"); /// ARTICLE PREVIEW $editUrl = Title::makeTitle(NS_SPECIAL, "QuickEdit")->getFullURL() . "?type=editform&target=" . urlencode($title->getFullText()) . "&fromnab=1"; $wgOut->addHTML("<div class='nap_section minor_section'>"); $wgOut->addHTML("<a name='article' id='anchor-article'></a>"); $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_articlepreview') . " - <a href=\"{$title->getFullURL()}\" target=\"new\">" . wfMsg('nap_articlelinktext') . "</a> {$externalLinkImg}" . " - <a href=\"{$title->getEditURL()}\" target=\"new\">" . wfMsg('edit') . "</a> {$externalLinkImg}" . " - <a href=\"{$title->getFullURL()}?action=history\" target=\"new\">" . wfMsg('history') . "</a> {$externalLinkImg}" . " - <a href=\"{$title->getTalkPage()->getFullURL()}\" target=\"new\">" . wfMsg('discuss') . "</a> {$externalLinkImg}" . "</h2>"); $wgOut->addHTML("<div class='nap_body section_text'>"); $wgOut->addHTML("<div id='article_contents' ondblclick='nap_editClick(\"{$editUrl}\");'>"); $popts = $wgOut->parserOptions(); $popts->setTidy(true); // $parserOutput = $wgOut->parse($rev->getText(), $title, $popts); $output = $wgParser->parse($rev->getText(), $title, $popts); $parserOutput = $output->getText(); $magic = WikihowArticleHTML::grabTheMagic($rev->getText()); $html = WikihowArticleHTML::processArticleHTML($parserOutput, array('no-ads' => true, 'ns' => $title->getNamespace(), 'magic-word' => $magic)); $wgOut->addHTML($html); $wgOut->addHTML("</div>"); $wgOut->addHTML("<center><input id='editButton' type='button' class='button primary' name='wpEdit' value='" . wfMsg('edit') . "' onclick='nap_editClick(\"{$editUrl}\");'/></center>"); $wgOut->addHTML("</div>"); $wgOut->addHTML("</div>"); $wgOut->addHTML('<div style="clear: both;"></div>'); /// DISCUSSION PREVIEW $talkPage = $title->getTalkPage(); $wgOut->addHTML("<div class='nap_section minor_section'>"); $wgOut->addHTML("<a name='talk' id='anchor-talk'></a>"); $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_discussion') . " - <a href=\"{$talkPage->getFullURL()}\" target=\"new\">" . wfMsg('nap_articlelinktext') . "</a> {$externalLinkImg}" . "</h2>"); $wgOut->addHTML("<div class='nap_body section_text'>"); $wgOut->addHTML("<div id='disc_page'>"); if ($talkPage->getArticleID() > 0) { $rp = Revision::newFromTitle($talkPage); $wgOut->addHTML($wgOut->parse($rp->getText())); } else { $wgOut->addHTML(wfMsg('nap_discussionnocontent')); } $wgOut->addHTML(PostComment::getForm(true, $talkPage, true)); $wgOut->addHTML("</div>"); $wgOut->addHTML("</div>"); $wgOut->addHTML("</div>"); /// USER INFORMATION $wgOut->addHTML("<div class='nap_section minor_section'>"); $wgOut->addHTML("<a name='user' id='anchor-user'></a>"); $used_templates = array(); if ($ut_id > 0) { $res = $dbr->select('templatelinks', array('tl_title'), array('tl_from=' . $ut_id), __METHOD__); while ($row = $dbr->fetchObject($res)) { $used_templates[] = strtolower($row->tl_title); } $dbr->freeResult($res); } $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_userinfo') . " - <a href=\"{$user_talk->getFullURL()}\" target=\"new\">" . wfMsg('nap_articlelinktext') . "</a> {$externalLinkImg}" . "</h2>"); $wgOut->addHTML("<div class='nap_body section_text'>"); $contribs = SpecialPage::getTitleFor('Contributions', $user->getName()); $regDateTxt = ""; if ($user->getRegistration() > 0) { preg_match('/^(\\d{4})(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)$/D', $user->getRegistration(), $da); $uts = gmmktime((int) $da[4], (int) $da[5], (int) $da[6], (int) $da[2], (int) $da[3], (int) $da[1]); $regdate = gmdate('F j, Y', $uts); $regDateTxt = wfMsg('nap_regdatetext', $regdate) . ' '; } $key = 'nap_userinfodetails_anon'; if ($user->getID() != 0) { $key = 'nap_userinfodetails'; } $wgOut->addWikiText(wfMsg($key, $user->getName(), number_format(WikihowUser::getAuthorStats($first_user), 0, "", ","), $title->getFullText(), $regDateTxt)); if (WikihowUser::getAuthorStats($first_user) < 50) { if ($user_talk->getArticleId() == 0) { $wgOut->addHTML(wfMsg('nap_newwithouttalkpage')); } else { $rp = Revision::newFromTitle($user_talk); $xtra = ""; if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE 8.0") === false) { $xtra = "max-height: 300px; overflow: scroll;"; } $output = $wgParser->parse($rp->getText(), $user_talk, $popts); $parserOutput = $output->getText(); $wgOut->addHTML("<div style='border: 1px solid #eee; {$xtra}'>" . $parserOutput . "</div>"); } } if ($user_talk->getArticleId() != 0 && sizeof($used_templates) > 0) { $wgOut->addHTML('<br />' . wfMsg('nap_usertalktemplates', implode($used_templates, ", "))); } $wgOut->addHTML(PostComment::getForm(true, $user_talk, true)); $wgOut->addHTML("</div>"); $wgOut->addHTML("</div>"); /// ACTION INFORMATION $maxrcid = $dbr->selectField('recentchanges', 'max(rc_id)', array('rc_cur_id=' . $aid), __METHOD__); $wgOut->addHTML("<div class='nap_section minor_section'>"); $wgOut->addHTML("<a name='action' id='anchor-action'></a>"); $wgOut->addHTML("<h2 class='nap_header'> " . wfMsg('nap_action') . "</h2>"); $wgOut->addHTML("<div class='nap_body section_text'>"); $wgOut->addHTML("<form action='{$this->me->getFullURL()}' name='nap_form' method='post' onsubmit='return checkNap();'>"); $wgOut->addHTML("<input type='hidden' name='target' value='" . htmlspecialchars($title->getText()) . "'/>"); $wgOut->addHTML("<input type='hidden' name='page' value='{$aid}'/>"); $wgOut->addHTML("<input type='hidden' name='newbie' value='" . $wgRequest->getVal('newbie', 0) . "'/>"); $wgOut->addHTML("<input type='hidden' name='prevuser' value='" . $user->getName() . "'/>"); $wgOut->addHTML("<input type='hidden' name='maxrcid' value='{$maxrcid}'/>"); $wgOut->addHTML("<table>"); $suggested = $dbr->selectField('suggested_titles', 'count(*)', array('st_title' => $title->getDBKey()), __METHOD__); if ($suggested > 0) { $wgOut->addHTML("<tr><td valign='top'>" . wfMsg('nap_suggested_warning') . "</td></tr>"); } $wgOut->addHTML("</table>"); $wgOut->addHTML(wfMsg('nap_actiontemplates')); if ($wgUser->isAllowed('delete') || $wgUser->isAllowed('move')) { $wgOut->addHTML(wfMsg('nap_actionmovedeleteheader')); if ($wgUser->isAllowed('move')) { $wgOut->addHTML(wfMsg('nap_actionmove', htmlspecialchars($title->getText()))); } if ($wgUser->isAllowed('delete')) { $wgOut->addHTML(wfMsg('nap_actiondelete')); } } // BUTTONS $wgOut->addHTML("<input type='submit' value='" . wfMsg('nap_skip') . "' id='nap_skip' name='nap_skip' class='button secondary' />"); if (!$locked) { $wgOut->addHTML("<input type='submit' value='" . wfMsg('nap_markaspatrolled') . "' id='nap_submit' name='nap_submit' class='button primary' />"); } $wgOut->addHTML("</form>"); $wgOut->addHTML("</div>"); $wgOut->addHTML("</div>"); $wgOut->addHTML(<<<END <script type='text/javascript'> var tabindex = 1; for(i = 0; i < document.forms.length; i++) { \tfor (j = 0; j < document.forms[i].elements.length; j++) { \t\tswitch (document.forms[i].elements[j].type) { \t\t\tcase 'submit': \t\t\tcase 'text': \t\t\tcase 'textarea': \t\t\tcase 'checkbox': \t\t\tcase 'button': \t\t\t\tdocument.forms[i].elements[j].tabIndex = tabindex++; \t\t\t\tbreak; \t\t\tdefault: \t\t\t\tbreak; \t\t} \t} } // Handlers for expand/contract arrows (function (\$) { \$('.nap_expand').click(function() { \tvar thisSpan = \$(this); \tvar body = thisSpan.parent().next(); \tvar footer = body.next(); \tif (body.css('display') != 'none') { \t\tfooter.hide(); \t\tbody.css('overflow', 'hidden'); \t\tvar oldHeight = body.height(); \t\tbody.animate( \t\t\t{ height: 0 }, \t\t\t200, \t\t\t'swing', \t\t\tfunction () { \t\t\t\tthisSpan.html('►'); \t\t\t\tbody \t\t\t\t\t.hide() \t\t\t\t\t.height(oldHeight); \t\t\t}); \t} else { \t\tvar oldHeight = body.height(); \t\tbody.height(0); \t\tbody.animate( \t\t\t{ height: oldHeight }, \t\t\t200, \t\t\t'swing', \t\t\tfunction () { \t\t\t\tthisSpan.html('▼'); \t\t\t\tfooter.show(); \t\t\t\tbody.css('overflow', 'visible'); \t\t\t}); \t} \treturn false; }); })(jQuery); </script> END ); }
/** * Prepares array of user fields needed to be passed by API * @param User $oUser * @return array */ public function prepareUserParams(\User $oUser) { $aUserParams = ['user_id' => $oUser->getId(), 'user_name' => $oUser->getName(), 'user_real_name' => $oUser->getRealName(), 'user_email' => $oUser->getEmail(), 'user_email_authenticated' => $oUser->getEmailAuthenticationTimestamp(), 'user_registration' => $oUser->getRegistration(), 'user_editcount' => (int) $oUser->getEditCount(), 'user_touched' => $oUser->getTouched()]; return $aUserParams; }
/** * Echo should be disabled for users who are under cohort study * @param $user User * @return bool */ public static function isEchoDisabled(User $user) { global $wgEchoCohortInterval; // Make sure the user has an id and cohort study timestamp is specified if (!$wgEchoCohortInterval || !$user->getId()) { return false; } list($start, $bucketEnd, $cohortEnd) = $wgEchoCohortInterval; $regTimestamp = $user->getRegistration(); // Cohort study is for user with a registration timestamp if (!$regTimestamp) { return false; } // Cohort study is for even user_id if ($user->getId() % 2 === 1) { return false; } $now = wfTimestampNow(); // Make sure the user is registered during the bucketing period // and the cohort study doesn't end yet if ($start <= $regTimestamp && $regTimestamp <= $bucketEnd && $start <= $now && $now <= $cohortEnd) { return true; } return false; }
/** * As recCheckCondition, but *not* recursive. The only valid conditions * are those whose first element is APCOND_EMAILCONFIRMED/APCOND_EDITCOUNT/ * APCOND_AGE. Other types will throw an exception if no extension evalu- * ates them. * * @param array $cond A condition, which must not contain other conditions * @param User $user The user to check the condition against * @return bool Whether the condition is true for the user */ private static function checkCondition($cond, User $user) { if (count($cond) < 1) { return false; } switch ($cond[0]) { case APCOND_EMAILCONFIRMED: if (User::isValidEmailAddr($user->getEmail())) { global $wgEmailAuthentication; if ($wgEmailAuthentication) { return $user->getEmailAuthenticationTimestamp() ? true : false; } else { return true; } } return false; case APCOND_EDITCOUNT: return $user->getEditCount() >= $cond[1]; case APCOND_AGE: $age = time() - wfTimestampOrNull(TS_UNIX, $user->getRegistration()); return $age >= $cond[1]; case APCOND_INGROUPS: $groups = array_slice($cond, 1); return count(array_intersect($groups, $user->getGroups())) == count($groups); default: $result = null; wfRunHooks('AutopromoteCondition', array($cond[0], array_slice($cond, 1), $user, &$result)); if ($result === null) { throw new MWException("Unrecognized condition {$cond[0]} for autopromotion!"); } return $result ? true : false; } }