MediaWiki  master
SpecialShortPages.php
Go to the documentation of this file.
1 <?php
28 
36 
38  private $namespaceInfo;
39 
45  public function __construct(
49  ) {
50  parent::__construct( 'Shortpages' );
51  $this->namespaceInfo = $namespaceInfo;
52  $this->setDBLoadBalancer( $loadBalancer );
53  $this->setLinkBatchFactory( $linkBatchFactory );
54  }
55 
56  public function isSyndicated() {
57  return false;
58  }
59 
60  public function getQueryInfo() {
61  $config = $this->getConfig();
62  $tables = [ 'page' ];
63  $conds = [
64  'page_namespace' => array_diff(
65  $this->namespaceInfo->getContentNamespaces(),
66  $config->get( 'ShortPagesNamespaceExclusions' )
67  ),
68  'page_is_redirect' => 0
69  ];
70  $joinConds = [];
71  $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
72 
73  // Allow extensions to modify the query
74  $this->getHookRunner()->onShortPagesQuery( $tables, $conds, $joinConds, $options );
75 
76  return [
77  'tables' => $tables,
78  'fields' => [
79  'namespace' => 'page_namespace',
80  'title' => 'page_title',
81  'value' => 'page_len'
82  ],
83  'conds' => $conds,
84  'join_conds' => $joinConds,
85  'options' => $options
86  ];
87  }
88 
89  public function reallyDoQuery( $limit, $offset = false ) {
90  $fname = static::class . '::reallyDoQuery';
91  $dbr = $this->getRecacheDB();
92  $query = $this->getQueryInfo();
93  $order = $this->getOrderFields();
94 
95  if ( $this->sortDescending() ) {
96  foreach ( $order as &$field ) {
97  $field .= ' DESC';
98  }
99  }
100 
101  $tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
102  $fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
103  $conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
104  $options = isset( $query['options'] ) ? (array)$query['options'] : [];
105  $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
106 
107  if ( $limit !== false ) {
108  $options['LIMIT'] = intval( $limit );
109  }
110 
111  if ( $offset !== false ) {
112  $options['OFFSET'] = intval( $offset );
113  }
114 
115  $namespaces = $conds['page_namespace'];
116  if ( count( $namespaces ) === 1 ) {
117  $options['ORDER BY'] = $order;
118  $res = $dbr->select( $tables, $fields, $conds, $fname,
119  $options, $join_conds
120  );
121  } else {
122  unset( $conds['page_namespace'] );
123  $options['INNER ORDER BY'] = $order;
124  $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ? ' DESC' : '' ) ];
125  $sql = $dbr->unionConditionPermutations(
126  $tables,
127  $fields,
128  [ 'page_namespace' => $namespaces ],
129  $conds,
130  $fname,
131  $options,
132  $join_conds
133  );
134  $res = $dbr->query( $sql, $fname );
135  }
136 
137  return $res;
138  }
139 
140  protected function getOrderFields() {
141  return [ 'page_len' ];
142  }
143 
148  public function preprocessResults( $db, $res ) {
150  }
151 
152  protected function sortDescending() {
153  return false;
154  }
155 
161  public function formatResult( $skin, $result ) {
162  $dm = $this->getLanguage()->getDirMark();
163 
164  $title = Title::makeTitleSafe( $result->namespace, $result->title );
165  if ( !$title ) {
166  return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
167  Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
168  }
169 
170  $linkRenderer = $this->getLinkRenderer();
171  $hlink = $linkRenderer->makeKnownLink(
172  $title,
173  $this->msg( 'hist' )->text(),
174  [],
175  [ 'action' => 'history' ]
176  );
177  $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
178 
179  if ( $this->isCached() ) {
180  $plink = $linkRenderer->makeLink( $title );
181  $exists = $title->exists();
182  } else {
183  $plink = $linkRenderer->makeKnownLink( $title );
184  $exists = true;
185  }
186 
187  $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
188 
189  return $exists
190  ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
191  : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
192  }
193 
194  protected function getGroupName() {
195  return 'maintenance';
196  }
197 }
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
SpecialShortPages\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialShortPages.php:60
SpecialShortPages\__construct
__construct(NamespaceInfo $namespaceInfo, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
Definition: SpecialShortPages.php:45
SpecialShortPages\getOrderFields
getOrderFields()
Subclasses return an array of fields to order by here.
Definition: SpecialShortPages.php:140
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
SpecialShortPages\isSyndicated
isSyndicated()
Sometime we don't want to build rss / atom feeds.
Definition: SpecialShortPages.php:56
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
QueryPage\executeLBFromResultWrapper
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Definition: QueryPage.php:874
QueryPage\$offset
int $offset
The offset and limit in use, as passed to the query() function.
Definition: QueryPage.php:46
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
$dbr
$dbr
Definition: testCompression.php:54
QueryPage\$limit
int $limit
Definition: QueryPage.php:49
QueryPage\setLinkBatchFactory
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:135
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1095
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:878
SpecialShortPages\preprocessResults
preprocessResults( $db, $res)
Definition: SpecialShortPages.php:148
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
QueryPage\isCached
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
Definition: QueryPage.php:297
SpecialShortPages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialShortPages.php:194
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialShortPages\formatResult
formatResult( $skin, $result)
Definition: SpecialShortPages.php:161
$title
$title
Definition: testCompression.php:38
SpecialShortPages
SpecialShortpages extends QueryPage.
Definition: SpecialShortPages.php:35
QueryPage\getRecacheDB
getRecacheDB()
Get a DB connection to be used for slow recache queries.
Definition: QueryPage.php:441
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:677
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:892
SpecialShortPages\reallyDoQuery
reallyDoQuery( $limit, $offset=false)
Run the query and return the result.
Definition: SpecialShortPages.php:89
QueryPage\$linkBatchFactory
LinkBatchFactory null $linkBatchFactory
Definition: QueryPage.php:74
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
QueryPage\$loadBalancer
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:71
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
SpecialShortPages\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: SpecialShortPages.php:152
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
SpecialShortPages\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: SpecialShortPages.php:38
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81