MediaWiki REL1_31
ApiQueryReferences.php
Go to the documentation of this file.
1<?php
25
27
28 public function __construct( $query, $moduleName ) {
29 parent::__construct( $query, $moduleName, 'rf' );
30 }
31
32 public function getAllowedParams() {
33 return [
34 'continue' => [
35 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
36 ],
37 ];
38 }
39
40 public function execute() {
41 $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
42 if ( !$config->get( 'CiteStoreReferencesData' ) ) {
43 $this->dieWithError( 'apierror-citestoragedisabled' );
44 }
46 $titles = $this->getPageSet()->getGoodTitles();
47 ksort( $titles );
48 if ( !is_null( $params['continue'] ) ) {
49 $startId = (int)$params['continue'];
50 // check it is definitely an int
51 $this->dieContinueUsageIf( strval( $startId ) !== $params['continue'] );
52 } else {
53 $startId = false;
54 }
55
56 foreach ( $titles as $pageId => $title ) {
57 // Skip until you have the correct starting point
58 if ( $startId !== false && $startId !== $pageId ) {
59 continue;
60 } else {
61 $startId = false;
62 }
63 $storedRefs = Cite::getStoredReferences( $title );
64 $allReferences = [];
65 // some pages may not have references stored
66 if ( $storedRefs !== false ) {
67 // a page can have multiple <references> tags but they all have unique keys
68 foreach ( $storedRefs['refs'] as $index => $grouping ) {
69 foreach ( $grouping as $group => $members ) {
70 foreach ( $members as $name => $ref ) {
71 $ref['name'] = $name;
72 $key = $ref['key'];
73 if ( is_string( $name ) ) {
74 $id = Cite::getReferencesKey( $name . '-' . $key );
75 } else {
76 $id = Cite::getReferencesKey( $key );
77 }
78 $ref['group'] = $group;
79 $ref['reflist'] = $index;
80 $allReferences[$id] = $ref;
81 }
82 }
83 }
84 }
85 // set some metadata since its an assoc data structure
86 ApiResult::setArrayType( $allReferences, 'kvp', 'id' );
87 // Ship a data representation of the combined references.
88 $fit = $this->addPageSubItems( $pageId, $allReferences );
89 if ( !$fit ) {
90 $this->setContinueEnumParameter( 'continue', $pageId );
91 break;
92 }
93 }
94 }
95
102 public function getCacheMode( $params ) {
103 return 'public';
104 }
105
110 protected function getExamplesMessages() {
111 return [
112 'action=query&prop=references&titles=Albert%20Einstein' =>
113 'apihelp-query+references-example-1',
114 ];
115 }
116
117}
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1895
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:2066
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:749
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addPageSubItems( $pageId, $data)
Add a sub-element under the page element with the given page ID.
getPageSet()
Get the PageSet object to work on.
__construct( $query, $moduleName)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
static getStoredReferences(Title $title)
Fetch references stored for the given title in page_props For performance, results are cached.
Definition Cite.php:1405
static getReferencesKey( $key)
Return an id for use in wikitext output based on a key and optionally the number of it,...
Definition Cite.php:1003
MediaWikiServices is the service locator for the application scope of MediaWiki.
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1620
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition linkcache.txt:17
$params