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  $blacklist = $config->get( 'ShortPagesNamespaceBlacklist' );
63  $tables = [ 'page' ];
64  $conds = [
65  'page_namespace' => array_diff(
66  $this->namespaceInfo->getContentNamespaces(),
67  $blacklist
68  ),
69  'page_is_redirect' => 0
70  ];
71  $joinConds = [];
72  $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
73 
74  // Allow extensions to modify the query
75  $this->getHookRunner()->onShortPagesQuery( $tables, $conds, $joinConds, $options );
76 
77  return [
78  'tables' => $tables,
79  'fields' => [
80  'namespace' => 'page_namespace',
81  'title' => 'page_title',
82  'value' => 'page_len'
83  ],
84  'conds' => $conds,
85  'join_conds' => $joinConds,
86  'options' => $options
87  ];
88  }
89 
90  public function reallyDoQuery( $limit, $offset = false ) {
91  $fname = static::class . '::reallyDoQuery';
92  $dbr = $this->getRecacheDB();
93  $query = $this->getQueryInfo();
94  $order = $this->getOrderFields();
95 
96  if ( $this->sortDescending() ) {
97  foreach ( $order as &$field ) {
98  $field .= ' DESC';
99  }
100  }
101 
102  $tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
103  $fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
104  $conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
105  $options = isset( $query['options'] ) ? (array)$query['options'] : [];
106  $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
107 
108  if ( $limit !== false ) {
109  $options['LIMIT'] = intval( $limit );
110  }
111 
112  if ( $offset !== false ) {
113  $options['OFFSET'] = intval( $offset );
114  }
115 
116  $namespaces = $conds['page_namespace'];
117  if ( count( $namespaces ) === 1 ) {
118  $options['ORDER BY'] = $order;
119  $res = $dbr->select( $tables, $fields, $conds, $fname,
120  $options, $join_conds
121  );
122  } else {
123  unset( $conds['page_namespace'] );
124  $options['INNER ORDER BY'] = $order;
125  $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ? ' DESC' : '' ) ];
126  $sql = $dbr->unionConditionPermutations(
127  $tables,
128  $fields,
129  [ 'page_namespace' => $namespaces ],
130  $conds,
131  $fname,
132  $options,
133  $join_conds
134  );
135  $res = $dbr->query( $sql, $fname );
136  }
137 
138  return $res;
139  }
140 
141  protected function getOrderFields() {
142  return [ 'page_len' ];
143  }
144 
149  public function preprocessResults( $db, $res ) {
151  }
152 
153  protected function sortDescending() {
154  return false;
155  }
156 
162  public function formatResult( $skin, $result ) {
163  $dm = $this->getLanguage()->getDirMark();
164 
165  $title = Title::makeTitleSafe( $result->namespace, $result->title );
166  if ( !$title ) {
167  return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
168  Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
169  }
170 
171  $linkRenderer = $this->getLinkRenderer();
172  $hlink = $linkRenderer->makeKnownLink(
173  $title,
174  $this->msg( 'hist' )->text(),
175  [],
176  [ 'action' => 'history' ]
177  );
178  $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
179 
180  if ( $this->isCached() ) {
181  $plink = $linkRenderer->makeLink( $title );
182  $exists = $title->exists();
183  } else {
184  $plink = $linkRenderer->makeKnownLink( $title );
185  $exists = true;
186  }
187 
188  $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
189 
190  return $exists
191  ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
192  : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
193  }
194 
195  protected function getGroupName() {
196  return 'maintenance';
197  }
198 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:79
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:900
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:141
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:818
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:188
$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:855
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:136
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1083
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:866
SpecialShortPages\preprocessResults
preprocessResults( $db, $res)
Definition: SpecialShortPages.php:149
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
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:195
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:38
SpecialShortPages\formatResult
formatResult( $skin, $result)
Definition: SpecialShortPages.php:162
$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 Stable to override.
Definition: QueryPage.php:444
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:762
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:873
SpecialShortPages\reallyDoQuery
reallyDoQuery( $limit, $offset=false)
Run the query and return the result Stable to override.
Definition: SpecialShortPages.php:90
QueryPage\$linkBatchFactory
LinkBatchFactory null $linkBatchFactory
Definition: QueryPage.php:74
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1016
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:153
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:234
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