*
* @param array $query
* @param bool $query2
- * @param string $proto Protocol to use; setting this will cause a full URL to be used
+ * @param string|int|bool $proto A PROTO_* constant on how the URL should be expanded,
+ * or false (default) for no expansion
* @see self::getLocalURL for the arguments.
* @return string The URL
*/
- public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
- if ( $this->isExternal() || $proto !== PROTO_RELATIVE ) {
+ public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
+ if ( $this->isExternal() || $proto !== false ) {
$ret = $this->getFullURL( $query, $query2, $proto );
} elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
$ret = $this->getFragmentForURL();
$conds = $this->pageCond();
$dbw->onTransactionIdle( function () use ( $dbw, $conds, $method, $purgeTime ) {
$dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
-
$dbw->update(
'page',
[ 'page_touched' => $dbTimestamp ],
* @return bool
*/
public function canUseNoindex() {
- global $wgContentNamespaces, $wgExemptFromUserRobotsControl;
+ global $wgExemptFromUserRobotsControl;
$bannedNamespaces = is_null( $wgExemptFromUserRobotsControl )
- ? $wgContentNamespaces
+ ? MWNamespace::getContentNamespaces()
: $wgExemptFromUserRobotsControl;
return !in_array( $this->mNamespace, $bannedNamespaces );
use Hooks;
use Html;
use HtmlArmor;
+use LinkCache;
use Linker;
use MediaWiki\MediaWikiServices;
+use MWNamespace;
use Sanitizer;
use Title;
use TitleFormatter;
*/
private $titleFormatter;
+ /**
+ * @var LinkCache
+ */
+ private $linkCache;
+
/**
* Whether to run the legacy Linker hooks
*
/**
* @param TitleFormatter $titleFormatter
+ * @param LinkCache $linkCache
*/
- public function __construct( TitleFormatter $titleFormatter ) {
+ public function __construct( TitleFormatter $titleFormatter, LinkCache $linkCache ) {
$this->titleFormatter = $titleFormatter;
+ $this->linkCache = $linkCache;
}
/**
}
/**
- * If you have already looked up the proper CSS classes using Linker::getLinkColour()
+ * If you have already looked up the proper CSS classes using LinkRenderer::getLinkClasses()
* or some other method, use this to avoid looking it up again.
*
* @param LinkTarget $target
if ( $target->isExternal() ) {
$classes[] = 'extiw';
}
- $colour = Linker::getLinkColour( $target, $this->stubThreshold );
+ $colour = $this->getLinkClasses( $target );
if ( $colour !== '' ) {
$classes[] = $colour;
}
private function getLinkURL( LinkTarget $target, array $query = [] ) {
// TODO: Use a LinkTargetResolver service instead of Title
$title = Title::newFromLinkTarget( $target );
- $proto = $this->expandUrls !== false
- ? $this->expandUrls
- : PROTO_RELATIVE;
if ( $this->forceArticlePath ) {
$realQuery = $query;
$query = [];
} else {
$realQuery = [];
}
- $url = $title->getLinkURL( $query, false, $proto );
+ $url = $title->getLinkURL( $query, false, $this->expandUrls );
if ( $this->forceArticlePath && $realQuery ) {
$url = wfAppendQuery( $url, $realQuery );
return $ret;
}
+ /**
+ * Return the CSS classes of a known link
+ *
+ * @param LinkTarget $target
+ * @return string CSS class
+ */
+ public function getLinkClasses( LinkTarget $target ) {
+ // Make sure the target is in the cache
+ $id = $this->linkCache->addLinkObj( $target );
+ if ( $id == 0 ) {
+ // Doesn't exist
+ return '';
+ }
+
+ if ( $this->linkCache->getGoodLinkFieldObj( $target, 'redirect' ) ) {
+ # Page is a redirect
+ return 'mw-redirect';
+ } elseif ( $this->stubThreshold > 0 && MWNamespace::isContent( $target->getNamespace() )
+ && $this->linkCache->getGoodLinkFieldObj( $target, 'length' ) < $this->stubThreshold
+ ) {
+ # Page is a stub
+ return 'stub';
+ }
+
+ return '';
+ }
}