protected function setSyndicated()
 {
     $request = $this->getRequest();
     $queryParams = array('level' => $request->getIntOrNull('level'), 'tag' => $request->getVal('tag'), 'category' => $request->getVal('category'));
     $this->getOutput()->setSyndicated(true);
     $this->getOutput()->setFeedAppendQuery(wfArrayToCgi($queryParams));
 }
Example #2
0
 /**
  * purge is slightly weird because it can be either formed or formless depending
  * on user permissions
  */
 public function show()
 {
     $this->setHeaders();
     // This will throw exceptions if there's a problem
     $this->checkCanExecute($this->getUser());
     $user = $this->getUser();
     if ($user->pingLimiter('purge')) {
         // TODO: Display actionthrottledtext
         return;
     }
     if ($user->isAllowed('purge')) {
         // This will update the database immediately, even on HTTP GET.
         // Lots of uses may exist for this feature, so just ignore warnings.
         Profiler::instance()->getTransactionProfiler()->resetExpectations();
         $this->redirectParams = wfArrayToCgi(array_diff_key($this->getRequest()->getQueryValues(), ['title' => null, 'action' => null]));
         if ($this->onSubmit([])) {
             $this->onSuccess();
         }
     } else {
         $this->redirectParams = $this->getRequest()->getVal('redirectparams', '');
         $form = $this->getForm();
         if ($form->show()) {
             $this->onSuccess();
         }
     }
 }
Example #3
0
 function __construct()
 {
     parent::__construct();
     $this->classname = "google";
     $this->resourceModules[] = 'ext.MultiMaps.Google';
     $urlArgs = array();
     $urlArgs['sensor'] = 'false';
     $urlArgs['v'] = '3.10';
     $this->headerItem .= \Html::linkedScript('//maps.googleapis.com/maps/api/js?' . wfArrayToCgi($urlArgs)) . "\n";
 }
Example #4
0
 function __construct()
 {
     parent::__construct();
     $this->classname = "yandex";
     $this->resourceModules[] = 'ext.MultiMaps.Yandex';
     $urlArgs = array();
     $urlArgs['load'] = 'package.standard,package.geoObjects';
     $urlArgs['lang'] = 'ru-RU';
     $this->headerItem .= \Html::linkedScript('//api-maps.yandex.ru/2.0-stable/?' . wfArrayToCgi($urlArgs)) . "\n";
 }
Example #5
0
 function passCaptcha()
 {
     global $wgRequest;
     $ticket = $wgRequest->getVal('Asirra_Ticket');
     $api = 'http://challenge.asirra.com/cgi/Asirra?';
     $params = array('action' => 'ValidateTicket', 'ticket' => $ticket);
     $response = Http::get($api . wfArrayToCgi($params));
     $xml = simplexml_load_string($response);
     $result = $xml->xpath('/AsirraValidation/Result');
     return strval($result[0]) === 'Pass';
 }
 /**
  * @return array[]|bool The 'interwikimap' sub-array or false on failure.
  */
 protected function fetchLinks()
 {
     $url = wfArrayToCgi(array('action' => 'query', 'meta' => 'siteinfo', 'siprop' => 'interwikimap', 'sifilteriw' => 'local', 'format' => 'json'));
     if (!empty($this->source)) {
         $url = rtrim($this->source, '?') . '?' . $url;
     }
     $json = Http::get($url);
     $data = json_decode($json, true);
     if (is_array($data)) {
         return $data['query']['interwikimap'];
     } else {
         return false;
     }
 }
 /**
  * Returns the normalized form of the given page title, using the normalization rules of the given site.
  * If the given title is a redirect, the redirect weill be resolved and the redirect target is returned.
  *
  * @note  : This actually makes an API request to the remote site, so beware that this function is slow and depends
  *          on an external service.
  *
  * @note  : If MW_PHPUNIT_TEST is defined, the call to the external site is skipped, and the title
  *          is normalized using the local normalization rules as implemented by the Title class.
  *
  * @see Site::normalizePageName
  *
  * @since 1.21
  *
  * @param string $pageName
  *
  * @return string
  * @throws MWException
  */
 public function normalizePageName($pageName)
 {
     // Check if we have strings as arguments.
     if (!is_string($pageName)) {
         throw new MWException('$pageName must be a string');
     }
     // Go on call the external site
     if (defined('MW_PHPUNIT_TEST')) {
         // If the code is under test, don't call out to other sites, just normalize locally.
         // Note: this may cause results to be inconsistent with the actual normalization used by the respective remote site!
         $t = Title::newFromText($pageName);
         return $t->getPrefixedText();
     } else {
         // Make sure the string is normalized into NFC (due to the bug 40017)
         // but do nothing to the whitespaces, that should work appropriately.
         // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=40017
         $pageName = UtfNormal::cleanUp($pageName);
         // Build the args for the specific call
         $args = array('action' => 'query', 'prop' => 'info', 'redirects' => true, 'converttitles' => true, 'format' => 'json', 'titles' => $pageName);
         $url = $this->getFileUrl('api.php') . '?' . wfArrayToCgi($args);
         // Go on call the external site
         //@todo: we need a good way to specify a timeout here.
         $ret = Http::get($url);
     }
     if ($ret === false) {
         wfDebugLog("MediaWikiSite", "call to external site failed: {$url}");
         return false;
     }
     $data = FormatJson::decode($ret, true);
     if (!is_array($data)) {
         wfDebugLog("MediaWikiSite", "call to <{$url}> returned bad json: " . $ret);
         return false;
     }
     $page = static::extractPageRecord($data, $pageName);
     if (isset($page['missing'])) {
         wfDebugLog("MediaWikiSite", "call to <{$url}> returned a marker for a missing page title! " . $ret);
         return false;
     }
     if (isset($page['invalid'])) {
         wfDebugLog("MediaWikiSite", "call to <{$url}> returned a marker for an invalid page title! " . $ret);
         return false;
     }
     if (!isset($page['title'])) {
         wfDebugLog("MediaWikiSite", "call to <{$url}> did not return a page title! " . $ret);
         return false;
     }
     return $page['title'];
 }
Example #8
0
 /**
  * purge is slightly weird because it can be either formed or formless depending
  * on user permissions
  */
 public function show()
 {
     $this->setHeaders();
     // This will throw exceptions if there's a problem
     $this->checkCanExecute($this->getUser());
     if ($this->getUser()->isAllowed('purge')) {
         $this->redirectParams = wfArrayToCgi(array_diff_key($this->getRequest()->getQueryValues(), array('title' => null, 'action' => null)));
         if ($this->onSubmit(array())) {
             $this->onSuccess();
         }
     } else {
         $this->redirectParams = $this->getRequest()->getVal('redirectparams', '');
         $form = $this->getForm();
         if ($form->show()) {
             $this->onSuccess();
         }
     }
 }
 /**
  * Returns the (partial) URL for the given page (including any section identifier).
  *
  * @param TitleValue $page The link's target
  * @param array $params any additional URL parameters.
  *
  * @return string
  */
 public function getPageUrl(TitleValue $page, $params = array())
 {
     //TODO: move the code from Linker::linkUrl here!
     //The below is just a rough estimation!
     $name = $this->formatter->getPrefixedText($page);
     $name = str_replace(' ', '_', $name);
     $name = wfUrlencode($name);
     $url = $this->baseUrl . $name;
     if ($params) {
         $separator = strpos($url, '?') ? '&' : '?';
         $url .= $separator . wfArrayToCgi($params);
     }
     $fragment = $page->getFragment();
     if ($fragment !== '') {
         $url = $url . '#' . wfUrlencode($fragment);
     }
     return $url;
 }
Example #10
0
 /**
  * Get the HTMLForm to control behavior
  * @return HTMLForm|null
  */
 protected function getForm()
 {
     $this->fields = $this->getFormFields();
     // Give hooks a chance to alter the form, adding extra fields or text etc
     wfRunHooks('ActionModifyFormFields', array($this->getName(), &$this->fields, $this->page));
     $form = new HTMLForm($this->fields, $this->getContext(), $this->getName());
     $form->setSubmitCallback(array($this, 'onSubmit'));
     // Retain query parameters (uselang etc)
     $form->addHiddenField('action', $this->getName());
     // Might not be the same as the query string
     $params = array_diff_key($this->getRequest()->getQueryValues(), array('action' => null, 'title' => null));
     $form->addHiddenField('redirectparams', wfArrayToCgi($params));
     $form->addPreText($this->preText());
     $form->addPostText($this->postText());
     $this->alterForm($form);
     // Give hooks a chance to alter the form, adding extra fields or text etc
     wfRunHooks('ActionBeforeFormDisplay', array($this->getName(), &$form, $this->page));
     return $form;
 }
 /**
  * Gets a DOMDocument, searches it for files, uploads files and markus to webservice and generated PDF.
  * @param DOMDocument $oHtmlDOM The source markup
  * @return string The resulting PDF as bytes
  */
 public function createPDF(&$oHtmlDOM)
 {
     $this->findFiles($oHtmlDOM);
     $this->uploadFiles();
     //HINT: http://www.php.net/manual/en/class.domdocument.php#96055
     //But: Formated Output is evil because is will destroy formatting in <pre> Tags!
     $sHtmlDOM = $oHtmlDOM->saveXML($oHtmlDOM->documentElement);
     //Save temporary
     $sTmpHtmlFile = BSDATADIR . DS . 'UEModulePDF' . DS . $this->aParams['document-token'] . '.html';
     $sTmpPDFFile = BSDATADIR . DS . 'UEModulePDF' . DS . $this->aParams['document-token'] . '.pdf';
     file_put_contents($sTmpHtmlFile, $sHtmlDOM);
     $aOptions = array('timeout' => 120, 'postData' => array('fileType' => '', 'documentToken' => $this->aParams['document-token'], 'sourceHtmlFile_name' => basename($sTmpHtmlFile), 'sourceHtmlFile' => '@' . $sTmpHtmlFile, 'wikiId' => wfWikiID()));
     if (BsConfig::get('MW::TestMode')) {
         $aOptions['postData']['debug'] = "true";
     }
     global $bsgUEModulePDFCURLOptions;
     $aOptions = array_merge_recursive($aOptions, $bsgUEModulePDFCURLOptions);
     wfRunHooks('BSUEModulePDFCreatePDFBeforeSend', array($this, &$aOptions, $oHtmlDOM));
     $vHttpEngine = Http::$httpEngine;
     Http::$httpEngine = 'curl';
     //HINT: http://www.php.net/manual/en/function.curl-setopt.php#refsect1-function.curl-setopt-notes
     //Upload HTML source
     //TODO: Handle $sResponse
     $sResponse = Http::post($this->aParams['soap-service-url'] . '/UploadAsset', $aOptions);
     //Now do the rendering
     //We re-send the paramters but this time without the file.
     unset($aOptions['postData']['sourceHtmlFile']);
     unset($aOptions['postData']['fileType']);
     //We do not want the request to be multipart/formdata because that's more difficult to handle on Servlet-side
     $aOptions['postData'] = wfArrayToCgi($aOptions['postData']);
     $vPdfByteArray = Http::post($this->aParams['soap-service-url'] . '/RenderPDF', $aOptions);
     Http::$httpEngine = $vHttpEngine;
     if ($vPdfByteArray == false) {
         wfDebugLog('BS::UEModulePDF', 'BsPDFServlet::createPDF: Failed creating "' . $this->aParams['document-token'] . '"');
     }
     file_put_contents($sTmpPDFFile, $vPdfByteArray);
     //Remove temporary file
     if (!BsConfig::get('MW::TestMode')) {
         unlink($sTmpHtmlFile);
         unlink($sTmpPDFFile);
     }
     return $vPdfByteArray;
 }
Example #12
0
 /**
  * Get the HTMLForm to control behavior
  * @return HTMLForm|null
  */
 protected function getForm()
 {
     $this->fields = $this->getFormFields();
     // Give hooks a chance to alter the form, adding extra fields or text etc
     Hooks::run('ActionModifyFormFields', [$this->getName(), &$this->fields, $this->page]);
     $form = new HTMLForm($this->fields, $this->getContext(), $this->getName());
     $form->setSubmitCallback([$this, 'onSubmit']);
     $title = $this->getTitle();
     $form->setAction($title->getLocalURL(['action' => $this->getName()]));
     // Retain query parameters (uselang etc)
     $params = array_diff_key($this->getRequest()->getQueryValues(), ['action' => null, 'title' => null]);
     if ($params) {
         $form->addHiddenField('redirectparams', wfArrayToCgi($params));
     }
     $form->addPreText($this->preText());
     $form->addPostText($this->postText());
     $this->alterForm($form);
     // Give hooks a chance to alter the form, adding extra fields or text etc
     Hooks::run('ActionBeforeFormDisplay', [$this->getName(), &$form, $this->page]);
     return $form;
 }
 protected function doPairs()
 {
     if (!isset($this->config['key'])) {
         throw new TranslationWebServiceException('API key is not set');
     }
     $pairs = array();
     $params = array('key' => $this->config['key']);
     $url = $this->config['pairs'] . '?' . wfArrayToCgi($params);
     // BC MW <= 1.24
     $json = Http::request('GET', $url, array('timeout' => $this->config['timeout']));
     $response = FormatJson::decode($json);
     if (!is_object($response)) {
         $exception = 'Malformed reply from remote server: ' . strval($json);
         throw new TranslationWebServiceException($exception);
     }
     foreach ($response->dirs as $pair) {
         list($source, $target) = explode('-', $pair);
         $pairs[$source][$target] = true;
     }
     return $pairs;
 }
Example #14
0
 protected function fetchImageQuery($query)
 {
     global $wgMemc;
     $url = $this->mApiBase . '?' . wfArrayToCgi(array_merge($query, array('format' => 'json', 'action' => 'query')));
     if (!isset($this->mQueryCache[$url])) {
         $key = wfMemcKey('ForeignAPIRepo', 'Metadata', md5($url));
         $data = $wgMemc->get($key);
         if (!$data) {
             $data = Http::get($url);
             if (!$data) {
                 return null;
             }
             $wgMemc->set($key, $data, 3600);
         }
         if (count($this->mQueryCache) > 100) {
             // Keep the cache from growing infinitely
             $this->mQueryCache = array();
         }
         $this->mQueryCache[$url] = $data;
     }
     return json_decode($this->mQueryCache[$url], true);
 }
Example #15
0
 public function show()
 {
     $this->setHeaders();
     // This will throw exceptions if there's a problem
     $this->checkCanExecute($this->getUser());
     $user = $this->getUser();
     if ($user->pingLimiter('purge')) {
         // TODO: Display actionthrottledtext
         return;
     }
     if ($this->getRequest()->wasPosted()) {
         $this->redirectParams = wfArrayToCgi(array_diff_key($this->getRequest()->getQueryValues(), ['title' => null, 'action' => null]));
         if ($this->onSubmit([])) {
             $this->onSuccess();
         }
     } else {
         $this->redirectParams = $this->getRequest()->getVal('redirectparams', '');
         $form = $this->getForm();
         if ($form->show()) {
             $this->onSuccess();
         }
     }
 }
Example #16
0
 /**
  * @param $thread Thread
  * Example return value:
  *	array (
  *		edit => array( 'label'	 => 'Edit',
  *					'href'	  => 'http...',
  *					'enabled' => false ),
  *		reply => array( 'label'	  => 'Reply',
  *					'href'	  => 'http...',
  *					'enabled' => true )
  *	)
  */
 function threadCommands($thread)
 {
     $commands = array();
     $isLqtPage = LqtDispatch::isLqtPage($thread->getTitle());
     $history_url = self::permalinkUrlWithQuery($thread, array('action' => 'history'));
     $commands['history'] = array('label' => wfMessage('history_short')->parse(), 'href' => $history_url, 'enabled' => true);
     if ($thread->isHistorical()) {
         return array();
     }
     $user_can_edit = $thread->root()->getTitle()->quickUserCan('edit');
     $editMsg = $user_can_edit ? 'edit' : 'viewsource';
     if ($isLqtPage) {
         $commands['edit'] = array('label' => wfMessage($editMsg)->parse(), 'href' => $this->talkpageUrl($this->title, 'edit', $thread, true, $this->request), 'enabled' => true);
     }
     if ($this->user->isAllowed('delete')) {
         $delete_url = $thread->title()->getLocalURL('action=delete');
         $deleteMsg = $thread->type() == Threads::TYPE_DELETED ? 'lqt_undelete' : 'delete';
         $commands['delete'] = array('label' => wfMessage($deleteMsg)->parse(), 'href' => $delete_url, 'enabled' => true);
     }
     if ($isLqtPage) {
         if (!$thread->isTopmostThread() && $this->user->isAllowed('lqt-split')) {
             $splitUrl = SpecialPage::getTitleFor('SplitThread', $thread->title()->getPrefixedText())->getLocalURL();
             $commands['split'] = array('label' => wfMessage('lqt-thread-split')->parse(), 'href' => $splitUrl, 'enabled' => true);
         }
         if ($this->user->isAllowed('lqt-merge')) {
             $mergeParams = $_GET;
             $mergeParams['lqt_merge_from'] = $thread->id();
             unset($mergeParams['title']);
             $mergeUrl = $this->title->getLocalURL(wfArrayToCgi($mergeParams));
             $label = wfMessage('lqt-thread-merge')->parse();
             $commands['merge'] = array('label' => $label, 'href' => $mergeUrl, 'enabled' => true);
         }
     }
     $commands['link'] = array('label' => wfMessage('lqt_permalink')->parse(), 'href' => $thread->title()->getLocalURL(), 'enabled' => true, 'showlabel' => true, 'tooltip' => wfMessage('lqt_permalink')->parse());
     Hooks::run('LiquidThreadsThreadCommands', array($thread, &$commands));
     return $commands;
 }
Example #17
0
 /**
  * Appends or replaces value of query variables.
  *
  * @param array $array of values to replace/add to query
  * @param bool $onlyquery whether to only return the query string and not
  *                   the complete URL
  * @return String
  */
 public function appendQueryArray($array, $onlyquery = false)
 {
     global $wgTitle;
     $newquery = $this->getQueryValues();
     unset($newquery['title']);
     $newquery = array_merge($newquery, $array);
     $query = wfArrayToCgi($newquery);
     return $onlyquery ? $query : $wgTitle->getLocalURL($query);
 }
Example #18
0
 /**
  * This function returns an HTML link to the given target.  It serves a few
  * purposes:
  *   1) If $target is a Title, the correct URL to link to will be figured
  *      out automatically.
  *   2) It automatically adds the usual classes for various types of link
  *      targets: "new" for red links, "stub" for short articles, etc.
  *   3) It escapes all attribute values safely so there's no risk of XSS.
  *   4) It provides a default tooltip if the target is a Title (the page
  *      name of the target).
  * link() replaces the old functions in the makeLink() family.
  *
  * @param $target        Title  Can currently only be a Title, but this may
  *   change to support Images, literal URLs, etc.
  * @param $text          string The HTML contents of the <a> element, i.e.,
  *   the link text.  This is raw HTML and will not be escaped.  If null,
  *   defaults to the prefixed text of the Title; or if the Title is just a
  *   fragment, the contents of the fragment.
  * @param $customAttribs array  A key => value array of extra HTML attri-
  *   butes, such as title and class.  (href is ignored.)  Classes will be
  *   merged with the default classes, while other attributes will replace
  *   default attributes.  All passed attribute values will be HTML-escaped.
  *   A false attribute value means to suppress that attribute.
  * @param $query         array  The query string to append to the URL
  *   you're linking to, in key => value array form.  Query keys and values
  *   will be URL-encoded.
  * @param $options string|array  String or array of strings:
  *     'known': Page is known to exist, so don't check if it does.
  *     'broken': Page is known not to exist, so don't check if it does.
  *     'noclasses': Don't add any classes automatically (includes "new",
  *       "stub", "mw-redirect", "extiw").  Only use the class attribute
  *       provided, if any, so you get a simple blue link with no funny i-
  *       cons.
  *     'forcearticlepath': Use the article path always, even with a querystring.
  *       Has compatibility issues on some setups, so avoid wherever possible.
  * @return string HTML <a> attribute
  */
 public static function link($target, $html = null, $customAttribs = array(), $query = array(), $options = array())
 {
     wfProfileIn(__METHOD__);
     if (!$target instanceof Title) {
         wfProfileOut(__METHOD__);
         return "<!-- ERROR -->{$html}";
     }
     $options = (array) $options;
     $dummy = new DummyLinker();
     // dummy linker instance for bc on the hooks
     $ret = null;
     if (!wfRunHooks('LinkBegin', array($dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret))) {
         wfProfileOut(__METHOD__);
         return $ret;
     }
     # Normalize the Title if it's a special page
     $target = self::normaliseSpecialPage($target);
     # If we don't know whether the page exists, let's find out.
     wfProfileIn(__METHOD__ . '-checkPageExistence');
     if (!in_array('known', $options) and !in_array('broken', $options)) {
         if ($target->isKnown()) {
             $options[] = 'known';
         } else {
             $options[] = 'broken';
         }
     }
     wfProfileOut(__METHOD__ . '-checkPageExistence');
     $oldquery = array();
     if (in_array("forcearticlepath", $options) && $query) {
         $oldquery = $query;
         $query = array();
     }
     # Note: we want the href attribute first, for prettiness.
     $attribs = array('href' => self::linkUrl($target, $query, $options));
     if (in_array('forcearticlepath', $options) && $oldquery) {
         $attribs['href'] = wfAppendQuery($attribs['href'], wfArrayToCgi($oldquery));
     }
     $attribs = array_merge($attribs, self::linkAttribs($target, $customAttribs, $options));
     if (is_null($html)) {
         $html = self::linkText($target);
     }
     $ret = null;
     if (wfRunHooks('LinkEnd', array($dummy, $target, $options, &$html, &$attribs, &$ret))) {
         $ret = Html::rawElement('a', $attribs, $html);
     }
     wfProfileOut(__METHOD__);
     return $ret;
 }
Example #19
0
 protected function _proxy($params)
 {
     foreach ($params as $key => $val) {
         if (is_null($val)) {
             // Don't pass nulls to remote
             unset($params[$key]);
         }
     }
     $target = $this->mProxy . '?' . wfArrayToCgi($params);
     $blob = Http::get($target, $this->mTimeout);
     if ($blob === false) {
         throw new MWException("SVN proxy error");
     }
     $data = unserialize($blob);
     return $data;
 }
Example #20
0
/**
 * Append a query string to an existing URL, which may or may not already
 * have query string parameters already. If so, they will be combined.
 *
 * @param string $url
 * @param string|string[] $query String or associative array
 * @return string
 */
function wfAppendQuery($url, $query)
{
    if (is_array($query)) {
        $query = wfArrayToCgi($query);
    }
    if ($query != '') {
        if (false === strpos($url, '?')) {
            $url .= '?';
        } else {
            $url .= '&';
        }
        $url .= $query;
    }
    return $url;
}
Example #21
0
function getEscapedProfileUrl($_filter = false, $_sort = false, $_expand = false)
{
    // @codingStandardsIgnoreStart
    global $filter, $sort, $expand;
    // @codingStandardsIgnoreEnd
    if ($_expand === false) {
        $_expand = $expand;
    }
    return htmlspecialchars('?' . wfArrayToCgi(['filter' => $_filter ? $_filter : $filter, 'sort' => $_sort ? $_sort : $sort, 'expand' => implode(',', array_keys($_expand))]));
}
 /**
  * Get the query string to append to feed link URLs.
  *
  * @return string
  */
 public function getFeedQuery()
 {
     global $wgFeedLimit;
     $this->getOptions()->validateIntBounds('limit', 0, $wgFeedLimit);
     $options = $this->getOptions()->getChangedValues();
     // wfArrayToCgi() omits options set to null or false
     foreach ($options as &$value) {
         if ($value === false) {
             $value = '0';
         }
     }
     unset($value);
     return wfArrayToCgi($options);
 }
Example #23
0
 /**
  * @dataProvider provideCgiRoundTrip
  * @covers ::wfArrayToCgi
  */
 public function testCgiRoundTrip($cgi)
 {
     $this->assertEquals($cgi, wfArrayToCgi(wfCgiToArray($cgi)));
 }
 /**
  * build array of urls for personal toolbar
  * @return array
  */
 protected function buildPersonalUrls()
 {
     $title = $this->getTitle();
     $request = $this->getRequest();
     $pageurl = $title->getLocalURL();
     /* set up the default links for the personal toolbar */
     $personal_urls = array();
     # Due to bug 32276, if a user does not have read permissions,
     # $this->getTitle() will just give Special:Badtitle, which is
     # not especially useful as a returnto parameter. Use the title
     # from the request instead, if there was one.
     if ($this->getUser()->isAllowed('read')) {
         $page = $this->getTitle();
     } else {
         $page = Title::newFromText($request->getVal('title', ''));
     }
     $page = $request->getVal('returnto', $page);
     $a = array();
     if (strval($page) !== '') {
         $a['returnto'] = $page;
         $query = $request->getVal('returntoquery', $this->thisquery);
         if ($query != '') {
             $a['returntoquery'] = $query;
         }
     }
     $returnto = wfArrayToCgi($a);
     if ($this->loggedin) {
         $personal_urls['userpage'] = array('text' => $this->username, 'href' => &$this->userpageUrlDetails['href'], 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', 'active' => $this->userpageUrlDetails['href'] == $pageurl, 'dir' => 'auto');
         $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
         $personal_urls['mytalk'] = array('text' => $this->msg('mytalk')->text(), 'href' => &$usertalkUrlDetails['href'], 'class' => $usertalkUrlDetails['exists'] ? false : 'new', 'active' => $usertalkUrlDetails['href'] == $pageurl);
         $href = self::makeSpecialUrl('Preferences');
         $personal_urls['preferences'] = array('text' => $this->msg('mypreferences')->text(), 'href' => $href, 'active' => $href == $pageurl);
         if ($this->getUser()->isAllowed('viewmywatchlist')) {
             $href = self::makeSpecialUrl('Watchlist');
             $personal_urls['watchlist'] = array('text' => $this->msg('mywatchlist')->text(), 'href' => $href, 'active' => $href == $pageurl);
         }
         # We need to do an explicit check for Special:Contributions, as we
         # have to match both the title, and the target, which could come
         # from request values (Special:Contributions?target=Jimbo_Wales)
         # or be specified in "sub page" form
         # (Special:Contributions/Jimbo_Wales). The plot
         # thickens, because the Title object is altered for special pages,
         # so it doesn't contain the original alias-with-subpage.
         $origTitle = Title::newFromText($request->getText('title'));
         if ($origTitle instanceof Title && $origTitle->isSpecialPage()) {
             list($spName, $spPar) = SpecialPageFactory::resolveAlias($origTitle->getText());
             $active = $spName == 'Contributions' && ($spPar && $spPar == $this->username || $request->getText('target') == $this->username);
         } else {
             $active = false;
         }
         $href = self::makeSpecialUrlSubpage('Contributions', $this->username);
         $personal_urls['mycontris'] = array('text' => $this->msg('mycontris')->text(), 'href' => $href, 'active' => $active);
         $personal_urls['logout'] = array('text' => $this->msg('pt-userlogout')->text(), 'href' => self::makeSpecialUrl('Userlogout', $title->isSpecial('Preferences') ? 'noreturnto' : $returnto), 'active' => false);
     } else {
         $useCombinedLoginLink = $this->useCombinedLoginLink();
         $loginlink = $this->getUser()->isAllowed('createaccount') && $useCombinedLoginLink ? 'nav-login-createaccount' : 'pt-login';
         $is_signup = $request->getText('type') == 'signup';
         $login_url = array('text' => $this->msg($loginlink)->text(), 'href' => self::makeSpecialUrl('Userlogin', $returnto), 'active' => $title->isSpecial('Userlogin') && ($loginlink == 'nav-login-createaccount' || !$is_signup));
         $createaccount_url = array('text' => $this->msg('pt-createaccount')->text(), 'href' => self::makeSpecialUrl('Userlogin', "{$returnto}&type=signup"), 'active' => $title->isSpecial('Userlogin') && $is_signup);
         if ($this->showIPinHeader()) {
             $href =& $this->userpageUrlDetails['href'];
             $personal_urls['anonuserpage'] = array('text' => $this->username, 'href' => $href, 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', 'active' => $pageurl == $href);
             $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
             $href =& $usertalkUrlDetails['href'];
             $personal_urls['anontalk'] = array('text' => $this->msg('anontalk')->text(), 'href' => $href, 'class' => $usertalkUrlDetails['exists'] ? false : 'new', 'active' => $pageurl == $href);
         }
         if ($this->getUser()->isAllowed('createaccount') && !$useCombinedLoginLink) {
             $personal_urls['createaccount'] = $createaccount_url;
         }
         $personal_urls['login'] = $login_url;
     }
     Hooks::run('PersonalUrls', array(&$personal_urls, &$title, $this));
     return $personal_urls;
 }
Example #25
0
 /**
  * Output a standard permission error page
  *
  * @param array $errors Error message keys
  * @param string $action Action that was denied or null if unknown
  */
 public function showPermissionsErrorPage(array $errors, $action = null)
 {
     // For some action (read, edit, create and upload), display a "login to do this action"
     // error if all of the following conditions are met:
     // 1. the user is not logged in
     // 2. the only error is insufficient permissions (i.e. no block or something else)
     // 3. the error can be avoided simply by logging in
     if (in_array($action, array('read', 'edit', 'createpage', 'createtalk', 'upload')) && $this->getUser()->isAnon() && count($errors) == 1 && isset($errors[0][0]) && ($errors[0][0] == 'badaccess-groups' || $errors[0][0] == 'badaccess-group0') && (User::groupHasPermission('user', $action) || User::groupHasPermission('autoconfirmed', $action))) {
         $displayReturnto = null;
         # Due to bug 32276, if a user does not have read permissions,
         # $this->getTitle() will just give Special:Badtitle, which is
         # not especially useful as a returnto parameter. Use the title
         # from the request instead, if there was one.
         $request = $this->getRequest();
         $returnto = Title::newFromURL($request->getVal('title', ''));
         if ($action == 'edit') {
             $msg = 'whitelistedittext';
             $displayReturnto = $returnto;
         } elseif ($action == 'createpage' || $action == 'createtalk') {
             $msg = 'nocreatetext';
         } elseif ($action == 'upload') {
             $msg = 'uploadnologintext';
         } else {
             # Read
             $msg = 'loginreqpagetext';
             $displayReturnto = Title::newMainPage();
         }
         $query = array();
         if ($returnto) {
             $query['returnto'] = $returnto->getPrefixedText();
             if (!$request->wasPosted()) {
                 $returntoquery = $request->getValues();
                 unset($returntoquery['title']);
                 unset($returntoquery['returnto']);
                 unset($returntoquery['returntoquery']);
                 $query['returntoquery'] = wfArrayToCgi($returntoquery);
             }
         }
         $loginLink = Linker::linkKnown(SpecialPage::getTitleFor('Userlogin'), $this->msg('loginreqlink')->escaped(), array(), $query);
         $this->prepareErrorPage($this->msg('loginreqtitle'));
         $this->addHTML($this->msg($msg)->rawParams($loginLink)->parse());
         # Don't return to a page the user can't read otherwise
         # we'll end up in a pointless loop
         if ($displayReturnto && $displayReturnto->userCan('read', $this->getUser())) {
             $this->returnToMain(null, $displayReturnto);
         }
     } else {
         $this->prepareErrorPage($this->msg('permissionserrors'));
         $this->addWikiText($this->formatPermissionsErrorMessage($errors, $action));
     }
 }
Example #26
0
 /**
  * Helper to fix up the get{Canonical,Full,Link,Local,Internal}URL args
  * get{Canonical,Full,Link,Local,Internal}URL methods accepted an optional
  * second argument named variant. This was deprecated in favor
  * of passing an array of option with a "variant" key
  * Once $query2 is removed for good, this helper can be dropped
  * and the wfArrayToCgi moved to getLocalURL();
  *
  * @since 1.19 (r105919)
  * @param array|string $query
  * @param bool $query2
  * @return string
  */
 private static function fixUrlQueryArgs($query, $query2 = false)
 {
     if ($query2 !== false) {
         wfDeprecated("Title::get{Canonical,Full,Link,Local,Internal}URL " . "method called with a second parameter is deprecated. Add your " . "parameter to an array passed as the first parameter.", "1.19");
     }
     if (is_array($query)) {
         $query = wfArrayToCgi($query);
     }
     if ($query2) {
         if (is_string($query2)) {
             // $query2 is a string, we will consider this to be
             // a deprecated $variant argument and add it to the query
             $query2 = wfArrayToCgi(array('variant' => $query2));
         } else {
             $query2 = wfArrayToCgi($query2);
         }
         // If we have $query content add a & to it first
         if ($query) {
             $query .= '&';
         }
         // Now append the queries together
         $query .= $query2;
     }
     return $query;
 }
 /**
  * Creates a login or logout button
  * @return array Representation of button with text and href keys
  */
 protected function getLogInOutLink()
 {
     $query = array();
     if (!$this->getRequest()->wasPosted()) {
         $returntoquery = $this->getRequest()->getValues();
         unset($returntoquery['title']);
         unset($returntoquery['returnto']);
         unset($returntoquery['returntoquery']);
     }
     $title = $this->getTitle();
     // Don't ever redirect back to the login page (bug 55379)
     if (!$title->isSpecial('Userlogin')) {
         $query['returnto'] = $title->getPrefixedText();
     }
     $user = $this->getUser();
     if ($user->isLoggedIn()) {
         if (!empty($returntoquery)) {
             $query['returntoquery'] = wfArrayToCgi($returntoquery);
         }
         $url = SpecialPage::getTitleFor('Userlogout')->getFullURL($query);
         $url = $this->mobileContext->getMobileUrl($url, $this->getConfig()->get('SecureLogin'));
         $username = $user->getName();
         $loginLogoutLink = array('name' => 'auth', 'components' => array(array('text' => $username, 'href' => SpecialPage::getTitleFor('UserProfile', $username)->getLocalUrl(), 'class' => MobileUI::iconClass('profile', 'before', 'truncated-text primary-action'), 'data-event-name' => 'profile'), array('text' => wfMessage('mobile-frontend-main-menu-logout')->escaped(), 'href' => $url, 'class' => MobileUI::iconClass('secondary-logout', 'element', 'secondary-action truncated-text'), 'data-event-name' => 'logout')));
     } else {
         // note returnto is not set for mobile (per product spec)
         // note welcome=yes in returnto  allows us to detect accounts created from the left nav
         $returntoquery['welcome'] = 'yes';
         // unset campaign on login link so as not to interfere with A/B tests
         unset($returntoquery['campaign']);
         $query['returntoquery'] = wfArrayToCgi($returntoquery);
         $url = $this->getLoginUrl($query);
         $loginLogoutLink = array('name' => 'auth', 'components' => array(array('text' => wfMessage('mobile-frontend-main-menu-login')->escaped(), 'href' => $url, 'class' => MobileUI::iconClass('anonymous-white', 'before'), 'data-event-name' => 'login')), 'class' => 'jsonly');
     }
     return $loginLogoutLink;
 }
Example #28
0
 /**
  * Appends or replaces value of query variables.
  *
  * @param array $array Array of values to replace/add to query
  * @param bool $onlyquery Whether to only return the query string
  *  and not the complete URL [deprecated]
  * @return string
  */
 public function appendQueryArray($array, $onlyquery = true)
 {
     global $wgTitle;
     $newquery = $this->getQueryValues();
     unset($newquery['title']);
     $newquery = array_merge($newquery, $array);
     $query = wfArrayToCgi($newquery);
     if (!$onlyquery) {
         wfDeprecated(__METHOD__, '1.25');
         return $wgTitle->getLocalURL($query);
     }
     return $query;
 }
Example #29
0
 /**
  * @param array $query
  * @param string $secretKey
  * @return string
  */
 public static function getQuerySignature(array $query, $secretKey)
 {
     ksort($query);
     // stable order
     return hash_hmac('sha1', wfArrayToCgi($query), $secretKey);
 }
 /**
  * Show a form for filtering namespace and username
  *
  * @param $par String
  * @return String
  */
 public function execute($par)
 {
     $out = $this->getOutput();
     $this->setHeaders();
     $this->outputHeader();
     $this->showNavigation = !$this->including();
     // Maybe changed in setup
     $this->setup($par);
     if (!$this->including()) {
         // Settings
         $this->form();
         $feedType = $this->opts->getValue('feed');
         if ($feedType) {
             $this->feed($feedType);
             return;
         }
         $allValues = $this->opts->getAllValues();
         unset($allValues['feed']);
         $out->setFeedAppendQuery(wfArrayToCgi($allValues));
     }
     $pager = new NewPagesPager($this, $this->opts);
     $pager->mLimit = $this->opts->getValue('limit');
     $pager->mOffset = $this->opts->getValue('offset');
     if ($pager->getNumRows()) {
         $navigation = '';
         if ($this->showNavigation) {
             $navigation = $pager->getNavigationBar();
         }
         $out->addHTML($navigation . $pager->getBody() . $navigation);
     } else {
         $out->addWikiMsg('specialpage-empty');
     }
 }