/**
  * Returns HTML of license link or empty string
  * For example:
  *   "<a title="Wikipedia:Copyright" href="/index.php/Wikipedia:Copyright">CC BY</a>"
  *
  * @param string $context The context in which the license link appears, e.g. footer,
  *   editor, talk, or upload.
  * @param array $attribs An associative array of extra HTML attributes to add to the link
  * @return string
  */
 public static function getLicense($context, $attribs = array())
 {
     $config = MobileContext::singleton()->getConfig();
     $rightsPage = $config->get('RightsPage');
     $rightsUrl = $config->get('RightsUrl');
     $rightsText = $config->get('RightsText');
     // Construct the link to the licensing terms
     if ($rightsText) {
         // Use shorter text for some common licensing strings. See Installer.i18n.php
         // for the currently offered strings. Unfortunately, there is no good way to
         // comprehensively support localized licensing strings since the license (as
         // stored in LocalSettings.php) is just freeform text, not an i18n key.
         $commonLicenses = array('Creative Commons Attribution-Share Alike 3.0' => 'CC BY-SA 3.0', 'Creative Commons Attribution Share Alike' => 'CC BY-SA', 'Creative Commons Attribution 3.0' => 'CC BY 3.0', 'Creative Commons Attribution 2.5' => 'CC BY 2.5', 'Creative Commons Attribution' => 'CC BY', 'Creative Commons Attribution Non-Commercial Share Alike' => 'CC BY-NC-SA', 'Creative Commons Zero (Public Domain)' => 'CC0 (Public Domain)', 'GNU Free Documentation License 1.3 or later' => 'GFDL 1.3 or later');
         if (isset($commonLicenses[$rightsText])) {
             $rightsText = $commonLicenses[$rightsText];
         }
         if ($rightsPage) {
             $title = Title::newFromText($rightsPage);
             $link = Linker::linkKnown($title, $rightsText, $attribs);
         } elseif ($rightsUrl) {
             $link = Linker::makeExternalLink($rightsUrl, $rightsText, true, '', $attribs);
         } else {
             $link = $rightsText;
         }
     } else {
         $link = '';
     }
     // Allow other extensions (for example, WikimediaMessages) to override
     $msg = 'mobile-frontend-copyright';
     Hooks::run('MobileLicenseLink', array(&$link, $context, $attribs, &$msg));
     return array('msg' => $msg, 'link' => $link, 'plural' => self::getPluralLicenseInfo($link));
 }
Example #2
0
 /**
  * Convenience to get a link to a page on a foreign wiki
  *
  * @param $wikiID String: wiki'd id (generally database name)
  * @param $page String: page name (must be normalised before calling this function!)
  * @param $text String: link's text; optional, default to $page
  * @return String: HTML link or false if the wiki was not found
  */
 public static function makeForeignLink($wikiID, $page, $text = null)
 {
     if (!$text) {
         $text = $page;
     }
     $url = self::getForeignURL($wikiID, $page);
     if ($url === false) {
         return false;
     }
     return Linker::makeExternalLink($url, $text);
 }
Example #3
0
/**
 * Creates a HTML link that will open in a new browser window or tab.
 *
 * @param Parser $parser Parser being used
 * @param string $target literal URI or a MediaWiki link for linked resource
 * @param string $label link text
 * @return string HTML
 */
function efParserCreateLink($parser, $target, $label = null)
{
    // sanitise the input and set defaults
    if (is_null($label)) {
        $label = $target;
        $label = htmlspecialchars($label, ENT_NOQUOTES, 'UTF-8');
    } else {
        $label = preg_replace("/\\b({$parser->mUrlProtocols})/", "\$1 ", $label);
        // Hack to not parse external links by breaking them
        $label = $parser->recursiveTagParse($label);
        $label = preg_replace("/\\b({$parser->mUrlProtocols}) /", "\$1", $label);
        // Put them back together
    }
    $attributes = array('target' => '_blank');
    // WARNING: the order of the statements below does matter!
    //
    // Also, the Parser::insertStripItem is used to render the HTML inline.
    // See: http://www.mediawiki.org/wiki/Manual:Parser_functions#Parser_interface
    // Process (or rule out) external targets (literal URIs)
    if (preg_match($parser->mExtLinkBracketedRegex, "[{$target}]")) {
        return $parser->insertStripItem(Linker::makeExternalLink($target, $label, false, '', $attributes), $parser->mStripState);
    }
    // The target is not a literal URI.  Create a Title object.
    $oTitle = Title::newFromText($target);
    // Title::newFromText may occasionally return null, which means something is really wrong with the $target.
    if (is_null($oTitle)) {
        return $parser->insertStripItem(wfMsg('newwindowlinks-invalid-target'), $parser->mStripState);
    }
    // Process (or rule out) existing local articles.
    if ($oTitle->exists()) {
        return $parser->insertStripItem(Linker::link($oTitle, $label, $attributes), $parser->mStripState);
    }
    // Process (or rule out) interwiki links.
    if (true !== $oTitle->isLocal()) {
        return $parser->insertStripItem(Linker::makeExternalLink($oTitle->getFullURL(), $label, false, '', $attributes), $parser->mStripState);
    }
    // Only non existing local articles remain.
    return $parser->insertStripItem(Linker::link($oTitle, $label, $attributes), $parser->mStripState);
}
 public function getList($limit = 10, $offset = 0, $wikiName = null, $criteria = array(), $order = 'city_created DESC')
 {
     $data = array('count' => 0, 'items' => array());
     $where = array();
     // processing parameters for DB query: the criteria
     foreach ($criteria as $v) {
         if (isset($this->criteria[$v])) {
             $where[$this->criteria[$v]['column']] = 1;
         }
     }
     // display wikis having names starting with $wikiName
     if (!empty($wikiName)) {
         $where[] = 'city_url >= ' . $this->db->addQuotes('http://' . $wikiName);
     }
     // check for the number of wikis matching the given criteria
     $oRow = $this->db->selectRow('noreptemp.spamwikis', 'count(0) as cnt', $where, __METHOD__, null);
     if (is_object($oRow)) {
         $data['count'] = $oRow->cnt;
     }
     // empty set, so let's give up here
     if (0 == $data['count']) {
         return $data;
     }
     // if one or more wikis match the given criteria, fetch the actual data
     $res = $this->db->select('noreptemp.spamwikis', array('city_id', 'city_url', 'city_title', 'city_created', 'city_founding_user'), $where, __METHOD__, array('LIMIT' => $limit, 'OFFSET' => $offset, 'ORDER BY' => $order));
     // process the data
     while ($oRow = $this->db->fetchObject($res)) {
         // fetch and format the information about the user, who created the wiki
         $user = User::newFromId($oRow->city_founding_user);
         $mail = $user->getEmail();
         if (!empty($mail)) {
             $mail = Linker::makeExternalLink('mailto:' . $user->getEmail(), $user->getEmail(), false);
         }
         // format the output
         $data['items'][] = array('<input type="checkbox" name="close[' . $oRow->city_id . ']" value="1" />', '<b>' . $oRow->city_title . '</b><br /><small>' . Linker::makeExternalLink($oRow->city_url, $oRow->city_url, false) . '</small>', $oRow->city_created, Linker::link($user->getUserPage(), $user->getName()), $mail);
     }
     // return the output
     return $data;
 }
Example #5
0
 /**
  * @param string $type
  * @return string
  */
 function getCopyright($type = 'detect')
 {
     global $wgRightsPage, $wgRightsUrl, $wgRightsText;
     if ($type == 'detect') {
         if (!$this->isRevisionCurrent() && !$this->msg('history_copyright')->inContentLanguage()->isDisabled()) {
             $type = 'history';
         } else {
             $type = 'normal';
         }
     }
     if ($type == 'history') {
         $msg = 'history_copyright';
     } else {
         $msg = 'copyright';
     }
     if ($wgRightsPage) {
         $title = Title::newFromText($wgRightsPage);
         $link = Linker::linkKnown($title, $wgRightsText);
     } elseif ($wgRightsUrl) {
         $link = Linker::makeExternalLink($wgRightsUrl, $wgRightsText);
     } elseif ($wgRightsText) {
         $link = $wgRightsText;
     } else {
         # Give up now
         return '';
     }
     // Allow for site and per-namespace customization of copyright notice.
     // @todo Remove deprecated $forContent param from hook handlers and then remove here.
     $forContent = true;
     Hooks::run('SkinCopyrightFooter', array($this->getTitle(), $type, &$msg, &$link, &$forContent));
     return $this->msg($msg)->rawParams($link)->text();
 }
Example #6
0
 /**
  * @return string
  */
 function sysLinks()
 {
     $s = array($this->getSkin()->mainPageLink(), Linker::linkKnown(Title::newFromText(wfMessage('aboutpage')->inContentLanguage()->text()), wfMessage('about')->text()), Linker::makeExternalLink(Skin::makeInternalOrExternalUrl(wfMessage('helppage')->inContentLanguage()->text()), wfMessage('help')->text(), false), Linker::linkKnown(Title::newFromText(wfMessage('faqpage')->inContentLanguage()->text()), wfMessage('faq')->text()));
     $personalUrls = $this->getPersonalTools();
     foreach (array('logout', 'createaccount', 'login') as $key) {
         if ($personalUrls[$key]) {
             $s[] = $this->makeListItem($key, $personalUrls[$key], array('tag' => 'span'));
         }
     }
     return $this->getSkin()->getLanguage()->pipeList($s);
 }
	/**
	 * @return String
	 */
	public function showIncubatingWiki() {
		global $wgLang;
		$substatus = $this->mSubStatus;
		if( $substatus == 'imported' && $this->mIsSister ) {
			$substatus = 'closedsister';
		}
		$portalLink = Linker::makeExternalLink( $this->mPortal, $this->mProjectName );
		if( $this->mThisLangData['type'] != 'invalid' ) {
			$gotoLink = Linker::link(
				IncubatorTest::getMainPage( $this->mLangCode, $this->mPrefix ),
				wfMsgNoTrans( 'wminc-infopage-enter' ) );
			$gotoMainPage = Html::rawElement( 'span',
				array( 'class' => 'wminc-infopage-entertest' ),
				$wgLang->getArrow() . ' ' . ( $this->mIsSister ? $portalLink : $gotoLink ) );
		}
		$subdomain = IncubatorTest::getSubdomain( $this->mLangCode, $this->mProjectCode );
		$subdomainLink = IncubatorTest::makeExternalLinkText( $subdomain, true );
		$content = Html::rawElement( 'div', array( 'class' => 'wminc-infopage-status' ),
			wfMsgWikiHtml( 'wminc-infopage-status-' . $substatus, $subdomainLink, $portalLink ) );
		if( $this->mSubStatus != 'approved' && $this->mThisLangData['type'] != 'invalid' ) {
			$content .= Html::element( 'div',
				array( 'class' => 'wminc-infopage-contribute' ),
				wfMsg( 'wminc-infopage-contribute' ) );
		}
		return $this->StandardInfoPage( '', $gotoMainPage, $content );
	}
Example #8
0
 /**
  * Creates and formats a version line for a single extension.
  *
  * Information for five columns will be created. Parameters required in the
  * $extension array for part rendering are indicated in ()
  *  - The name of (name), and URL link to (url), the extension
  *  - Official version number (version) and if available version control system
  *    revision (path), link, and date
  *  - If available the short name of the license (license-name) and a linke
  *    to ((LICENSE)|(COPYING))(\.txt)? if it exists.
  *  - Description of extension (descriptionmsg or description)
  *  - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
  *
  * @param $extension Array
  *
  * @return string raw HTML
  */
 function getCreditsForExtension(array $extension)
 {
     $out = $this->getOutput();
     // We must obtain the information for all the bits and pieces!
     // ... such as extension names and links
     $extensionName = isset($extension['name']) ? $extension['name'] : '[no name]';
     if (isset($extension['url'])) {
         $extensionNameLink = Linker::makeExternalLink($extension['url'], $extensionName, true, '', array('class' => 'mw-version-ext-name'));
     } else {
         $extensionNameLink = $extensionName;
     }
     // ... and the version information
     // If the extension path is set we will check that directory for GIT and SVN
     // metadata in an attempt to extract date and vcs commit metadata.
     $canonicalVersion = '&ndash;';
     $extensionPath = null;
     $vcsVersion = null;
     $vcsLink = null;
     $vcsDate = null;
     if (isset($extension['version'])) {
         $canonicalVersion = $out->parseInline($extension['version']);
     }
     if (isset($extension['path'])) {
         $extensionPath = dirname($extension['path']);
         $gitInfo = new GitInfo($extensionPath);
         $vcsVersion = $gitInfo->getHeadSHA1();
         if ($vcsVersion !== false) {
             $vcsVersion = substr($vcsVersion, 0, 7);
             $vcsLink = $gitInfo->getHeadViewUrl();
             $vcsDate = $gitInfo->getHeadCommitDate();
         } else {
             $svnInfo = self::getSvnInfo($extensionPath);
             if ($svnInfo !== false) {
                 $vcsVersion = $this->msg('version-svn-revision', $svnInfo['checkout-rev'])->text();
                 $vcsLink = isset($svnInfo['viewvc-url']) ? $svnInfo['viewvc-url'] : '';
             }
         }
     }
     $versionString = Html::rawElement('span', array('class' => 'mw-version-ext-version'), $canonicalVersion);
     if ($vcsVersion) {
         if ($vcsLink) {
             $vcsVerString = Linker::makeExternalLink($vcsLink, $this->msg('version-version', $vcsVersion), true, '', array('class' => 'mw-version-ext-vcs-version'));
         } else {
             $vcsVerString = Html::element('span', array('class' => 'mw-version-ext-vcs-version'), "({$vcsVersion})");
         }
         $versionString .= " {$vcsVerString}";
         if ($vcsDate) {
             $vcsTimeString = Html::element('span', array('class' => 'mw-version-ext-vcs-timestamp'), $this->getLanguage()->timeanddate($vcsDate));
             $versionString .= " {$vcsTimeString}";
         }
         $versionString = Html::rawElement('span', array('class' => 'mw-version-ext-meta-version'), $versionString);
     }
     // ... and license information; if a license file exists we
     // will link to it
     $licenseLink = '';
     if (isset($extension['license-name'])) {
         $licenseLink = Linker::link($this->getPageTitle('License/' . $extensionName), $out->parseInline($extension['license-name']), array('class' => 'mw-version-ext-license'));
     } elseif ($this->getExtLicenseFileName($extensionPath)) {
         $licenseLink = Linker::link($this->getPageTitle('License/' . $extensionName), $this->msg('version-ext-license'), array('class' => 'mw-version-ext-license'));
     }
     // ... and generate the description; which can be a parameterized l10n message
     // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
     // up string
     if (isset($extension['descriptionmsg'])) {
         // Localized description of extension
         $descriptionMsg = $extension['descriptionmsg'];
         if (is_array($descriptionMsg)) {
             $descriptionMsgKey = $descriptionMsg[0];
             // Get the message key
             array_shift($descriptionMsg);
             // Shift out the message key to get the parameters only
             array_map("htmlspecialchars", $descriptionMsg);
             // For sanity
             $description = $this->msg($descriptionMsgKey, $descriptionMsg)->text();
         } else {
             $description = $this->msg($descriptionMsg)->text();
         }
     } elseif (isset($extension['description'])) {
         // Non localized version
         $description = $extension['description'];
     } else {
         $description = '';
     }
     $description = $out->parseInline($description);
     // ... now get the authors for this extension
     $authors = isset($extension['author']) ? $extension['author'] : array();
     $authors = $this->listAuthors($authors, $extensionName, $extensionPath);
     // Finally! Create the table
     $html = Html::openElement('tr', array('class' => 'mw-version-ext', 'id' => "mw-version-ext-{$extensionName}"));
     $html .= Html::rawElement('td', array(), $extensionNameLink);
     $html .= Html::rawElement('td', array(), $versionString);
     $html .= Html::rawElement('td', array(), $licenseLink);
     $html .= Html::rawElement('td', array('class' => 'mw-version-ext-description'), $description);
     $html .= Html::rawElement('td', array('class' => 'mw-version-ext-authors'), $authors);
     $html .= Html::closeElement('td');
     return $html;
 }
Example #9
0
File: Linker.php Project: paladox/2
 /**
  * Generates a link to the given Title
  *
  * @note This is only public for technical reasons. It's not intended for use outside Linker.
  *
  * @param Title $title
  * @param string $text
  * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
  *  as used by WikiMap.
  * @param string|string[] $options See the $options parameter in Linker::link.
  *
  * @return string HTML link
  */
 public static function makeCommentLink(Title $title, $text, $wikiId = null, $options = array())
 {
     if ($wikiId !== null && !$title->isExternal()) {
         $link = Linker::makeExternalLink(WikiMap::getForeignURL($wikiId, $title->getPrefixedText(), $title->getFragment()), $text, false);
     } else {
         $link = Linker::link($title, $text, array(), array(), $options);
     }
     return $link;
 }
Example #10
0
 function getCopyright($type = 'detect')
 {
     global $wgRightsPage, $wgRightsUrl, $wgRightsText;
     if ($type == 'detect') {
         $diff = $this->getRequest()->getVal('diff');
         if (is_null($diff) && !$this->isRevisionCurrent() && wfMsgForContent('history_copyright') !== '-') {
             $type = 'history';
         } else {
             $type = 'normal';
         }
     }
     if ($type == 'history') {
         $msg = 'history_copyright';
     } else {
         $msg = 'copyright';
     }
     $out = '';
     if ($wgRightsPage) {
         $title = Title::newFromText($wgRightsPage);
         $link = Linker::linkKnown($title, $wgRightsText);
     } elseif ($wgRightsUrl) {
         $link = Linker::makeExternalLink($wgRightsUrl, $wgRightsText);
     } elseif ($wgRightsText) {
         $link = $wgRightsText;
     } else {
         # Give up now
         return $out;
     }
     // Allow for site and per-namespace customization of copyright notice.
     $forContent = true;
     wfRunHooks('SkinCopyrightFooter', array($this->getTitle(), $type, &$msg, &$link, &$forContent));
     if ($forContent) {
         $out .= wfMsgForContent($msg, $link);
     } else {
         $out .= wfMsg($msg, $link);
     }
     return $out;
 }
Example #11
0
 public function makeExternalLink($url, $text, $escape = true, $linktype = '', $attribs = [], $title = null)
 {
     return Linker::makeExternalLink($url, $text, $escape, $linktype, $attribs, $title);
 }
Example #12
0
 /**
  * Creates and formats a version line for a single extension.
  *
  * Information for five columns will be created. Parameters required in the
  * $extension array for part rendering are indicated in ()
  *  - The name of (name), and URL link to (url), the extension
  *  - Official version number (version) and if available version control system
  *    revision (path), link, and date
  *  - If available the short name of the license (license-name) and a link
  *    to ((LICENSE)|(COPYING))(\.txt)? if it exists.
  *  - Description of extension (descriptionmsg or description)
  *  - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
  *
  * @param string $type Category name of the extension
  * @param array $extension
  *
  * @return string Raw HTML
  */
 public function getCreditsForExtension($type, array $extension)
 {
     $out = $this->getOutput();
     // We must obtain the information for all the bits and pieces!
     // ... such as extension names and links
     if (isset($extension['namemsg'])) {
         // Localized name of extension
         $extensionName = $this->msg($extension['namemsg'])->text();
     } elseif (isset($extension['name'])) {
         // Non localized version
         $extensionName = $extension['name'];
     } else {
         $extensionName = $this->msg('version-no-ext-name')->text();
     }
     if (isset($extension['url'])) {
         $extensionNameLink = Linker::makeExternalLink($extension['url'], $extensionName, true, '', ['class' => 'mw-version-ext-name']);
     } else {
         $extensionNameLink = $extensionName;
     }
     // ... and the version information
     // If the extension path is set we will check that directory for GIT
     // metadata in an attempt to extract date and vcs commit metadata.
     $canonicalVersion = '&ndash;';
     $extensionPath = null;
     $vcsVersion = null;
     $vcsLink = null;
     $vcsDate = null;
     if (isset($extension['version'])) {
         $canonicalVersion = $out->parseInline($extension['version']);
     }
     if (isset($extension['path'])) {
         global $IP;
         $extensionPath = dirname($extension['path']);
         if ($this->coreId == '') {
             wfDebug('Looking up core head id');
             $coreHeadSHA1 = self::getGitHeadSha1($IP);
             if ($coreHeadSHA1) {
                 $this->coreId = $coreHeadSHA1;
             }
         }
         $cache = wfGetCache(CACHE_ANYTHING);
         $memcKey = wfMemcKey('specialversion-ext-version-text', $extension['path'], $this->coreId);
         list($vcsVersion, $vcsLink, $vcsDate) = $cache->get($memcKey);
         if (!$vcsVersion) {
             wfDebug("Getting VCS info for extension {$extension['name']}");
             $gitInfo = new GitInfo($extensionPath);
             $vcsVersion = $gitInfo->getHeadSHA1();
             if ($vcsVersion !== false) {
                 $vcsVersion = substr($vcsVersion, 0, 7);
                 $vcsLink = $gitInfo->getHeadViewUrl();
                 $vcsDate = $gitInfo->getHeadCommitDate();
             }
             $cache->set($memcKey, [$vcsVersion, $vcsLink, $vcsDate], 60 * 60 * 24);
         } else {
             wfDebug("Pulled VCS info for extension {$extension['name']} from cache");
         }
     }
     $versionString = Html::rawElement('span', ['class' => 'mw-version-ext-version'], $canonicalVersion);
     if ($vcsVersion) {
         if ($vcsLink) {
             $vcsVerString = Linker::makeExternalLink($vcsLink, $this->msg('version-version', $vcsVersion), true, '', ['class' => 'mw-version-ext-vcs-version']);
         } else {
             $vcsVerString = Html::element('span', ['class' => 'mw-version-ext-vcs-version'], "({$vcsVersion})");
         }
         $versionString .= " {$vcsVerString}";
         if ($vcsDate) {
             $vcsTimeString = Html::element('span', ['class' => 'mw-version-ext-vcs-timestamp'], $this->getLanguage()->timeanddate($vcsDate, true));
             $versionString .= " {$vcsTimeString}";
         }
         $versionString = Html::rawElement('span', ['class' => 'mw-version-ext-meta-version'], $versionString);
     }
     // ... and license information; if a license file exists we
     // will link to it
     $licenseLink = '';
     if (isset($extension['name'])) {
         $licenseName = null;
         if (isset($extension['license-name'])) {
             $licenseName = $out->parseInline($extension['license-name']);
         } elseif ($this->getExtLicenseFileName($extensionPath)) {
             $licenseName = $this->msg('version-ext-license')->escaped();
         }
         if ($licenseName !== null) {
             $licenseLink = Linker::link($this->getPageTitle('License/' . $extension['name']), $licenseName, ['class' => 'mw-version-ext-license', 'dir' => 'auto']);
         }
     }
     // ... and generate the description; which can be a parameterized l10n message
     // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
     // up string
     if (isset($extension['descriptionmsg'])) {
         // Localized description of extension
         $descriptionMsg = $extension['descriptionmsg'];
         if (is_array($descriptionMsg)) {
             $descriptionMsgKey = $descriptionMsg[0];
             // Get the message key
             array_shift($descriptionMsg);
             // Shift out the message key to get the parameters only
             array_map("htmlspecialchars", $descriptionMsg);
             // For sanity
             $description = $this->msg($descriptionMsgKey, $descriptionMsg)->text();
         } else {
             $description = $this->msg($descriptionMsg)->text();
         }
     } elseif (isset($extension['description'])) {
         // Non localized version
         $description = $extension['description'];
     } else {
         $description = '';
     }
     $description = $out->parseInline($description);
     // ... now get the authors for this extension
     $authors = isset($extension['author']) ? $extension['author'] : [];
     $authors = $this->listAuthors($authors, $extension['name'], $extensionPath);
     // Finally! Create the table
     $html = Html::openElement('tr', ['class' => 'mw-version-ext', 'id' => Sanitizer::escapeId('mw-version-ext-' . $type . '-' . $extension['name'])]);
     $html .= Html::rawElement('td', [], $extensionNameLink);
     $html .= Html::rawElement('td', [], $versionString);
     $html .= Html::rawElement('td', [], $licenseLink);
     $html .= Html::rawElement('td', ['class' => 'mw-version-ext-description'], $description);
     $html .= Html::rawElement('td', ['class' => 'mw-version-ext-authors'], $authors);
     $html .= Html::closeElement('tr');
     return $html;
 }
 public function formatVersionRow($arr)
 {
     $ts = $arr['timestamp'];
     $wikis = $arr['wikis'];
     $c = $arr['count'];
     $hasSelf = in_array($this->mWiki, $wikis);
     extract($this->formatConf);
     $lang = $this->getLang();
     $datime = $lang->timeanddate($ts);
     $date = $lang->date($ts);
     $time = $lang->time($ts);
     ## Make user link...
     $userLink = '';
     if (!$arr['user_wiki'] && !$arr['user_name']) {
         $userLink = '';
         # Nothing...
         $username = '';
     } elseif ($arr['user_wiki'] == wfWikiId()) {
         $userLink = Linker::link(Title::makeTitle(NS_USER, $arr['user_name']), htmlspecialchars($arr['user_name']));
         $username = $arr['user_name'];
     } elseif ($wiki = WikiMap::getWiki($arr['user_wiki'])) {
         $userLink = Linker::makeExternalLink($wiki->getUrl('User:'******'user_name']), htmlspecialchars($arr['user_name'] . '@' . $arr['user_wiki']));
         $username = '';
     } else {
         ## Last-ditch
         $userLink = htmlspecialchars($arr['user_name'] . '@' . $arr['user_wiki']);
         $username = '';
     }
     $actions = array();
     $view = '';
     if ($hasSelf) {
         $view .= Linker::linkKnown($self, $this->msg('configure-view')->escaped(), array(), array('version' => $ts));
     } elseif ($allowedAll) {
         $view .= $this->msg('configure-view')->escaped();
     }
     if ($allowedAll) {
         $viewWikis = array();
         foreach ($wikis as $wiki) {
             $viewWikis[] = Linker::linkKnown($self, htmlspecialchars($wiki), array(), array('version' => $ts, 'wiki' => $wiki));
         }
         $view .= ' (' . $lang->commaList($viewWikis) . ')';
     }
     if ($view) {
         $actions[] = $view;
     }
     $editDone = false;
     if ($allowedConfig) {
         if ($hasSelf) {
             $editCore = $editMsg . Linker::linkKnown($configTitle, $this->msg('configure-edit-core')->escaped(), array(), array('version' => $ts));
         } elseif ($allowedConfigAll) {
             $editCore = $editMsg . $this->msg('configure-edit-core')->escaped();
         } else {
             $editCore = $editMsg;
         }
         if ($allowedConfigAll) {
             $viewWikis = array();
             foreach ($wikis as $wiki) {
                 $viewWikis[] = Linker::linkKnown($configTitle, htmlspecialchars($wiki), array(), array('version' => $ts, 'wiki' => $wiki));
             }
             $editCore .= ' (' . $lang->commaList($viewWikis) . ')';
         }
         $actions[] = $editCore;
     }
     if ($allowedExtensions) {
         $editExt = '';
         if (!$allowedConfig) {
             $editExt .= $editMsg;
         }
         if ($hasSelf) {
             $editExt .= Linker::linkKnown($extTitle, $this->msg('configure-edit-ext')->escaped(), array(), array('version' => $ts));
         } elseif ($allowedExtensionsAll) {
             $editExt .= $this->msg('configure-edit-ext')->escaped();
         }
         if ($allowedExtensionsAll) {
             $viewWikis = array();
             foreach ($wikis as $wiki) {
                 $viewWikis[] = Linker::linkKnown($extTitle, htmlspecialchars($wiki), array(), array('version' => $ts, 'wiki' => $wiki));
             }
             $editExt .= ' (' . $lang->commaList($viewWikis) . ')';
         }
         $actions[] = $editExt;
     }
     if ($showDiff) {
         $diffCheck = $c == 2 ? array('checked' => 'checked') : array();
         $versionCheck = $c == 1 ? array('checked' => 'checked') : array();
         $buttons = Xml::element('input', array_merge(array('type' => 'radio', 'name' => 'diff', 'value' => $ts), $diffCheck)) . Xml::element('input', array_merge(array('type' => 'radio', 'name' => 'version', 'value' => $ts), $versionCheck));
         $actions[] = Linker::link($this->getTitle(), $this->msg('configure-viewconfig-default-diff')->escaped(), array(), array('version' => $ts, 'diff' => 'default'));
     } else {
         $buttons = '';
     }
     $comment = $arr['reason'] ? Linker::commentBlock($arr['reason']) : '';
     $action = $lang->commaList($actions);
     $msg = $this->msg('configure-viewconfig-line')->rawParams($buttons)->params($datime)->rawParams($userLink, $action, $comment)->params($date, $time, $username)->parse();
     return Xml::tags('li', null, $msg) . "\n";
 }
Example #14
0
 /**
  * If this request is a redirect view, send "redirected from" subtitle to
  * $wgOut. Returns true if the header was needed, false if this is not a
  * redirect view. Handles both local and remote redirects.
  *
  * @return boolean
  */
 public function showRedirectedFromHeader()
 {
     global $wgOut, $wgRequest, $wgRedirectSources;
     $rdfrom = $wgRequest->getVal('rdfrom');
     if (isset($this->mRedirectedFrom)) {
         // This is an internally redirected page view.
         // We'll need a backlink to the source page for navigation.
         if (wfRunHooks('ArticleViewRedirect', array(&$this))) {
             # start wikia change
             global $wgWikiaUseNoFollow;
             $redirAttribs = array();
             if (!empty($wgWikiaUseNoFollow)) {
                 $redirAttribs['rel'] = 'nofollow';
             }
             # end wikia change
             $redir = Linker::linkKnown($this->mRedirectedFrom, null, $redirAttribs, array('redirect' => 'no'));
             $wgOut->addSubtitle(wfMessage('redirectedfrom')->rawParams($redir));
             // Set the fragment if one was specified in the redirect
             if (strval($this->getTitle()->getFragment()) != '') {
                 $fragment = Xml::escapeJsString($this->getTitle()->getFragmentForURL());
                 $wgOut->addInlineScript("redirectToFragment(\"{$fragment}\");");
             }
             /**
             * Commented out by christian@wikia-inc.com
             * /extensions/wikia/CanonicalHref is used by Wikia to handle redirects and all of these cases:
             * http://muppet.wikia.com/wiki/Kermit_the_Frog
             * http://muppet.wikia.com/index.php/Kermit_the_Frog
             * http://muppet.wikia.com/index.php?title=Kermit_the_Frog
             * http://muppet.wikia.com/wiki/Kermit_the_Frog?action=view
             *
             				// Add a <link rel="canonical"> tag
             				$wgOut->addLink( array( 'rel' => 'canonical',
             					'href' => $this->getTitle()->getLocalURL() )
             				);
             */
             // Tell $wgOut the user arrived at this article through a redirect
             $wgOut->setRedirectedFrom($this->mRedirectedFrom);
             return true;
         }
     } elseif ($rdfrom) {
         // This is an externally redirected view, from some other wiki.
         // If it was reported from a trusted site, supply a backlink.
         if ($wgRedirectSources && preg_match($wgRedirectSources, $rdfrom)) {
             $redir = Linker::makeExternalLink($rdfrom, $rdfrom);
             $wgOut->addSubtitle(wfMessage('redirectedfrom')->rawParams($redir));
             return true;
         }
     }
     return false;
 }
Example #15
0
    /**
     * Formats wiki links and media links in text; all other wiki formatting
     * is ignored
     *
     * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
     * @param string $comment Text to format links in
     * @param Title|null $title An optional title object used to links to sections
     * @param bool $local Whether section links should refer to local page
     * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), as used by WikiMap
     *
     * @return string
     */
    public static function formatLinksInComment($comment, $title = null, $local = false, $wikiId = null)
    {
        return preg_replace_callback('/
				\\[\\[
				:? # ignore optional leading colon
				([^\\]|]+) # 1. link target; page names cannot include ] or |
				(?:\\|
					# 2. a pipe-separated substring; only the last is captured
					# Stop matching at | and ]] without relying on backtracking.
					((?:]?[^\\]|])*+)
				)*
				\\]\\]
				([^[]*) # 3. link trail (the text up until the next link)
			/x', function ($match) use($title, $local, $wikiId) {
            global $wgContLang;
            $medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|';
            $medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):';
            $comment = $match[0];
            # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
            if (strpos($match[1], '%') !== false) {
                $match[1] = str_replace(array('<', '>'), array('&lt;', '&gt;'), rawurldecode($match[1]));
            }
            # Handle link renaming [[foo|text]] will show link as "text"
            if ($match[2] != "") {
                $text = $match[2];
            } else {
                $text = $match[1];
            }
            $submatch = array();
            $thelink = null;
            if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) {
                # Media link; trail not supported.
                $linkRegexp = '/\\[\\[(.*?)\\]\\]/';
                $title = Title::makeTitleSafe(NS_FILE, $submatch[1]);
                if ($title) {
                    $thelink = Linker::makeMediaLinkObj($title, $text);
                }
            } else {
                # Other kind of link
                if (preg_match($wgContLang->linkTrail(), $match[3], $submatch)) {
                    $trail = $submatch[1];
                } else {
                    $trail = "";
                }
                $linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/';
                if (isset($match[1][0]) && $match[1][0] == ':') {
                    $match[1] = substr($match[1], 1);
                }
                list($inside, $trail) = Linker::splitTrail($trail);
                $linkText = $text;
                $linkTarget = Linker::normalizeSubpageLink($title, $match[1], $linkText);
                $target = Title::newFromText($linkTarget);
                if ($target) {
                    if ($target->getText() == '' && !$target->isExternal() && !$local && $title) {
                        $newTarget = clone $title;
                        $newTarget->setFragment('#' . $target->getFragment());
                        $target = $newTarget;
                    }
                    if ($wikiId !== null) {
                        $thelink = Linker::makeExternalLink(WikiMap::getForeignURL($wikiId, $target->getFullText()), $linkText . $inside, false) . $trail;
                    } else {
                        $thelink = Linker::link($target, $linkText . $inside) . $trail;
                    }
                }
            }
            if ($thelink) {
                // If the link is still valid, go ahead and replace it in!
                $comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1);
            }
            return $comment;
        }, $comment);
    }
 /**
  * @param $row
  * @param $isListItem bool
  * @return String
  */
 function formatRow($row, $isListItem = true)
 {
     $user = $this->getUser();
     $lang = $this->getLanguage();
     $actionLinks = array();
     $title = Title::makeTitle($row->afl_namespace, $row->afl_title);
     $diffLink = false;
     if (self::isHidden($row) && !$this->canSeeHidden()) {
         return '';
     }
     if (!$row->afl_wiki) {
         $pageLink = Linker::link($title);
         if ($row->afl_rev_id) {
             $diffLink = Linker::link($title, wfMessage('abusefilter-log-diff')->parse(), array(), array('diff' => 'prev', 'oldid' => $row->afl_rev_id));
         }
     } else {
         $pageLink = WikiMap::makeForeignLink($row->afl_wiki, $row->afl_title);
         if ($row->afl_rev_id) {
             $diffUrl = WikiMap::getForeignURL($row->afl_wiki, $row->afl_title);
             $diffUrl = wfAppendQuery($diffUrl, array('diff' => 'prev', 'oldid' => $row->afl_rev_id));
             $diffLink = Linker::makeExternalLink($diffUrl, wfMessage('abusefilter-log-diff')->parse());
         }
     }
     if (!$row->afl_wiki) {
         // Local user
         $userLink = Linker::userLink($row->afl_user, $row->afl_user_text) . Linker::userToolLinks($row->afl_user, $row->afl_user_text, true);
     } else {
         $userLink = WikiMap::foreignUserLink($row->afl_wiki, $row->afl_user_text);
         $userLink .= ' (' . WikiMap::getWikiName($row->afl_wiki) . ')';
     }
     $timestamp = $lang->timeanddate($row->afl_timestamp, true);
     $actions_taken = $row->afl_actions;
     if (!strlen(trim($actions_taken))) {
         $actions_taken = $this->msg('abusefilter-log-noactions')->text();
     } else {
         $actions = explode(',', $actions_taken);
         $displayActions = array();
         foreach ($actions as $action) {
             $displayActions[] = AbuseFilter::getActionDisplay($action);
         }
         $actions_taken = $lang->commaList($displayActions);
     }
     $globalIndex = AbuseFilter::decodeGlobalName($row->afl_filter);
     if ($globalIndex) {
         // Pull global filter description
         $parsed_comments = $this->getOutput()->parseInline(AbuseFilter::getGlobalFilterDescription($globalIndex));
         $filter_hidden = null;
     } else {
         $parsed_comments = $this->getOutput()->parseInline($row->af_public_comments);
         $filter_hidden = $row->af_hidden;
     }
     if (self::canSeeDetails($row->afl_filter, $filter_hidden)) {
         if ($isListItem) {
             $detailsLink = Linker::linkKnown($this->getPageTitle($row->afl_id), $this->msg('abusefilter-log-detailslink')->escaped());
             $actionLinks[] = $detailsLink;
         }
         $examineTitle = SpecialPage::getTitleFor('AbuseFilter', 'examine/log/' . $row->afl_id);
         $examineLink = Linker::link($examineTitle, $this->msg('abusefilter-changeslist-examine')->parse(), array());
         $actionLinks[] = $examineLink;
         if ($diffLink) {
             $actionLinks[] = $diffLink;
         }
         if ($user->isAllowed('abusefilter-hide-log')) {
             $hideLink = Linker::link($this->getPageTitle(), $this->msg('abusefilter-log-hidelink')->text(), array(), array('hide' => $row->afl_id));
             $actionLinks[] = $hideLink;
         }
         if ($globalIndex) {
             global $wgAbuseFilterCentralDB;
             $globalURL = WikiMap::getForeignURL($wgAbuseFilterCentralDB, 'Special:AbuseFilter/' . $globalIndex);
             $linkText = wfMessage('abusefilter-log-detailedentry-global')->numParams($globalIndex)->escaped();
             $filterLink = Linker::makeExternalLink($globalURL, $linkText);
         } else {
             $title = SpecialPage::getTitleFor('AbuseFilter', $row->afl_filter);
             $linkText = wfMessage('abusefilter-log-detailedentry-local')->numParams($row->afl_filter)->escaped();
             $filterLink = Linker::link($title, $linkText);
         }
         $description = $this->msg('abusefilter-log-detailedentry-meta')->rawParams($timestamp, $userLink, $filterLink, $row->afl_action, $pageLink, $actions_taken, $parsed_comments, $lang->pipeList($actionLinks), $row->afl_user_text)->parse();
     } else {
         if ($diffLink) {
             $msg = 'abusefilter-log-entry-withdiff';
         } else {
             $msg = 'abusefilter-log-entry';
         }
         $description = $this->msg($msg)->rawParams($timestamp, $userLink, $row->afl_action, $pageLink, $actions_taken, $parsed_comments, $diffLink)->parse();
     }
     if (self::isHidden($row) === true) {
         $description .= ' ' . $this->msg('abusefilter-log-hidden')->parse();
         $class = 'afl-hidden';
     } elseif (self::isHidden($row) === 'implicit') {
         $description .= ' ' . $this->msg('abusefilter-log-hidden-implicit')->parse();
     }
     if ($isListItem) {
         return Xml::tags('li', isset($class) ? array('class' => $class) : null, $description);
     } else {
         return Xml::tags('span', isset($class) ? array('class' => $class) : null, $description);
     }
 }
Example #17
0
 function formatResult($skin, $result)
 {
     $title = Title::makeTitle($result->namespace, $result->title);
     $url = $result->url;
     $pageLink = Linker::linkKnown($title);
     $urlLink = Linker::makeExternalLink($url, $url);
     return $this->msg('linksearch-line')->rawParams($urlLink, $pageLink)->escaped();
 }
 function formatValue($field, $value)
 {
     switch ($field) {
         case 'am_title':
             $title = Title::makeTitle(NS_MEDIAWIKI, $value . $this->suffix);
             $talk = Title::makeTitle(NS_MEDIAWIKI_TALK, $value . $this->suffix);
             $translation = Linker::makeExternalLink('https://translatewiki.net/w/i.php?' . wfArrayToCgi(array('title' => 'Special:SearchTranslations', 'group' => 'mediawiki', 'grouppath' => 'mediawiki', 'query' => 'language:' . $this->getLanguage()->getCode() . '^25 ' . 'messageid:"MediaWiki:' . $value . '"^10 "' . $this->msg($value)->inLanguage('en')->plain() . '"')), $this->msg('allmessages-filter-translate')->text());
             if ($this->mCurrentRow->am_customised) {
                 $title = Linker::linkKnown($title, $this->getLanguage()->lcfirst($value));
             } else {
                 $title = Linker::link($title, $this->getLanguage()->lcfirst($value), array(), array(), array('broken'));
             }
             if ($this->mCurrentRow->am_talk_exists) {
                 $talk = Linker::linkKnown($talk, $this->talk);
             } else {
                 $talk = Linker::link($talk, $this->talk, array(), array(), array('broken'));
             }
             return $title . ' ' . $this->msg('parentheses')->rawParams($talk)->escaped() . ' ' . $this->msg('parentheses')->rawParams($translation)->escaped();
         case 'am_default':
         case 'am_actual':
             return Sanitizer::escapeHtmlAllowEntities($value, ENT_QUOTES);
     }
     return '';
 }
 function getUploadLink()
 {
     global $wgUploadNavigationUrl;
     if ($wgUploadNavigationUrl) {
         # Using an empty class attribute to avoid automatic setting of "external" class
         return Linker::makeExternalLink($wgUploadNavigationUrl, wfMessage('upload')->escaped(), false, null, array('class' => ''));
     } else {
         return Linker::linkKnown(SpecialPage::getTitleFor('Upload'), wfMessage('upload')->escaped());
     }
 }
Example #20
0
 /**
  * Replace external links (REL)
  *
  * Note: this is all very hackish and the order of execution matters a lot.
  * Make sure to run maintenance/parserTests.php if you change this code.
  *
  * @private
  *
  * @param $text string
  *
  * @return string
  */
 function replaceExternalLinks($text)
 {
     wfProfileIn(__METHOD__);
     $bits = preg_split($this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     $s = array_shift($bits);
     $i = 0;
     while ($i < count($bits)) {
         $url = $bits[$i++];
         $protocol = $bits[$i++];
         $text = $bits[$i++];
         $trail = $bits[$i++];
         # The characters '<' and '>' (which were escaped by
         # removeHTMLtags()) should not be included in
         # URLs, per RFC 2396.
         $m2 = array();
         if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
             $text = substr($url, $m2[0][1]) . ' ' . $text;
             $url = substr($url, 0, $m2[0][1]);
         }
         # If the link text is an image URL, replace it with an <img> tag
         # This happened by accident in the original parser, but some people used it extensively
         $img = $this->maybeMakeExternalImage($text);
         if ($img !== false) {
             $text = $img;
         }
         $dtrail = '';
         # Set linktype for CSS - if URL==text, link is essentially free
         $linktype = $text === $url ? 'free' : 'text';
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         global $wgRTEParserEnabled;
         if (!empty($wgRTEParserEnabled)) {
             $RTE_wikitextIdx = RTEMarker::getDataIdx(RTEMarker::EXTERNAL_WIKITEXT, $trail);
             $wasblank = $text == '';
         }
         # RTE - end
         # No link text, e.g. [http://domain.tld/some.link]
         if ($text == '') {
             # Autonumber
             $langObj = $this->getTargetLanguage();
             $text = '[' . $langObj->formatNum(++$this->mAutonumber) . ']';
             $linktype = 'autonumber';
         } else {
             # Have link text, e.g. [http://domain.tld/some.link text]s
             # Check for trail
             list($dtrail, $trail) = Linker::splitTrail($trail);
         }
         $text = $this->getConverterLanguage()->markNoConversion($text);
         $url = Sanitizer::cleanUrl($url);
         # Use the encoded URL
         # This means that users can paste URLs directly into the text
         # Funny characters like ö aren't valid in URLs anyway
         # This was changed in August 2004
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         if (!empty($wgRTEParserEnabled)) {
             $text = RTEMarker::generate(RTEMarker::EXTERNAL_DATA, RTEData::put('data', array('type' => 'external', 'wikitextIdx' => $RTE_wikitextIdx, 'text' => $text, 'link' => $url, 'linktype' => $linktype, 'wasblank' => $wasblank))) . $text;
         }
         # RTE - end
         $s .= Linker::makeExternalLink($url, $text, false, $linktype, $this->getExternalLinkAttribs($url)) . $dtrail . $trail;
         # Register link in the output object.
         # Replace unnecessary URL escape codes with the referenced character
         # This prevents spammers from hiding links from the filters
         $pasteurized = self::replaceUnusualEscapes($url);
         $this->mOutput->addExternalLink($pasteurized);
     }
     wfProfileOut(__METHOD__);
     return $s;
 }
Example #21
0
 /**
  * If this request is a redirect view, send "redirected from" subtitle to
  * the output. Returns true if the header was needed, false if this is not
  * a redirect view. Handles both local and remote redirects.
  *
  * @return boolean
  */
 public function showRedirectedFromHeader()
 {
     global $wgRedirectSources;
     $outputPage = $this->getContext()->getOutput();
     $rdfrom = $this->getContext()->getRequest()->getVal('rdfrom');
     if (isset($this->mRedirectedFrom)) {
         // This is an internally redirected page view.
         // We'll need a backlink to the source page for navigation.
         if (wfRunHooks('ArticleViewRedirect', array(&$this))) {
             $redir = Linker::linkKnown($this->mRedirectedFrom, null, array(), array('redirect' => 'no'));
             $outputPage->addSubtitle(wfMessage('redirectedfrom')->rawParams($redir));
             // Set the fragment if one was specified in the redirect
             if (strval($this->getTitle()->getFragment()) != '') {
                 $fragment = Xml::escapeJsString($this->getTitle()->getFragmentForURL());
                 $outputPage->addInlineScript("redirectToFragment(\"{$fragment}\");");
             }
             // Add a <link rel="canonical"> tag
             $outputPage->addLink(array('rel' => 'canonical', 'href' => $this->getTitle()->getLocalURL()));
             // Tell the output object that the user arrived at this article through a redirect
             $outputPage->setRedirectedFrom($this->mRedirectedFrom);
             return true;
         }
     } elseif ($rdfrom) {
         // This is an externally redirected view, from some other wiki.
         // If it was reported from a trusted site, supply a backlink.
         if ($wgRedirectSources && preg_match($wgRedirectSources, $rdfrom)) {
             $redir = Linker::makeExternalLink($rdfrom, $rdfrom);
             $outputPage->addSubtitle(wfMessage('redirectedfrom')->rawParams($redir));
             return true;
         }
     }
     return false;
 }
Example #22
0
 /**
  * @param Skin $skin
  * @param object $result Result row
  * @return string
  */
 function formatResult($skin, $result)
 {
     $title = new TitleValue((int) $result->namespace, $result->title);
     $pageLink = $this->linkRenderer->renderHtmlLink($title);
     $url = $result->url;
     $urlLink = Linker::makeExternalLink($url, $url);
     return $this->msg('linksearch-line')->rawParams($urlLink, $pageLink)->escaped();
 }
Example #23
0
 /**
  * @param $type string
  * @return string
  */
 function getCopyright($type = 'detect')
 {
     global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
     if ($type == 'detect') {
         if (!$this->isRevisionCurrent() && !$this->msg('history_copyright')->inContentLanguage()->isDisabled()) {
             $type = 'history';
         } else {
             $type = 'normal';
         }
     }
     if ($type == 'history') {
         $msg = 'history_copyright';
     } else {
         $msg = 'copyright';
     }
     if ($wgRightsPage) {
         $title = Title::newFromText($wgRightsPage);
         $link = Linker::linkKnown($title, $wgRightsText);
     } elseif ($wgRightsUrl) {
         $link = Linker::makeExternalLink($wgRightsUrl, $wgRightsText);
     } elseif ($wgRightsText) {
         $link = $wgRightsText;
     } else {
         # Give up now
         return '';
     }
     // Allow for site and per-namespace customization of copyright notice.
     $forContent = true;
     wfRunHooks('SkinCopyrightFooter', array($this->getTitle(), $type, &$msg, &$link, &$forContent));
     $msgObj = $this->msg($msg)->rawParams($link);
     if ($forContent) {
         $msg = $msgObj->inContentLanguage()->text();
         if ($this->getLanguage()->getCode() !== $wgContLang->getCode()) {
             $msg = Html::rawElement('span', array('lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir()), $msg);
         }
         return $msg;
     } else {
         return $msgObj->text();
     }
 }
Example #24
0
 /**
  * If this request is a redirect view, send "redirected from" subtitle to
  * the output. Returns true if the header was needed, false if this is not
  * a redirect view. Handles both local and remote redirects.
  *
  * @return bool
  */
 public function showRedirectedFromHeader()
 {
     global $wgRedirectSources;
     $context = $this->getContext();
     $outputPage = $context->getOutput();
     $request = $context->getRequest();
     $rdfrom = $request->getVal('rdfrom');
     // Construct a URL for the current page view, but with the target title
     $query = $request->getValues();
     unset($query['rdfrom']);
     unset($query['title']);
     if ($this->getTitle()->isRedirect()) {
         // Prevent double redirects
         $query['redirect'] = 'no';
     }
     $redirectTargetUrl = $this->getTitle()->getLinkURL($query);
     if (isset($this->mRedirectedFrom)) {
         // This is an internally redirected page view.
         // We'll need a backlink to the source page for navigation.
         if (Hooks::run('ArticleViewRedirect', array(&$this))) {
             $redir = Linker::linkKnown($this->mRedirectedFrom, null, array(), array('redirect' => 'no'));
             $outputPage->addSubtitle("<span class=\"mw-redirectedfrom\">" . $context->msg('redirectedfrom')->rawParams($redir)->parse() . "</span>");
             // Add the script to update the displayed URL and
             // set the fragment if one was specified in the redirect
             $outputPage->addJsConfigVars(array('wgInternalRedirectTargetUrl' => $redirectTargetUrl));
             $outputPage->addModules('mediawiki.action.view.redirect');
             // Add a <link rel="canonical"> tag
             $outputPage->setCanonicalUrl($this->getTitle()->getCanonicalURL());
             // Tell the output object that the user arrived at this article through a redirect
             $outputPage->setRedirectedFrom($this->mRedirectedFrom);
             return true;
         }
     } elseif ($rdfrom) {
         // This is an externally redirected view, from some other wiki.
         // If it was reported from a trusted site, supply a backlink.
         if ($wgRedirectSources && preg_match($wgRedirectSources, $rdfrom)) {
             $redir = Linker::makeExternalLink($rdfrom, $rdfrom);
             $outputPage->addSubtitle("<span class=\"mw-redirectedfrom\">" . $context->msg('redirectedfrom')->rawParams($redir)->parse() . "</span>");
             // Add the script to update the displayed URL
             $outputPage->addJsConfigVars(array('wgInternalRedirectTargetUrl' => $redirectTargetUrl));
             $outputPage->addModules('mediawiki.action.view.redirect');
             return true;
         }
     }
     return false;
 }
Example #25
0
 protected function imageDupes()
 {
     $this->loadFile();
     $out = $this->getContext()->getOutput();
     $dupes = $this->mPage->getDuplicates();
     if (count($dupes) == 0) {
         return;
     }
     $out->addHTML("<div id='mw-imagepage-section-duplicates'>\n");
     $out->addWikiMsg('duplicatesoffile', $this->getContext()->getLanguage()->formatNum(count($dupes)), $this->getTitle()->getDBkey());
     $out->addHTML("<ul class='mw-imagepage-duplicates'>\n");
     /**
      * @var $file File
      */
     foreach ($dupes as $file) {
         $fromSrc = '';
         if ($file->isLocal()) {
             $link = Linker::linkKnown($file->getTitle());
         } else {
             $link = Linker::makeExternalLink($file->getDescriptionUrl(), $file->getTitle()->getPrefixedText());
             $fromSrc = wfMessage('shared-repo-from', $file->getRepo()->getDisplayName())->text();
         }
         $out->addHTML("<li>{$link} {$fromSrc}</li>\n");
     }
     $out->addHTML("</ul></div>\n");
 }
 /**
  * The main method handling the Special:SpamWikis behaviour.
  */
 public function index()
 {
     // access control
     if (!$this->wg->User->isAllowed('specialspamwikis')) {
         $this->displayRestrictionError();
         return false;
     }
     // init some basic data
     $this->wg->Out->setPageTitle(wfMsg('specialspamwikis-pagetitle'));
     $this->mTitle = Title::makeTitle(NS_SPECIAL, $this->getName());
     $this->mAction = htmlspecialchars($this->mTitle->getLocalURL());
     // placeholder for the actual data
     $this->mData = new StdClass();
     // required for HTML links
     $link = new Linker();
     // the code below implements the behaviour of the stats subpage
     // TODO: find a better method to check for subpages
     if ("{$this->mTitle->getPrefixedText()}/stats" == $this->wg->request->getVal('title')) {
         // fetch the data
         $data = new SpecialSpamWikisData();
         $this->mData->stats = $data->getStats();
         // render the output
         $this->response->getView()->setTemplate('SpecialSpamWikisSpecialPageController', 'stats');
         return null;
     }
     // the code below implements the behaviour after form submission
     if (F::app()->wg->request->wasPosted()) {
         // which wikis to close?
         $this->mData->close = array();
         $this->mData->summary = array();
         $data = $this->request->getVal('close');
         if (!empty($data)) {
             // DB handle
             $tmpDb = F::app()->wf->getDb(DB_MASTER, array(), 'stats');
             foreach ($data as $k => $v) {
                 // get some info about the wiki
                 $city = WikiFactory::getWikiByID($k);
                 // set the public status to "spam"
                 $status = WikiFactory::setPublicStatus(-2, $k, 'SpecialSpamWikis');
                 // clear the cached settings for the wiki
                 WikiFactory::clearCache($k);
                 // prepare the output data
                 $this->mData->close[] = array('city' => $link->makeExternalLink($city->city_url, $city->city_title), 'status' => -2 == $status);
                 // update the summary
                 if (-2 == $status) {
                     if (!isset($this->mData->summary[$city->city_founding_user])) {
                         $this->mData->summary[$city->city_founding_user] = 1;
                     } else {
                         $this->mData->summary[$city->city_founding_user]++;
                     }
                 }
                 // remove from the noreptemp.spamwikis
                 $tmpDb->delete('noreptemp.spamwikis', array('city_id' => $k), __METHOD__);
             }
             // clear the interwiki links for ALL languages in memcached.
             WikiFactory::clearInterwikiCache();
             unset($tmpDb);
         }
         // calculate and pre-format data for StaffLog entry
         $summary = array('sum' => array_sum($this->mData->summary), 'count' => count($this->mData->summary), 'avg' => 0);
         if (0 != $summary['count']) {
             $summary['avg'] = sprintf('%1.2f', $summary['sum'] / $summary['count']);
         }
         // pass the calculated summary to the output (yes, overwrite the previous value)
         $this->mData->summary = $summary;
         // make a StaffLog entry
         StaffLogger::log('spamwiki', 'mark', $this->wg->User->getID(), $this->wg->User->getName(), 0, '', wfMsgExt('specialspamwikis-stafflog-summary', array('parsemag'), $summary['sum'], $summary['count'], $summary['avg']));
         // render the output
         $this->response->getView()->setTemplate('SpecialSpamWikisSpecialPageController', 'close');
         return null;
     }
     // the code below handles the default behaviour: displays the form
     $this->response->addAsset('resources/wikia/libraries/jquery/datatables/jquery.dataTables.min.js');
     $this->response->addAsset('extensions/wikia/SpecialSpamWikis/css/table.scss');
     $data = new SpecialSpamWikisData();
     $this->mData->criteria = $data->getCriteria();
 }
Example #27
0
 /**
  * Replace external links (REL)
  *
  * Note: this is all very hackish and the order of execution matters a lot.
  * Make sure to run tests/parserTests.php if you change this code.
  *
  * @private
  *
  * @param $text string
  *
  * @throws MWException
  * @return string
  */
 function replaceExternalLinks($text)
 {
     wfProfileIn(__METHOD__);
     $bits = preg_split($this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     if ($bits === false) {
         wfProfileOut(__METHOD__);
         throw new MWException("PCRE needs to be compiled with --enable-unicode-properties in order for MediaWiki to function");
     }
     $s = array_shift($bits);
     $i = 0;
     while ($i < count($bits)) {
         $url = $bits[$i++];
         $i++;
         // protocol
         $text = $bits[$i++];
         $trail = $bits[$i++];
         # The characters '<' and '>' (which were escaped by
         # removeHTMLtags()) should not be included in
         # URLs, per RFC 2396.
         $m2 = array();
         if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
             $text = substr($url, $m2[0][1]) . ' ' . $text;
             $url = substr($url, 0, $m2[0][1]);
         }
         # If the link text is an image URL, replace it with an <img> tag
         # This happened by accident in the original parser, but some people used it extensively
         $img = $this->maybeMakeExternalImage($text);
         if ($img !== false) {
             $text = $img;
         }
         $dtrail = '';
         # Set linktype for CSS - if URL==text, link is essentially free
         $linktype = $text === $url ? 'free' : 'text';
         # No link text, e.g. [http://domain.tld/some.link]
         if ($text == '') {
             # Autonumber
             $langObj = $this->getTargetLanguage();
             $text = '[' . $langObj->formatNum(++$this->mAutonumber) . ']';
             $linktype = 'autonumber';
         } else {
             # Have link text, e.g. [http://domain.tld/some.link text]s
             # Check for trail
             list($dtrail, $trail) = Linker::splitTrail($trail);
         }
         $text = $this->getConverterLanguage()->markNoConversion($text);
         $url = Sanitizer::cleanUrl($url);
         # Use the encoded URL
         # This means that users can paste URLs directly into the text
         # Funny characters like ö aren't valid in URLs anyway
         # This was changed in August 2004
         $s .= Linker::makeExternalLink($url, $text, false, $linktype, $this->getExternalLinkAttribs($url)) . $dtrail . $trail;
         # Register link in the output object.
         # Replace unnecessary URL escape codes with the referenced character
         # This prevents spammers from hiding links from the filters
         $pasteurized = self::replaceUnusualEscapes($url);
         $this->mOutput->addExternalLink($pasteurized);
     }
     wfProfileOut(__METHOD__);
     return $s;
 }
Example #28
0
 function formatResult($skin, $result)
 {
     $title = Title::makeTitle($result->namespace, $result->title);
     $url = $result->url;
     $pageLink = Linker::linkKnown($title);
     $urlLink = Linker::makeExternalLink($url, $url);
     return wfMsgHtml('linksearch-line', $urlLink, $pageLink);
 }
 /**
  * Returns HTML of license link or empty string
  * For example:
  *   "<a title="Wikipedia:Copyright" href="/index.php/Wikipedia:Copyright">CC BY</a>"
  *
  * @param string $context The context in which the license link appears, e.g. footer,
  *   editor, talk, or upload.
  * @param array $attribs An associative array of extra HTML attributes to add to the link
  * @return string
  */
 public static function getLicense($context, $attribs = array())
 {
     $config = MobileContext::singleton()->getConfig();
     $rightsPage = $config->get('RightsPage');
     $rightsUrl = $config->get('RightsUrl');
     $rightsText = $config->get('RightsText');
     // Construct the link to the licensing terms
     if ($rightsText) {
         // Use shorter text for some common licensing strings. See Installer.i18n.php
         // for the currently offered strings. Unfortunately, there is no good way to
         // comprehensively support localized licensing strings since the license (as
         // stored in LocalSetttings.php) is just freeform text, not an i18n key.
         $commonLicenses = array('Creative Commons Attribution-Share Alike 3.0' => 'CC BY-SA 3.0', 'Creative Commons Attribution Share Alike' => 'CC BY-SA', 'Creative Commons Attribution 3.0' => 'CC BY 3.0', 'Creative Commons Attribution 2.5' => 'CC BY 2.5', 'Creative Commons Attribution' => 'CC BY', 'Creative Commons Attribution Non-Commercial Share Alike' => 'CC BY-NC-SA', 'Creative Commons Zero (Public Domain)' => 'CC0 (Public Domain)', 'GNU Free Documentation License 1.3 or later' => 'GFDL 1.3 or later');
         if (isset($commonLicenses[$rightsText])) {
             $rightsText = $commonLicenses[$rightsText];
         }
         if ($rightsPage) {
             $title = Title::newFromText($rightsPage);
             $link = Linker::linkKnown($title, $rightsText, $attribs);
         } elseif ($rightsUrl) {
             $link = Linker::makeExternalLink($rightsUrl, $rightsText, true, '', $attribs);
         } else {
             $link = $rightsText;
         }
     } else {
         $link = '';
     }
     // Allow other extensions (for example, WikimediaMessages) to override
     Hooks::run('MobileLicenseLink', array(&$link, $context, $attribs));
     // for plural support we need the info, if there is one or more licenses used in the license text
     // this check if very simple and works on the base, that more than one license will
     // use "and" as a connective
     // 1 - no plural
     // 2 - plural
     $delimiterMsg = wfMessage('and');
     // check, if "and" isn't disabled and exists in site language
     $isPlural = !$delimiterMsg->isDisabled() && strpos($rightsText, $delimiterMsg->text()) === false ? 1 : 2;
     return array('link' => $link, 'plural' => $isPlural);
 }
 /**
  * Generates a media, external or file link for a given result
  * @param object $oDocument Apache_Solr_Document
  * @param object $oTitle Title of wiki page
  * @return string Anchor media, external or file link
  */
 private function getFileLink($oDocument, $oTitle)
 {
     if ($oDocument->overall_type == 'repo') {
         $sSearchLink = Linker::makeMediaLinkObj($oTitle);
     } elseif ($oDocument->overall_type == 'special-linked') {
         $sTitle = $oDocument->title;
         $sLink = $oDocument->path;
         $sSearchLink = Linker::makeExternalLink($sLink, $sTitle, '');
         $sSearchLink = str_replace('<a', '<a target="_blank"', $sSearchLink);
     } else {
         $sTitle = $oDocument->title;
         $sLink = $oDocument->path;
         $sSearchLink = '<a target="_blank" href="file:///' . $sLink . '">' . $sTitle . '</a>';
     }
     return $sSearchLink;
 }