Skip to content

Commit

Permalink
Update copied code to REL1_36
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed May 28, 2021
1 parent 2d1d100 commit 3a99c7a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@

```php
wfLoadExtension( 'UnifiedExtensionForFemiwiki' );
$wgSpecialPages['Whatlinkshere'] = 'SpecialOrderedWhatlinkshere';
$wgSpecialPages['Whatlinkshere'] = [
'class' => 'SpecialOrderedWhatLinksHere',
'services' => [
'DBLoadBalancer',
'LinkBatchFactory',
'ContentHandlerFactory',
'SearchEngineFactory',
'NamespaceInfo',
]
];
$wgGoogleAnalyticsTrackingID = 'AA-00000000-0';
```

Expand Down
14 changes: 13 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"AutoloadClasses": {
"SpecialOrderedWhatlinkshere": "specials/SpecialOrderedWhatlinkshere.php",
"SpecialOrderedWhatLinksHere": "specials/SpecialOrderedWhatLinksHere.php",
"FemiwikiHooks": "includes/FemiwikiHooks.php",
"FemiwikiAuthenticationRequest": "includes/FemiwikiAuthenticationRequest.php",
"FemiwikiPreAuthenticationProvider": "includes/FemiwikiPreAuthenticationProvider.php"
Expand All @@ -32,6 +32,18 @@
"SidebarBeforeOutput": "FemiwikiHooks::onSidebarBeforeOutput",
"SkinAddFooterLinks": "FemiwikiHooks::onSkinAddFooterLinks"
},
"SpecialPages": {
"OrderedWhatlinkshere": {
"class": "SpecialOrderedWhatLinksHere",
"services": [
"DBLoadBalancer",
"LinkBatchFactory",
"ContentHandlerFactory",
"SearchEngineFactory",
"NamespaceInfo"
]
}
},
"MessagesDirs": {
"UnifiedExtensionForFemiwiki": ["i18n"]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

use Wikimedia\Rdbms\ILoadBalancer;

/**
* Implement for https://phabricator.wikimedia.org/T4306
*/
class SpecialOrderedWhatlinkshere extends SpecialWhatLinksHere {
class SpecialOrderedWhatLinksHere extends SpecialWhatLinksHere {

/**
* Copied from REL1_35 without modification to replace private function showIndirectLinks.
* Copied from REL1_36 without modification to replace private function showIndirectLinks.
*
* @param string $par
*/
Expand Down Expand Up @@ -65,7 +68,7 @@ public function execute( $par ) {
}

/**
* Copied from REL1_35 with modification (marked as ***Message*** below)
* Copied from REL1_36 with modification (marked as ***Message*** below)
* @param int $level Recursion level
* @param Title $target Target title
* @param int $limit Number of entries to display
Expand All @@ -74,12 +77,12 @@ public function execute( $par ) {
*/
private function showIndirectLinks( $level, $target, $limit, $from = 0, $back = 0 ) {
$out = $this->getOutput();
$dbr = wfGetDB( DB_REPLICA );
$dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );

$hidelinks = $this->opts->getValue( 'hidelinks' );
$hideredirs = $this->opts->getValue( 'hideredirs' );
$hidetrans = $this->opts->getValue( 'hidetrans' );
$hideimages = $target->getNamespace() != NS_FILE || $this->opts->getValue( 'hideimages' );
$hideimages = $target->getNamespace() !== NS_FILE || $this->opts->getValue( 'hideimages' );

// For historical reasons `pagelinks` always contains an entry for the redirect target.
// So we only need to query `redirect` if `pagelinks` isn't being queried.
Expand All @@ -104,13 +107,20 @@ private function showIndirectLinks( $level, $target, $limit, $from = 0, $back =
];

$namespace = $this->opts->getValue( 'namespace' );
$invert = $this->opts->getValue( 'invert' );
$nsComparison = ( $invert ? '!= ' : '= ' ) . $dbr->addQuotes( $namespace );
if ( is_int( $namespace ) ) {
$conds['redirect'][] = "page_namespace $nsComparison";
$conds['pagelinks'][] = "pl_from_namespace $nsComparison";
$conds['templatelinks'][] = "tl_from_namespace $nsComparison";
$conds['imagelinks'][] = "il_from_namespace $nsComparison";
$invert = $this->opts->getValue( 'invert' );
if ( $invert ) {
// Select all namespaces except for the specified one.
// This allows the database to use the *_from_namespace index. (T241837)
$namespaces = array_diff(
$this->namespaceInfo->getValidNamespaces(), [ $namespace ] );
} else {
$namespaces = $namespace;
}
$conds['redirect']['page_namespace'] = $namespaces;
$conds['pagelinks']['pl_from_namespace'] = $namespaces;
$conds['templatelinks']['tl_from_namespace'] = $namespaces;
$conds['imagelinks']['il_from_namespace'] = $namespaces;
}

/* ***Removed***
Expand Down Expand Up @@ -304,7 +314,7 @@ private function showIndirectLinks( $level, $target, $limit, $from = 0, $back =

// use LinkBatch to make sure, that all required data (associated with Titles)
// is loaded in one query
$lb = new LinkBatch();
$lb = $this->linkBatchFactory->newLinkBatch();
foreach ( $rows as $row ) {
$lb->add( $row->page_namespace, $row->page_title );
}
Expand Down Expand Up @@ -368,8 +378,8 @@ private function showIndirectLinks( $level, $target, $limit, $from = 0, $back =
*/
private function getPrevNext( $prevNumber, $nextNumber ) {
$currentLimit = $this->opts->getValue( 'limit' );
$prev = $this->msg( 'whatlinkshere-prev' )->numParams( $currentLimit )->escaped();
$next = $this->msg( 'whatlinkshere-next' )->numParams( $currentLimit )->escaped();
$prev = $this->msg( 'whatlinkshere-prev' )->numParams( $currentLimit )->text();
$next = $this->msg( 'whatlinkshere-next' )->numParams( $currentLimit )->text();

$changed = $this->opts->getChangedValues();
unset( $changed['target'] );
Expand All @@ -381,7 +391,7 @@ private function getPrevNext( $prevNumber, $nextNumber ) {
if ( $prevNumber !== null ) {
$overrides = [ 'from' => $prevNumber ];
// ***Replacement ends***
$prev = $this->makeSelfLink( $prev, array_merge( $changed, $overrides ) );
$prev = Message::rawParam( $this->makeSelfLink( $prev, array_merge( $changed, $overrides ) ) );
}
/* ***Replaced***
if ( $nextId != 0 ) {
Expand All @@ -390,20 +400,20 @@ private function getPrevNext( $prevNumber, $nextNumber ) {
if ( $nextNumber != 0 ) {
$overrides = [ 'from' => $nextNumber ];
// ***Replacement ends***
$next = $this->makeSelfLink( $next, array_merge( $changed, $overrides ) );
$next = Message::rawParam( $this->makeSelfLink( $next, array_merge( $changed, $overrides ) ) );
}

$limitLinks = [];
$lang = $this->getLanguage();
foreach ( $this->limits as $limit ) {
$prettyLimit = htmlspecialchars( $lang->formatNum( $limit ) );
$prettyLimit = $lang->formatNum( $limit );
$overrides = [ 'limit' => $limit ];
$limitLinks[] = $this->makeSelfLink( $prettyLimit, array_merge( $changed, $overrides ) );
}

$nums = $lang->pipeList( $limitLinks );

return $this->msg( 'viewprevnext' )->rawParams( $prev, $next, $nums )->escaped();
return $this->msg( 'viewprevnext' )->params( $prev, $next )->rawParams( $nums )->escaped();
}

/**
Expand Down

0 comments on commit 3a99c7a

Please sign in to comment.