MediaWiki  master
SpecialUnwatchedPages.php
Go to the documentation of this file.
1 <?php
32 
39 
42 
45 
51  public function __construct(
54  LanguageConverterFactory $languageConverterFactory
55  ) {
56  parent::__construct( 'Unwatchedpages', 'unwatchedpages' );
57  $this->linkBatchFactory = $linkBatchFactory;
58  $this->setDBLoadBalancer( $loadBalancer );
59  $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
60  }
61 
62  public function isExpensive() {
63  return true;
64  }
65 
66  public function isSyndicated() {
67  return false;
68  }
69 
76  public function preprocessResults( $db, $res ) {
77  if ( !$res->numRows() ) {
78  return;
79  }
80 
81  $batch = $this->linkBatchFactory->newLinkBatch();
82  foreach ( $res as $row ) {
83  $batch->add( $row->namespace, $row->title );
84  }
85  $batch->execute();
86 
87  $res->seek( 0 );
88  }
89 
90  public function getQueryInfo() {
91  $dbr = $this->getDBLoadBalancer()->getConnectionRef( ILoadBalancer::DB_REPLICA );
92  return [
93  'tables' => [ 'page', 'watchlist' ],
94  'fields' => [
95  'namespace' => 'page_namespace',
96  'title' => 'page_title',
97  'value' => 'page_namespace'
98  ],
99  'conds' => [
100  'wl_title IS NULL',
101  'page_is_redirect' => 0,
102  'page_namespace != ' . $dbr->addQuotes( NS_MEDIAWIKI ),
103  ],
104  'join_conds' => [ 'watchlist' => [
105  'LEFT JOIN', [ 'wl_title = page_title',
106  'wl_namespace = page_namespace' ] ] ]
107  ];
108  }
109 
110  protected function sortDescending() {
111  return false;
112  }
113 
114  protected function getOrderFields() {
115  return [ 'page_namespace', 'page_title' ];
116  }
117 
122  public function execute( $par ) {
123  parent::execute( $par );
124  $this->getOutput()->addModules( 'mediawiki.special.unwatchedPages' );
125  $this->addHelpLink( 'Help:Watchlist' );
126  }
127 
133  public function formatResult( $skin, $result ) {
134  $nt = Title::makeTitleSafe( $result->namespace, $result->title );
135  if ( !$nt ) {
136  return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
137  Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
138  }
139 
140  $text = $this->languageConverter->convertHtml( $nt->getPrefixedText() );
141 
142  $linkRenderer = $this->getLinkRenderer();
143 
144  $plink = $linkRenderer->makeKnownLink( $nt, new HtmlArmor( $text ) );
145  $wlink = $linkRenderer->makeKnownLink(
146  $nt,
147  $this->msg( 'watch' )->text(),
148  [ 'class' => 'mw-watch-link' ],
149  [ 'action' => 'watch' ]
150  );
151 
152  return $this->getLanguage()->specialList( $plink, $wlink );
153  }
154 
155  protected function getGroupName() {
156  return 'maintenance';
157  }
158 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
SpecialUnwatchedPages
A special page that displays a list of pages that are not on anyones watchlist.
Definition: SpecialUnwatchedPages.php:38
QueryPage\getDBLoadBalancer
getDBLoadBalancer()
Definition: QueryPage.php:900
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
SpecialUnwatchedPages\$languageConverter
ILanguageConverter $languageConverter
Definition: SpecialUnwatchedPages.php:44
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:185
$res
$res
Definition: testCompression.php:57
QueryPage
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition: QueryPage.php:41
MediaWiki\Languages\LanguageConverterFactory
An interface for creating language converters.
Definition: LanguageConverterFactory.php:46
SpecialUnwatchedPages\preprocessResults
preprocessResults( $db, $res)
Pre-cache page existence to speed up link generation.
Definition: SpecialUnwatchedPages.php:76
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
$dbr
$dbr
Definition: testCompression.php:54
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:948
SpecialUnwatchedPages\__construct
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, LanguageConverterFactory $languageConverterFactory)
Definition: SpecialUnwatchedPages.php:51
MediaWiki\Languages\LanguageConverterFactory\getLanguageConverter
getLanguageConverter( $language=null)
Provide a LanguageConverter for given language.
Definition: LanguageConverterFactory.php:125
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialUnwatchedPages\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialUnwatchedPages.php:41
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialUnwatchedPages\execute
execute( $par)
Add the JS.
Definition: SpecialUnwatchedPages.php:122
SpecialUnwatchedPages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialUnwatchedPages.php:155
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:689
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:29
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:892
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
SpecialUnwatchedPages\isSyndicated
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
Definition: SpecialUnwatchedPages.php:66
SpecialUnwatchedPages\isExpensive
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
Definition: SpecialUnwatchedPages.php:62
SpecialUnwatchedPages\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: SpecialUnwatchedPages.php:110
SpecialUnwatchedPages\getOrderFields
getOrderFields()
Subclasses return an array of fields to order by here.
Definition: SpecialUnwatchedPages.php:114
SpecialUnwatchedPages\formatResult
formatResult( $skin, $result)
Definition: SpecialUnwatchedPages.php:133
QueryPage\$loadBalancer
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:71
SpecialPage\getContentLanguage
getContentLanguage()
Shortcut to get content language.
Definition: SpecialPage.php:840
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
SpecialUnwatchedPages\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialUnwatchedPages.php:90
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81