MediaWiki REL1_30
ApiQueryReferences.php
Go to the documentation of this file.
1<?php
25
26 public function __construct( $query, $moduleName ) {
27 parent::__construct( $query, $moduleName, 'rf' );
28 }
29
30 public function getAllowedParams() {
31 return [
32 'continue' => [
33 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
34 ],
35 ];
36 }
37
38 public function execute() {
39 $config = ConfigFactory::getDefaultInstance()->makeConfig( 'cite' );
40 if ( !$config->get( 'CiteStoreReferencesData' ) ) {
41 if ( is_callable( [ $this, 'dieWithError' ] ) ) {
42 $this->dieWithError( 'apierror-citestoragedisabled' );
43 } else {
44 $this->dieUsage( 'Cite extension reference storage is not enabled', 'citestoragedisabled' );
45 }
46 }
48 $titles = $this->getPageSet()->getGoodTitles();
49 ksort( $titles );
50 if ( !is_null( $params['continue'] ) ) {
51 $startId = (int)$params['continue'];
52 // check it is definitely an int
53 $this->dieContinueUsageIf( strval( $startId ) !== $params['continue'] );
54 } else {
55 $startId = false;
56 }
57
58 foreach ( $titles as $pageId => $title ) {
59 // Skip until you have the correct starting point
60 if ( $startId !== false && $startId !== $pageId ) {
61 continue;
62 } else {
63 $startId = false;
64 }
65 $storedRefs = Cite::getStoredReferences( $title );
66 $allReferences = [];
67 // some pages may not have references stored
68 if ( $storedRefs !== false ) {
69 // a page can have multiple <references> tags but they all have unique keys
70 foreach ( $storedRefs['refs'] as $index => $grouping ) {
71 foreach ( $grouping as $group => $members ) {
72 foreach ( $members as $name => $ref ) {
73 $ref['name'] = $name;
74 $key = $ref['key'];
75 if ( is_string( $name ) ) {
76 $id = Cite::getReferencesKey( $name . '-' . $key );
77 } else {
78 $id = Cite::getReferencesKey( $key );
79 }
80 $ref['group'] = $group;
81 $ref['reflist'] = $index;
82 $allReferences[$id] = $ref;
83 }
84 }
85 }
86 }
87 // set some metadata since its an assoc data structure
88 ApiResult::setArrayType( $allReferences, 'kvp', 'id' );
89 // Ship a data representation of the combined references.
90 $fit = $this->addPageSubItems( $pageId, $allReferences );
91 if ( !$fit ) {
92 $this->setContinueEnumParameter( 'continue', $pageId );
93 break;
94 }
95 }
96 }
97
98 public function getCacheMode( $params ) {
99 return 'public';
100 }
101
105 protected function getExamplesMessages() {
106 return [
107 'action=query&prop=references&titles=Albert%20Einstein' =>
108 'apihelp-query+references-example-1',
109 ];
110 }
111
112}
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1855
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:2026
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:740
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:128
dieUsage( $description, $errorCode, $httpRespCode=0, $extradata=null)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
Definition ApiBase.php:2660
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:1375
static getReferencesKey( $key)
Return an id for use in wikitext output based on a key and optionally the number of it,...
Definition Cite.php:994
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:1610
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