MediaWiki  1.34.0
SpecialShortPages.php
Go to the documentation of this file.
1 <?php
27 
35 
36  function __construct( $name = 'Shortpages' ) {
37  parent::__construct( $name );
38  }
39 
40  function isSyndicated() {
41  return false;
42  }
43 
44  public function getQueryInfo() {
45  $config = $this->getConfig();
46  $blacklist = $config->get( 'ShortPagesNamespaceBlacklist' );
47  $tables = [ 'page' ];
48  $conds = [
49  'page_namespace' => array_diff(
50  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces(),
51  $blacklist
52  ),
53  'page_is_redirect' => 0
54  ];
55  $joinConds = [];
56  $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
57 
58  // Allow extensions to modify the query
59  Hooks::run( 'ShortPagesQuery', [ &$tables, &$conds, &$joinConds, &$options ] );
60 
61  return [
62  'tables' => $tables,
63  'fields' => [
64  'namespace' => 'page_namespace',
65  'title' => 'page_title',
66  'value' => 'page_len'
67  ],
68  'conds' => $conds,
69  'join_conds' => $joinConds,
70  'options' => $options
71  ];
72  }
73 
74  public function reallyDoQuery( $limit, $offset = false ) {
75  $fname = static::class . '::reallyDoQuery';
76  $dbr = $this->getRecacheDB();
77  $query = $this->getQueryInfo();
78  $order = $this->getOrderFields();
79 
80  if ( $this->sortDescending() ) {
81  foreach ( $order as &$field ) {
82  $field .= ' DESC';
83  }
84  }
85 
86  $tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
87  $fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
88  $conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
89  $options = isset( $query['options'] ) ? (array)$query['options'] : [];
90  $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
91 
92  if ( $limit !== false ) {
93  $options['LIMIT'] = intval( $limit );
94  }
95 
96  if ( $offset !== false ) {
97  $options['OFFSET'] = intval( $offset );
98  }
99 
100  $namespaces = $conds['page_namespace'];
101  if ( count( $namespaces ) === 1 ) {
102  $options['ORDER BY'] = $order;
103  $res = $dbr->select( $tables, $fields, $conds, $fname,
104  $options, $join_conds
105  );
106  } else {
107  unset( $conds['page_namespace'] );
108  $options['INNER ORDER BY'] = $order;
109  $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ? ' DESC' : '' ) ];
110  $sql = $dbr->unionConditionPermutations(
111  $tables,
112  $fields,
113  [ 'page_namespace' => $namespaces ],
114  $conds,
115  $fname,
116  $options,
117  $join_conds
118  );
119  $res = $dbr->query( $sql, $fname );
120  }
121 
122  return $res;
123  }
124 
125  function getOrderFields() {
126  return [ 'page_len' ];
127  }
128 
133  function preprocessResults( $db, $res ) {
135  }
136 
137  function sortDescending() {
138  return false;
139  }
140 
146  function formatResult( $skin, $result ) {
147  $dm = $this->getLanguage()->getDirMark();
148 
149  $title = Title::makeTitleSafe( $result->namespace, $result->title );
150  if ( !$title ) {
151  return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
152  Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
153  }
154 
155  $linkRenderer = $this->getLinkRenderer();
156  $hlink = $linkRenderer->makeKnownLink(
157  $title,
158  $this->msg( 'hist' )->text(),
159  [],
160  [ 'action' => 'history' ]
161  );
162  $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
163 
164  if ( $this->isCached() ) {
165  $plink = $linkRenderer->makeLink( $title );
166  $exists = $title->exists();
167  } else {
168  $plink = $linkRenderer->makeKnownLink( $title );
169  $exists = true;
170  }
171 
172  $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
173 
174  return $exists
175  ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
176  : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
177  }
178 
179  protected function getGroupName() {
180  return 'maintenance';
181  }
182 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:792
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
SpecialShortPages\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialShortPages.php:44
SpecialShortPages\getOrderFields
getOrderFields()
Subclasses return an array of fields to order by here.
Definition: SpecialShortPages.php:125
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:749
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:187
$res
$res
Definition: testCompression.php:52
SpecialShortPages\isSyndicated
isSyndicated()
Sometime we don't want to build rss / atom feeds.
Definition: SpecialShortPages.php:40
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:36
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:800
QueryPage\$offset
int $offset
The offset and limit in use, as passed to the query() function.
Definition: QueryPage.php:41
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
$dbr
$dbr
Definition: testCompression.php:50
QueryPage\$limit
int $limit
Definition: QueryPage.php:44
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:758
SpecialShortPages\preprocessResults
preprocessResults( $db, $res)
Definition: SpecialShortPages.php:133
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:258
SpecialShortPages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialShortPages.php:179
SpecialShortPages\formatResult
formatResult( $skin, $result)
Definition: SpecialShortPages.php:146
$title
$title
Definition: testCompression.php:34
SpecialShortPages
SpecialShortpages extends QueryPage.
Definition: SpecialShortPages.php:34
QueryPage\getRecacheDB
getRecacheDB()
Get a DB connection to be used for slow recache queries.
Definition: QueryPage.php:399
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:692
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:613
SpecialShortPages\__construct
__construct( $name='Shortpages')
Definition: SpecialShortPages.php:36
SpecialShortPages\reallyDoQuery
reallyDoQuery( $limit, $offset=false)
Run the query and return the result.
Definition: SpecialShortPages.php:74
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:904
SpecialShortPages\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: SpecialShortPages.php:137
SpecialPage\$linkRenderer
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200