Author: SamPeng (penglingjun@zhishisoft.com)
Example #1
0
 /**
  * 运行事件
  * @param string $which 事件名称
  * @param string $type  事件类型 '':pc站 m:手机站
  * @return Hooks
  */
 public static function event($which, $assets = '', $type = '')
 {
     if (empty(self::$instance)) {
         self::$instance = new static();
     }
     self::$instance->type = $type;
     self::$instance->assets = $assets;
     self::$instance->position($which);
     self::$instance->type = '';
     self::$instance->assets = '';
     return self::$instance;
 }
 public function __construct()
 {
     parent::__construct();
     $paths = [];
     // Autodiscover extension unit tests
     $registry = ExtensionRegistry::getInstance();
     foreach ($registry->getAllThings() as $info) {
         $paths[] = dirname($info['path']) . '/tests/phpunit';
     }
     // Extensions can return a list of files or directories
     Hooks::run('UnitTestsList', [&$paths]);
     foreach (array_unique($paths) as $path) {
         if (is_dir($path)) {
             // If the path is a directory, search for test cases.
             // @since 1.24
             $suffixes = ['Test.php'];
             $fileIterator = new File_Iterator_Facade();
             $matchingFiles = $fileIterator->getFilesAsArray($path, $suffixes);
             $this->addTestFiles($matchingFiles);
         } elseif (file_exists($path)) {
             // Add a single test case or suite class
             $this->addTestFile($path);
         }
     }
     if (!$paths) {
         $this->addTest(new DummyExtensionsTest('testNothing'));
     }
 }
Example #3
0
 private function getTokenTypes()
 {
     // If we're in a mode that breaks the same-origin policy, no tokens can
     // be obtained
     if ($this->lacksSameOriginSecurity()) {
         return [];
     }
     static $types = null;
     if ($types) {
         return $types;
     }
     $types = ['patrol' => ['ApiQueryRecentChanges', 'getPatrolToken']];
     $names = ['edit', 'delete', 'protect', 'move', 'block', 'unblock', 'email', 'import', 'watch', 'options'];
     foreach ($names as $name) {
         $types[$name] = ['ApiQueryInfo', 'get' . ucfirst($name) . 'Token'];
     }
     Hooks::run('ApiTokensGetTokenTypes', [&$types]);
     // For forwards-compat, copy any token types from ApiQueryTokens that
     // we don't already have something for.
     $user = $this->getUser();
     $request = $this->getRequest();
     foreach (ApiQueryTokens::getTokenTypeSalts() as $name => $salt) {
         if (!isset($types[$name])) {
             $types[$name] = function () use($salt, $user, $request) {
                 return ApiQueryTokens::getToken($user, $request->getSession(), $salt)->toString();
             };
         }
     }
     ksort($types);
     return $types;
 }
Example #4
0
function check_user_identity($required = true)
{
    $realm = 'OpenMediakit Transcoder';
    if ($required && !isset($_SERVER['PHP_AUTH_USER'])) {
        header('WWW-Authenticate: Basic realm="' . $realm . '"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Please authenticate';
        exit;
    }
    /*
     * Autre exemple de hook possible:
     * Hooks::call('pre_check_user_identity', array($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']));
     */
    require_once __DIR__ . '/../modules/users/libs/users.php';
    if ($required && isset($_SERVER['PHP_AUTH_USER'])) {
        $GLOBALS["me"] = Users::auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
    } else {
        $GLOBALS["me"] = array();
    }
    if ($required && !$GLOBALS["me"]) {
        header('WWW-Authenticate: Basic realm="' . $realm . '"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Login or password incorrect, or account disabled';
        exit;
    }
    Hooks::call('post_check_user_identity', $GLOBALS["me"]);
    //  mq("UPDATE user SET lastlogin=NOW() WHERE id='".$GLOBALS["me"]["id"]."';");
}
Example #5
0
 protected function setup($par)
 {
     // Options
     $opts = new FormOptions();
     $this->opts = $opts;
     // bind
     $opts->add('hideliu', false);
     $opts->add('hidepatrolled', $this->getUser()->getBoolOption('newpageshidepatrolled'));
     $opts->add('hidebots', false);
     $opts->add('hideredirs', true);
     $opts->add('limit', $this->getUser()->getIntOption('rclimit'));
     $opts->add('offset', '');
     $opts->add('namespace', '0');
     $opts->add('username', '');
     $opts->add('feed', '');
     $opts->add('tagfilter', '');
     $opts->add('invert', false);
     $this->customFilters = [];
     Hooks::run('SpecialNewPagesFilters', [$this, &$this->customFilters]);
     foreach ($this->customFilters as $key => $params) {
         $opts->add($key, $params['default']);
     }
     // Set values
     $opts->fetchValuesFromRequest($this->getRequest());
     if ($par) {
         $this->parseParams($par);
     }
     // Validate
     $opts->validateIntBounds('limit', 0, 5000);
 }
 public function setup()
 {
     global $wgOut, $wgExtensionAssetsPath, $IP, $wgResourceModules, $wgAutoloadClasses, $wgHooks, $wgParser, $wgJQUploadFileMagic;
     // If attachments allowed in this page, add the module into the page
     if ($title = array_key_exists('title', $_GET) ? Title::newFromText($_GET['title']) : false) {
         $this->id = $title->getArticleID();
     }
     // Set up the #file parser-function
     $wgParser->setFunctionHook($wgJQUploadFileMagic, array($this, 'expandFile'), SFH_NO_HASH);
     // Allow overriding of the file ID
     Hooks::run('jQueryUploadSetId', array($title, &$this->id));
     // If attachments allowed in this page, add the module into the page
     $attach = is_object($title) && $this->id && !$title->isRedirect() && !array_key_exists('action', $_REQUEST) && $title->getNamespace() != 6;
     if ($attach) {
         Hooks::run('jQueryUploadAddAttachLink', array($title, &$attach));
     }
     if ($attach) {
         $this->head();
         $wgHooks['BeforePageDisplay'][] = $this;
     }
     // Add the extensions own js
     $path = $wgExtensionAssetsPath . str_replace("{$IP}/extensions", '', dirname($wgAutoloadClasses[__CLASS__]));
     $wgResourceModules['ext.jqueryupload']['remoteExtPath'] = $path;
     $wgOut->addModules('ext.jqueryupload');
     $wgOut->addStyle("{$path}/styles/jqueryupload.css");
 }
Example #7
0
 /**
  * Returns the globally available instance of a Hooks
  * @return object The Hooks object.
  */
 public static function instance()
 {
     if (!isset(self::$instance) && !self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 public static function setupHooks()
 {
     $rsObj = new self();
     \Hooks::register('UserSetCookies', $rsObj);
     \Hooks::register('UserLoadFromSession', $rsObj);
     \Hooks::register('UserLogout', $rsObj);
 }
 public static function onRegistration()
 {
     global $wgEmailPageGroup, $wgGroupPermissions, $wgEmailPageAllowRemoteAddr, $wgEmailPageToolboxLink, $wgEmailPageActionLink;
     if ($wgEmailPageGroup) {
         $wgGroupPermissions['sysop'][$wgEmailPageGroup] = true;
     }
     if (isset($_SERVER['SERVER_ADDR'])) {
         $wgEmailPageAllowRemoteAddr[] = $_SERVER['SERVER_ADDR'];
     }
     // If form has been posted, include the phpmailer class
     if (isset($_REQUEST['ea-send'])) {
         if ($files = glob("{$dir}/*/class.phpmailer.php")) {
             require_once $files[0];
         } else {
             die("PHPMailer class not found!");
         }
     }
     // Add toolbox and action links
     if ($wgEmailPageToolboxLink) {
         Hooks::register('SkinTemplateToolboxEnd', __CLASS__ . '::onSkinTemplateToolboxEnd');
     }
     if ($wgEmailPageActionLink) {
         Hooks::register('SkinTemplateTabs', __CLASS__ . '::onSkinTemplateTabs');
         Hooks::register('SkinTemplateNavigation', __CLASS__ . '::onSkinTemplateNavigation');
     }
 }
 /**
  * @param string|number|null|bool $sectionId
  * @param Content $with
  * @param string $sectionTitle
  *
  * @throws MWException
  * @return Content
  *
  * @see Content::replaceSection()
  */
 public function replaceSection($sectionId, Content $with, $sectionTitle = '')
 {
     $myModelId = $this->getModel();
     $sectionModelId = $with->getModel();
     if ($sectionModelId != $myModelId) {
         throw new MWException("Incompatible content model for section: " . "document uses {$myModelId} but " . "section uses {$sectionModelId}.");
     }
     $oldtext = $this->getNativeData();
     $text = $with->getNativeData();
     if (strval($sectionId) === '') {
         return $with;
         # XXX: copy first?
     }
     if ($sectionId === 'new') {
         # Inserting a new section
         $subject = $sectionTitle ? wfMessage('newsectionheaderdefaultlevel')->rawParams($sectionTitle)->inContentLanguage()->text() . "\n\n" : '';
         if (Hooks::run('PlaceNewSection', array($this, $oldtext, $subject, &$text))) {
             $text = strlen(trim($oldtext)) > 0 ? "{$oldtext}\n\n{$subject}{$text}" : "{$subject}{$text}";
         }
     } else {
         # Replacing an existing section; roll out the big guns
         global $wgParser;
         $text = $wgParser->replaceSection($oldtext, $sectionId, $text);
     }
     $newContent = new static($text);
     return $newContent;
 }
 public function execute($par)
 {
     $this->setHeaders();
     $this->getOutput()->addModuleStyles('mediawiki.special');
     $this->edits = SiteStats::edits();
     $this->good = SiteStats::articles();
     $this->images = SiteStats::images();
     $this->total = SiteStats::pages();
     $this->users = SiteStats::users();
     $this->activeUsers = SiteStats::activeUsers();
     $this->hook = '';
     $text = Xml::openElement('table', ['class' => 'wikitable mw-statistics-table']);
     # Statistic - pages
     $text .= $this->getPageStats();
     # Statistic - edits
     $text .= $this->getEditStats();
     # Statistic - users
     $text .= $this->getUserStats();
     # Statistic - usergroups
     $text .= $this->getGroupStats();
     # Statistic - other
     $extraStats = [];
     if (Hooks::run('SpecialStatsAddExtra', [&$extraStats, $this->getContext()])) {
         $text .= $this->getOtherStats($extraStats);
     }
     $text .= Xml::closeElement('table');
     # Customizable footer
     $footer = $this->msg('statistics-footer');
     if (!$footer->isBlank()) {
         $text .= "\n" . $footer->parse();
     }
     $this->getOutput()->addHTML($text);
 }
 function execute($par)
 {
     /**
      * Some satellite ISPs use broken precaching schemes that log people out straight after
      * they're logged in (bug 17790). Luckily, there's a way to detect such requests.
      */
     if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '&') !== false) {
         wfDebug("Special:Userlogout request {$_SERVER['REQUEST_URI']} looks suspicious, denying.\n");
         throw new HttpError(400, $this->msg('suspicious-userlogout'), $this->msg('loginerror'));
     }
     $this->setHeaders();
     $this->outputHeader();
     // Make sure it's possible to log out
     $session = MediaWiki\Session\SessionManager::getGlobalSession();
     if (!$session->canSetUser()) {
         throw new ErrorPageError('cannotlogoutnow-title', 'cannotlogoutnow-text', [$session->getProvider()->describe(RequestContext::getMain()->getLanguage())]);
     }
     $user = $this->getUser();
     $oldName = $user->getName();
     $user->logout();
     $loginURL = SpecialPage::getTitleFor('Userlogin')->getFullURL($this->getRequest()->getValues('returnto', 'returntoquery'));
     $out = $this->getOutput();
     $out->addWikiMsg('logouttext', $loginURL);
     // Hook.
     $injected_html = '';
     Hooks::run('UserLogoutComplete', [&$user, &$injected_html, $oldName]);
     $out->addHTML($injected_html);
     $out->returnToMain();
 }
 public function __construct()
 {
     if (strtolower(ACTION_NAME) === 'index' && strtolower(MODULE_NAME) === 'profile' && strtolower(APP_NAME) === 'public') {
         $this->isRefresh = 1;
     }
     parent::__construct();
 }
 /**
  * @param ResourceLoaderContext $context
  * @return array
  */
 protected function getConfigSettings($context)
 {
     $hash = $context->getHash();
     if (isset($this->configVars[$hash])) {
         return $this->configVars[$hash];
     }
     global $wgContLang;
     $mainPage = Title::newMainPage();
     /**
      * Namespace related preparation
      * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces.
      * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive.
      */
     $namespaceIds = $wgContLang->getNamespaceIds();
     $caseSensitiveNamespaces = array();
     foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) {
         $namespaceIds[$wgContLang->lc($name)] = $index;
         if (!MWNamespace::isCapitalized($index)) {
             $caseSensitiveNamespaces[] = $index;
         }
     }
     $conf = $this->getConfig();
     // Build list of variables
     $vars = array('wgLoadScript' => wfScript('load'), 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $conf->get('StylePath'), 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $conf->get('ArticlePath'), 'wgScriptPath' => $conf->get('ScriptPath'), 'wgScriptExtension' => '.php', 'wgScript' => wfScript(), 'wgSearchType' => $conf->get('SearchType'), 'wgVariantArticlePath' => $conf->get('VariantArticlePath'), 'wgActionPaths' => (object) $conf->get('ActionPaths'), 'wgServer' => $conf->get('Server'), 'wgServerName' => $conf->get('ServerName'), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgTranslateNumerals' => $conf->get('TranslateNumerals'), 'wgVersion' => $conf->get('Version'), 'wgEnableAPI' => $conf->get('EnableAPI'), 'wgEnableWriteAPI' => $conf->get('EnableWriteAPI'), 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $conf->get('Sitename'), 'wgDBname' => $conf->get('DBname'), 'wgExtraSignatureNamespaces' => $conf->get('ExtraSignatureNamespaces'), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $conf->get('ExtensionAssetsPath'), 'wgCookiePrefix' => $conf->get('CookiePrefix'), 'wgCookieDomain' => $conf->get('CookieDomain'), 'wgCookiePath' => $conf->get('CookiePath'), 'wgCookieExpiration' => $conf->get('CookieExpiration'), 'wgResourceLoaderMaxQueryLength' => $conf->get('ResourceLoaderMaxQueryLength'), 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $conf->get('ResourceLoaderStorageVersion'), 'wgResourceLoaderStorageEnabled' => $conf->get('ResourceLoaderStorageEnabled'), 'wgResourceLoaderLegacyModules' => self::getLegacyModules(), 'wgForeignUploadTargets' => $conf->get('ForeignUploadTargets'), 'wgEnableUploads' => $conf->get('EnableUploads'));
     Hooks::run('ResourceLoaderGetConfigVars', array(&$vars));
     $this->configVars[$hash] = $vars;
     return $this->configVars[$hash];
 }
Example #15
0
 /**
  * Show a return link or redirect to it.
  * Extensions can change where the link should point or inject content into the page
  * (which will change it from redirect to link mode).
  *
  * @param string $type One of the following:
  *    - error: display a return to link ignoring $wgRedirectOnLogin
  *    - success: display a return to link using $wgRedirectOnLogin if needed
  *    - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
  * @param string $returnTo
  * @param array|string $returnToQuery
  * @param bool $stickHTTPS Keep redirect link on HTTPS
  */
 public function showReturnToPage($type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false)
 {
     global $wgRedirectOnLogin, $wgSecureLogin;
     if ($type !== 'error' && $wgRedirectOnLogin !== null) {
         $returnTo = $wgRedirectOnLogin;
         $returnToQuery = [];
     } elseif (is_string($returnToQuery)) {
         $returnToQuery = wfCgiToArray($returnToQuery);
     }
     // Allow modification of redirect behavior
     Hooks::run('PostLoginRedirect', [&$returnTo, &$returnToQuery, &$type]);
     $returnToTitle = Title::newFromText($returnTo) ?: Title::newMainPage();
     if ($wgSecureLogin && !$stickHTTPS) {
         $options = ['http'];
         $proto = PROTO_HTTP;
     } elseif ($wgSecureLogin) {
         $options = ['https'];
         $proto = PROTO_HTTPS;
     } else {
         $options = [];
         $proto = PROTO_RELATIVE;
     }
     if ($type === 'successredirect') {
         $redirectUrl = $returnToTitle->getFullURL($returnToQuery, false, $proto);
         $this->getOutput()->redirect($redirectUrl);
     } else {
         $this->getOutput()->addReturnTo($returnToTitle, $returnToQuery, null, $options);
     }
 }
Example #16
0
 /**
  * @param array $params
  * @param Config $mainConfig
  * @return array
  */
 public static function applyDefaultParameters(array $params, Config $mainConfig)
 {
     $logger = LoggerFactory::getInstance('Mime');
     $params += ['typeFile' => $mainConfig->get('MimeTypeFile'), 'infoFile' => $mainConfig->get('MimeInfoFile'), 'xmlTypes' => $mainConfig->get('XMLMimeTypes'), 'guessCallback' => function ($mimeAnalyzer, &$head, &$tail, $file, &$mime) use($logger) {
         // Also test DjVu
         $deja = new DjVuImage($file);
         if ($deja->isValid()) {
             $logger->info(__METHOD__ . ": detected {$file} as image/vnd.djvu\n");
             $mime = 'image/vnd.djvu';
             return;
         }
         // Some strings by reference for performance - assuming well-behaved hooks
         Hooks::run('MimeMagicGuessFromContent', [$mimeAnalyzer, &$head, &$tail, $file, &$mime]);
     }, 'extCallback' => function ($mimeAnalyzer, $ext, &$mime) {
         // Media handling extensions can improve the MIME detected
         Hooks::run('MimeMagicImproveFromExtension', [$mimeAnalyzer, $ext, &$mime]);
     }, 'initCallback' => function ($mimeAnalyzer) {
         // Allow media handling extensions adding MIME-types and MIME-info
         Hooks::run('MimeMagicInit', [$mimeAnalyzer]);
     }, 'logger' => $logger];
     if ($params['infoFile'] === 'includes/mime.info') {
         $params['infoFile'] = __DIR__ . "/libs/mime/mime.info";
     }
     if ($params['typeFile'] === 'includes/mime.types') {
         $params['typeFile'] = __DIR__ . "/libs/mime/mime.types";
     }
     $detectorCmd = $mainConfig->get('MimeDetectorCommand');
     if ($detectorCmd) {
         $params['detectCallback'] = function ($file) use($detectorCmd) {
             return wfShellExec("{$detectorCmd} " . wfEscapeShellArg($file));
         };
     }
     return $params;
 }
 public function execute()
 {
     if (!class_exists('CentralAuthUser')) {
         $this->error("CentralAuth isn't enabled on this wiki\n", 1);
     }
     $username = $this->getArg(0);
     $user = User::newFromName($username);
     if ($user === false) {
         $this->error("'{$username}' is an invalid username\n", 1);
     }
     // Normalize username
     $username = $user->getName();
     if ($user->getId()) {
         $this->error("User '{$username}' already exists\n", 1);
     } else {
         global $wgAuth;
         $central = CentralAuthUser::getInstance($user);
         if (!$central->exists()) {
             $this->error("No such global user: '******'\n", 1);
         }
         $user->loadDefaults($username);
         $user->addToDatabase();
         $wgAuth->initUser($user, true);
         $wgAuth->updateUser($user);
         # Notify hooks (e.g. Newuserlog)
         Hooks::run('AuthPluginAutoCreate', array($user));
         # Update user count
         $ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
         $ssUpdate->doUpdate();
         $this->output("User '{$username}' created\n");
     }
 }
Example #18
0
 public static function attach($hooks_name, $func)
 {
     $hooks = self::$hooks;
     $hooks[$hooks_name][] = $func;
     self::$hooks = $hooks;
     return self::$hooks;
 }
Example #19
0
 /**
  * Format a line using the old system (aka without any javascript).
  *
  * @param RecentChange $rc Passed by reference
  * @param bool $watched (default false)
  * @param int $linenumber (default null)
  *
  * @return string|bool
  */
 public function recentChangesLine(&$rc, $watched = false, $linenumber = null)
 {
     $classes = array();
     // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
     if ($linenumber) {
         if ($linenumber & 1) {
             $classes[] = 'mw-line-odd';
         } else {
             $classes[] = 'mw-line-even';
         }
     }
     // Indicate watched status on the line to allow for more
     // comprehensive styling.
     $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
     $html = $this->formatChangeLine($rc, $classes, $watched);
     if ($this->watchlist) {
         $classes[] = Sanitizer::escapeClass('watchlist-' . $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title']);
     }
     if (!Hooks::run('OldChangesListRecentChangesLine', array(&$this, &$html, $rc, &$classes))) {
         return false;
     }
     $dateheader = '';
     // $html now contains only <li>...</li>, for hooks' convenience.
     $this->insertDateHeader($dateheader, $rc->mAttribs['rc_timestamp']);
     return "{$dateheader}<li class=\"" . implode(' ', $classes) . "\">" . $html . "</li>\n";
 }
Example #20
0
 /**
  * Converts an XML url or string to a PHP array format
  *
  * @static
  * @access public
  * @param string $data Either an url to an xml file, or a raw XML string. Peachy will autodetect which is which.
  * @return array Parsed XML
  * @throws BadEntryError
  * @throws DependencyError
  * @throws HookError
  * @throws XMLError
  */
 public static function load($data)
 {
     $http = HTTP::getDefaultInstance();
     if (!function_exists('simplexml_load_string')) {
         throw new DependencyError("SimpleXML", "http://us.php.net/manual/en/book.simplexml.php");
     }
     libxml_use_internal_errors(true);
     if (in_string("<?xml", $data)) {
         $xmlout = $data;
     } else {
         $xmlout = $http->get($data);
     }
     Hooks::runHook('PreSimpleXMLLoad', array(&$xmlout));
     $xml = simplexml_load_string($xmlout);
     Hooks::runHook('PostSimpleXMLLoad', array(&$xml));
     if (!$xml) {
         foreach (libxml_get_errors() as $error) {
             throw new XMLError($error);
         }
     }
     $outArr = array();
     $namespaces = $xml->getNamespaces(true);
     $namespaces['default'] = '';
     self::recurse($xml, $outArr, $namespaces);
     libxml_clear_errors();
     return $outArr;
 }
 public function execute()
 {
     if (!$this->getUser()->isLoggedIn()) {
         $this->dieUsage('Must be logged in to remove authentication data', 'notloggedin');
     }
     $params = $this->extractRequestParams();
     $manager = AuthManager::singleton();
     // Check security-sensitive operation status
     ApiAuthManagerHelper::newForModule($this)->securitySensitiveOperation($this->operation);
     // Fetch the request. No need to load from the request, so don't use
     // ApiAuthManagerHelper's method.
     $blacklist = $this->authAction === AuthManager::ACTION_REMOVE ? array_flip($this->getConfig()->get('RemoveCredentialsBlacklist')) : [];
     $reqs = array_filter($manager->getAuthenticationRequests($this->authAction, $this->getUser()), function ($req) use($params, $blacklist) {
         return $req->getUniqueId() === $params['request'] && !isset($blacklist[get_class($req)]);
     });
     if (count($reqs) !== 1) {
         $this->dieUsage('Failed to create change request', 'badrequest');
     }
     $req = reset($reqs);
     // Perform the removal
     $status = $manager->allowsAuthenticationDataChange($req, true);
     Hooks::run('ChangeAuthenticationDataAudit', [$req, $status]);
     if (!$status->isGood()) {
         $this->dieStatus($status);
     }
     $manager->changeAuthenticationData($req);
     $this->getResult()->addValue(null, $this->getModuleName(), ['status' => 'success']);
 }
Example #22
0
 public function finalSetup()
 {
     parent::finalSetup();
     global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache;
     global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
     global $wgLocaltimezone, $wgLocalisationCacheConf;
     global $wgDevelopmentWarnings;
     // Inject test autoloader
     require_once __DIR__ . '/../TestsAutoLoader.php';
     // wfWarn should cause tests to fail
     $wgDevelopmentWarnings = true;
     // Make sure all caches and stashes are either disabled or use
     // in-process cache only to prevent tests from using any preconfigured
     // cache meant for the local wiki from outside the test run.
     // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC.
     // Disabled in DefaultSettings, override local settings
     $wgMainWANCache = $wgMainCacheType = CACHE_NONE;
     // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db
     $wgMessageCacheType = $wgParserCacheType = $wgSessionCacheType = $wgLanguageConverterCacheType = 'hash';
     // Uses db-replicated in DefaultSettings
     $wgMainStash = 'hash';
     $wgUseDatabaseMessages = false;
     # Set for future resets
     // Assume UTC for testing purposes
     $wgLocaltimezone = 'UTC';
     $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
     // Bug 44192 Do not attempt to send a real e-mail
     Hooks::clear('AlternateUserMailer');
     Hooks::register('AlternateUserMailer', function () {
         return false;
     });
     // xdebug's default of 100 is too low for MediaWiki
     ini_set('xdebug.max_nesting_level', 1000);
 }
Example #23
0
 /**
  * @since 1.16.3
  * @throws MWException
  * @param string $collationName
  * @return Collation
  */
 public static function factory($collationName)
 {
     switch ($collationName) {
         case 'uppercase':
             return new UppercaseCollation();
         case 'identity':
             return new IdentityCollation();
         case 'uca-default':
             return new IcuCollation('root');
         case 'xx-uca-ckb':
             return new CollationCkb();
         case 'xx-uca-et':
             return new CollationEt();
         default:
             $match = [];
             if (preg_match('/^uca-([a-z@=-]+)$/', $collationName, $match)) {
                 return new IcuCollation($match[1]);
             }
             # Provide a mechanism for extensions to hook in.
             $collationObject = null;
             Hooks::run('Collation::factory', [$collationName, &$collationObject]);
             if ($collationObject instanceof Collation) {
                 return $collationObject;
             }
             // If all else fails...
             throw new MWException(__METHOD__ . ": unknown collation type \"{$collationName}\"");
     }
 }
 /**
  * Transforms content to be mobile friendly version.
  * Filters out various elements and runs the MobileFormatter.
  * @param OutputPage $out
  * @param string $mode mobile mode, i.e. stable or beta
  *
  * @return string
  */
 public static function DOMParse(OutputPage $out, $text = null, $isBeta = false)
 {
     $html = $text ? $text : $out->getHTML();
     $context = MobileContext::singleton();
     $formatter = MobileFormatter::newFromContext($context, $html);
     Hooks::run('MobileFrontendBeforeDOM', array($context, $formatter));
     $title = $out->getTitle();
     $isSpecialPage = $title->isSpecialPage();
     $formatter->enableExpandableSections($out->canUseWikiPage() && $out->getWikiPage()->getContentModel() == CONTENT_MODEL_WIKITEXT && array_search($title->getNamespace(), $context->getMFConfig()->get('MFNamespacesWithoutCollapsibleSections')) === false && $context->getRequest()->getText('action', 'view') == 'view');
     if ($context->getContentTransformations()) {
         // Remove images if they're disabled from special pages, but don't transform otherwise
         $formatter->filterContent(!$isSpecialPage);
     }
     $contentHtml = $formatter->getText();
     // If the page is a user page which has not been created, then let the
     // user know about it with pretty graphics and different texts depending
     // on whether the user is the owner of the page or not.
     if ($isBeta && $title->inNamespace(NS_USER) && !$title->isSubpage()) {
         $pageUserId = User::idFromName($title->getText());
         if ($pageUserId && !$title->exists()) {
             $pageUser = User::newFromId($pageUserId);
             $contentHtml = ExtMobileFrontend::getUserPageContent($out, $pageUser);
         }
     }
     return $contentHtml;
 }
Example #25
0
 public static function dispatch()
 {
     self::defaults();
     \Hooks::doAction("router.finish");
     self::statusRoutes();
     self::$router->dispatch(null, null, false);
 }
Example #26
0
 public function finalSetup()
 {
     parent::finalSetup();
     global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache;
     global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
     global $wgLocaltimezone, $wgLocalisationCacheConf;
     global $wgDevelopmentWarnings;
     // Inject test autoloader
     require_once __DIR__ . '/../TestsAutoLoader.php';
     // wfWarn should cause tests to fail
     $wgDevelopmentWarnings = true;
     $wgMainCacheType = CACHE_NONE;
     $wgMainWANCache = CACHE_NONE;
     $wgMessageCacheType = CACHE_NONE;
     $wgParserCacheType = CACHE_NONE;
     $wgLanguageConverterCacheType = CACHE_NONE;
     $wgUseDatabaseMessages = false;
     # Set for future resets
     // Assume UTC for testing purposes
     $wgLocaltimezone = 'UTC';
     $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
     // Bug 44192 Do not attempt to send a real e-mail
     Hooks::clear('AlternateUserMailer');
     Hooks::register('AlternateUserMailer', function () {
         return false;
     });
     // xdebug's default of 100 is too low for MediaWiki
     ini_set('xdebug.max_nesting_level', 1000);
 }
Example #27
0
 /**
  * Loads skin and user CSS files.
  * @param OutputPage $out
  */
 function setupSkinUserCss(OutputPage $out)
 {
     parent::setupSkinUserCss($out);
     $styles = array('mediawiki.skinning.interface', 'skins.vector.styles');
     Hooks::run('SkinVectorStyleModules', array($this, &$styles));
     $out->addModuleStyles($styles);
 }
 public function __isset($name)
 {
     // hook functions to Hook class
     if (Hooks::isHookFunction($name) || in_array($name, Core::$instanceClasses) || in_array($name, Core::$classes) || in_array($name, Core::$singletonClasses)) {
         return true;
     }
     return false;
 }
 function getQueryInfo()
 {
     $count = $this->getConfig()->get('WantedPagesThreshold') - 1;
     $query = ['tables' => ['pagelinks', 'pg1' => 'page', 'pg2' => 'page'], 'fields' => ['namespace' => 'pl_namespace', 'title' => 'pl_title', 'value' => 'COUNT(*)'], 'conds' => ['pg1.page_namespace IS NULL', "pl_namespace NOT IN ( '" . NS_USER . "', '" . NS_USER_TALK . "' )", "pg2.page_namespace != '" . NS_MEDIAWIKI . "'"], 'options' => ['HAVING' => ["COUNT(*) > {$count}", "COUNT(*) > SUM(pg2.page_is_redirect)"], 'GROUP BY' => ['pl_namespace', 'pl_title']], 'join_conds' => ['pg1' => ['LEFT JOIN', ['pg1.page_namespace = pl_namespace', 'pg1.page_title = pl_title']], 'pg2' => ['LEFT JOIN', 'pg2.page_id = pl_from']]];
     // Replacement for the WantedPages::getSQL hook
     Hooks::run('WantedPages::getQueryInfo', [&$this, &$query]);
     return $query;
 }
Example #30
0
 public static function parserInit(Parser $parser)
 {
     Hooks::register('ParserBeforeStrip', self::class . '::markBlockMathTags');
     $parser->setHook('math', self::class . '::mathTag');
     $parser->setHook('nomathjax', self::class . '::noMathJaxTag');
     Hooks::register('ParserAfterTidy', self::class . '::afterTidy');
     Hooks::register('BeforePageDisplay', self::class . '::Inject_JS');
     return true;
 }