r14312 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14311‎ | r14312 | r14313 >
Date:20:51, 20 May 2006
Author:yurik
Status:old
Tags:
Comment:
* new module content - shows raw page content
* nolanglinks is now filtered by namespace and sorted by title
* new parameter uiextended for userinfo
* Bugfix: all pages with ns=0 returned erroneous raw titles
* Bugfix: rawTitles were not matching up to the proper pages.
* Method descriptions and help clean-up
Modified paths:
  • /trunk/extensions/BotQuery/query.php (modified) (history)

Diff [purge]

Index: trunk/extensions/BotQuery/query.php
@@ -85,19 +85,23 @@
8686 "Example: query.php?what=info&format=html",
8787 )),
8888 'txt' => array( 'printHumanReadable', 'application/x-wiki-botquery-print_r', null, null, array(
89 - "Human-readable format using print_r() (http://www.php.net/print_r)",
 89+ "Human-readable format using print_r()",
 90+ "Details: http://www.php.net/print_r",
9091 "Example: query.php?what=info&format=txt",
9192 )),
9293 'json'=> array( 'printJSON', 'application/json', null, null, array(
93 - "JSON format (http://en.wikipedia.org/wiki/JSON)",
 94+ "JSON format",
 95+ "Details: http://en.wikipedia.org/wiki/JSON",
9496 "Example: query.php?what=info&format=json",
9597 )),
9698 'php' => array( 'printPHP', 'application/vnd.php.serialized', null, null, array(
97 - "PHP serialized format using serialize() (http://www.php.net/serialize)",
 99+ "PHP serialized format using serialize()",
 100+ "Details: http://www.php.net/serialize",
98101 "Example: query.php?what=info&format=php",
99102 )),
100 - 'dbg' => array( 'printParsableCode', 'application/x-wiki-botquery-var_export', null, null, array(
101 - "PHP source code format using var_export() (http://www.php.net/var_export)",
 103+ 'dbg' => array( 'printDebugCode', 'application/x-wiki-botquery-var_export', null, null, array(
 104+ "PHP source code format using var_export()",
 105+ "Details: http://www.php.net/var_export",
102106 "Example: query.php?what=info&format=dbg",
103107 )),
104108 );
@@ -113,19 +117,24 @@
114118 var $propGenerators = array(
115119
116120 // Site-wide Generators
117 - 'info' => array( "genMetaSiteInfo", true, null, null, array(
 121+ 'info' => array( 'genMetaSiteInfo', true, null, null, array(
118122 "General site information",
119123 "Example: query.php?what=info",
120124 )),
121 - 'namespaces' => array( "genMetaNamespaceInfo", true, null, null, array(
 125+ 'namespaces' => array( 'genMetaNamespaceInfo', true, null, null, array(
122126 "List of localized namespace names",
123127 "Example: query.php?what=namespaces",
124128 )),
125 - 'userinfo' => array( "genMetaUserInfo", true, null, null, array(
 129+ 'userinfo' => array( 'genMetaUserInfo', true,
 130+ array( 'uiextended' ),
 131+ array( false ),
 132+ array(
126133 "Information about current user",
127 - "Example: query.php?what=userinfo",
 134+ "Parameters supported:",
 135+ "uiextended - If present, includes additional information such as rights and groups.",
 136+ "Example: query.php?what=userinfo&uiextended",
128137 )),
129 - 'recentchanges' => array( "genMetaRecentChanges", true,
 138+ 'recentchanges' => array( 'genMetaRecentChanges', true,
130139 array( 'rcfrom', 'rclimit', 'rchide' ),
131140 array( null, 50, array(null, 'minor', 'bots', 'anons', 'liu') ),
132141 array(
@@ -138,7 +147,7 @@
139148 " Cannot specify both anons and liu.",
140149 "Example: query.php?what=recentchanges&rchide=liu|bots",
141150 )),
142 - 'allpages' => array( "genMetaAllPages", true,
 151+ 'allpages' => array( 'genMetaAllPages', true,
143152 array( 'aplimit', 'apfrom', 'apnamespace' ),
144153 array( 50, '!', 0 ),
145154 array(
@@ -149,17 +158,18 @@
150159 "apnamespaces - limits which namespace to enumerate. Default 0 (Main)",
151160 "Example: query.php?what=allpages&aplimit=50",
152161 )),
153 - 'nolanglinks' => array( "genMetaNoLangLinksPages", true,
154 - array( 'nllimit', 'nlfromid' ),
155 - array( 50, 0 ),
 162+ 'nolanglinks' => array( 'genMetaNoLangLinksPages', true,
 163+ array( 'nllimit', 'nlfrom', 'nlnamespace' ),
 164+ array( 50, '!', 0 ),
156165 array(
157166 "Enumerates pages without language links to the output list.",
158167 "Parameters supported:",
159168 "nllimit - how many total pages to return",
160 - "nlfromid - the page id to start enumerating from. Default is 0",
 169+ "nlfrom - the page title to start enumerating from. Default is '!'",
 170+ "nlnamespaces - limits which namespace to enumerate. Default 0 (Main)",
161171 "Example: query.php?what=nolanglinks&nllimit=50",
162172 )),
163 - 'users' => array( "genUserPages", true,
 173+ 'users' => array( 'genUserPages', true,
164174 array( 'usfrom', 'uslimit' ),
165175 array( null, 50 ),
166176 array(
@@ -173,24 +183,24 @@
174184 //
175185 // Page-specific Generators
176186 //
177 - 'redirects' => array( "genRedirectInfo", false, null, null, array(
 187+ 'redirects' => array( 'genRedirectInfo', false, null, null, array(
178188 "For all given redirects, provides additional information such as pageIds and double-redirection",
179189 "Example: query.php?what=redirects&titles=Main_page",
180190 " query.php?what=recentchanges|redirects (Which of the recent changes are redirects?)",
181191 )),
182 - 'links' => array( "genPageLinksHelper", false, null, null, array(
 192+ 'links' => array( 'genPageLinksHelper', false, null, null, array(
183193 "List of regular page links",
184194 "Example: query.php?what=links&titles=MediaWiki|Wikipedia",
185195 )),
186 - 'langlinks' => array( "genPageLinksHelper", false, null, null, array(
 196+ 'langlinks' => array( 'genPageLinksHelper', false, null, null, array(
187197 "Inter-language links",
188198 "Example: query.php?what=langlinks&titles=MediaWiki|Wikipedia",
189199 )),
190 - 'templates' => array( "genPageLinksHelper", false, null, null, array(
 200+ 'templates' => array( 'genPageLinksHelper', false, null, null, array(
191201 "List of used templates",
192202 "Example: query.php?what=templates&titles=Main_Page",
193203 )),
194 - 'backlinks' => array( "genPageBackLinksHelper", false,
 204+ 'backlinks' => array( 'genPageBackLinksHelper', false,
195205 array( 'blfilter', 'bllimit', 'blcontfrom' ),
196206 array( array('existing', 'nonredirects', 'all'), 50, null ),
197207 array(
@@ -202,7 +212,7 @@
203213 "blcontfrom - from which point to continue. Use the 'next' value from previous queries.",
204214 "Example: query.php?what=backlinks&titles=Main%20Page&bllimit=10",
205215 )),
206 - 'embeddedin' => array( "genPageBackLinksHelper", false,
 216+ 'embeddedin' => array( 'genPageBackLinksHelper', false,
207217 array( 'eifilter', 'eilimit', 'eicontfrom' ),
208218 array( array('existing', 'nonredirects', 'all'), 50, null ),
209219 array(
@@ -214,7 +224,7 @@
215225 "eicontfrom - from which point to continue. Use the 'next' value from previous queries.",
216226 "Example: query.php?what=embeddedin&titles=Template:Stub&eilimit=10",
217227 )),
218 - 'imagelinks' => array( "genPageBackLinksHelper", false,
 228+ 'imagelinks' => array( 'genPageBackLinksHelper', false,
219229 array( 'ilfilter', 'illimit', 'ilcontfrom' ),
220230 array( array('existing', 'nonredirects', 'all'), 50, null ),
221231 array(
@@ -225,7 +235,7 @@
226236 "ilcontfrom - from which point to continue. Use the 'next' value from previous queries.",
227237 "Example: query.php?what=imagelinks&titles=image:test.jpg&illimit=10",
228238 )),
229 - 'revisions' => array( "genPageHistory", false,
 239+ 'revisions' => array( 'genPageHistory', false,
230240 array( 'rvcomments', 'rvlimit', 'rvoffset', 'rvstart', 'rvend' ),
231241 array( false, 50, 0, null, null ),
232242 array(
@@ -238,6 +248,10 @@
239249 "rvend - timestamp of the latest entry",
240250 "Example: query.php?what=revisions&titles=Main%20Page&rvlimit=10&rvcomments",
241251 )),
 252+ 'content' => array( 'genPageContent', false, null, null, array(
 253+ "Raw page content",
 254+ "Example: query.php?what=content&titles=Main%20Page",
 255+ )),
242256 );
243257
244258 /**
@@ -269,6 +283,9 @@
270284 $this->normalizedTitles = array();
271285 }
272286
 287+ /**
 288+ * The core function - executes meta generators, populates basic page info, and then fills in the required additional data for all pages
 289+ */
273290 function execute() {
274291
275292 // Process metadata generators
@@ -286,6 +303,9 @@
287304 }
288305 }
289306
 307+ /**
 308+ * Helper method to call generators (either meta or non-meta)
 309+ */
290310 function callGenerators( $callMetaGenerators ) {
291311 foreach( $this->propGenerators as $property => &$generator ) {
292312 if( $generator[GEN_ISMETA] === $callMetaGenerators && in_array( $property, $this->properties )) {
@@ -294,6 +314,9 @@
295315 }
296316 }
297317
 318+ /**
 319+ * Output the result to the user
 320+ */
298321 function output($isError = false) {
299322 global $wgRequest, $wgUser;
300323
@@ -352,6 +375,9 @@
353376 }
354377 }
355378
 379+ /**
 380+ * Return an array of values that were given in a "a|b|c" notation, after it validates them against the list allowed values.
 381+ */
356382 function parseMultiValue( $valueName, $allowedValues ) {
357383 global $wgRequest;
358384
@@ -366,9 +392,16 @@
367393 return $valuesList;
368394 }
369395
 396+
370397 //
371398 // ************************************* GENERATORS *************************************
372399 //
 400+
 401+
 402+ /**
 403+ * Creates lists of pages to work on. User parameters 'titles' and 'pageids' will be added to the list, and information from page table will be provided.
 404+ * As the result of this method, $this->redirectPageIds and existingPageIds (arrays) will be available for other generators.
 405+ */
373406 function genPageInfo() {
374407 global $wgUser, $wgRequest;
375408
@@ -394,7 +427,7 @@
395428 // Make sure we remember the original title that was given to us
396429 // This way the caller can correlate new titles with the originally requested if they change namespaces, etc
397430 if( $titleString !== $titleObj->getPrefixedText() ) {
398 - $this->normalizedTitles[$titleString] = &$titleObj;
 431+ $this->normalizedTitles[$titleString] = $titleObj;
399432 }
400433 }
401434 if ( $linkBatch->isEmpty() ) {
@@ -530,6 +563,30 @@
531564 // When normalized title differs from what was given, append the given title(s)
532565 //
533566 foreach( $this->normalizedTitles as $givenTitle => &$title ) {
 567+
 568+
 569+
 570+
 571+
 572+
 573+
 574+
 575+
 576+echo "RAW: $givenTitle => " . $title->getPrefixedText() . "\n<br>";
 577+
 578+
 579+
 580+
 581+
 582+
 583+
 584+
 585+
 586+
 587+
 588+
 589+
 590+
534591 $pageId = $this->pageIdByText[$title->getPrefixedText()];
535592 $data = &$this->data['pages'][$pageId]['rawTitles'];
536593 $data['_element'] = 'title';
@@ -539,9 +596,15 @@
540597 return true; // success
541598 }
542599
 600+
543601 //
544602 // ************************************* META GENERATORS *************************************
545603 //
 604+
 605+
 606+ /**
 607+ * Get general site information
 608+ */
546609 function genMetaSiteInfo(&$prop, &$genInfo) {
547610 global $wgSitename, $wgVersion, $wgCapitalLinks;
548611 $meta = array();
@@ -556,6 +619,9 @@
557620 $this->data['meta']['site'] = $meta;
558621 }
559622
 623+ /**
 624+ * Get the list of localized namespaces
 625+ */
560626 function genMetaNamespaceInfo(&$prop, &$genInfo) {
561627 global $wgContLang;
562628 $meta = array();
@@ -566,21 +632,30 @@
567633 $this->data['meta']['namespaces'] = $meta;
568634 }
569635
 636+ /**
 637+ * Get current user's status information
 638+ */
570639 function genMetaUserInfo(&$prop, &$genInfo) {
571640 global $wgUser;
572641
 642+ extract( $this->getParams( $prop, $genInfo ));
573643 $meta = array();
574644 $meta['name'] = $wgUser->getName();
575645 if( $wgUser->isAnon() ) $meta['anonymous'] = '';
576646 if( $wgUser->isBot() ) $meta['bot'] = '';
577647 if( $wgUser->isBlocked() ) $meta[' blocked'] = '';
578 - $meta['groups'] = $wgUser->getGroups();
579 - $meta['groups']['_element'] = 'g';
580 - $meta['rights'] = $wgUser->getRights();
581 - $meta['rights']['_element'] = 'r';
 648+ if( $uiextended ) {
 649+ $meta['groups'] = $wgUser->getGroups();
 650+ $meta['groups']['_element'] = 'g';
 651+ $meta['rights'] = $wgUser->getRights();
 652+ $meta['rights']['_element'] = 'r';
 653+ }
582654 $this->data['meta']['user'] = $meta;
583655 }
584656
 657+ /**
 658+ * Add pagids of the most recently modified pages to the output
 659+ */
585660 function genMetaRecentChanges(&$prop, &$genInfo) {
586661
587662 extract( $this->getParams( $prop, $genInfo ));
@@ -636,6 +711,9 @@
637712 $this->db->freeResult( $res );
638713 }
639714
 715+ /**
 716+ * Add user pages to the list of titles to output (the actual user pages might not exist)
 717+ */
640718 function genUserPages(&$prop, &$genInfo) {
641719 global $wgContLang;
642720
@@ -661,50 +739,52 @@
662740 $this->db->freeResult( $res );
663741 }
664742
665 - //
666 - // TODO: This is very inefficient - we can get the actual page information, instead we make two identical query.
667 - //
 743+ /**
 744+ * Add all pages by a given namespace to the output
 745+ */
668746 function genMetaAllPages(&$prop, &$genInfo) {
 747+ //
 748+ // TODO: This is very inefficient - we can get the actual page information, instead we make two identical query.
 749+ //
669750 global $wgContLang;
670751 extract( $this->getParams( $prop, $genInfo ));
671752
672753 $ns = $wgContLang->getNsText($apnamespace);
673754 if( $ns === false ) {
674755 $this->dieUsage( "Unknown namespace $ns", 'ap_badnamespace' );
 756+ } else if( strlen($ns) > 0 ) {
 757+ $ns .= ':';
675758 }
676 - $ns .= ':';
677759
678760 $this->startProfiling();
679761 $res = $this->db->select(
680762 'page',
681763 'page_title',
682 - array( 'page_namespace=' . $this->db->addQuotes($apnamespace) . ' AND page_title>=' . $this->db->addQuotes($apfrom) ),
 764+ array( 'page_namespace' => intval($apnamespace), 'page_title>=' . $this->db->addQuotes($apfrom) ),
683765 $this->classname . '::genMetaAllPages',
684 - array( 'FORCE INDEX' => 'name_title', 'LIMIT' => $aplimit+1, 'ORDER BY' => 'page_title' ));
 766+ array( 'FORCE INDEX' => 'name_title', 'LIMIT' => $aplimit+1, 'ORDER BY' => 'page_namespace, page_title' ));
685767 $this->endProfiling($prop);
686768
687769 // Add found page ids to the list of requested titles - they will be auto-populated later
688770 $count = 0;
689771 while ( $row = $this->db->fetchObject( $res ) ) {
690 - if( ++$count >= $aplimit ) {
691 - // We've reached the one extra which shows that there are
692 - // additional pages to be had. Stop here...
 772+ if( ++$count > $aplimit ) {
 773+ // We've reached the one extra which shows that there are additional pages to be had. Stop here...
 774+ $this->addStatusMessage( $prop, array('next' => $row->page_title) );
693775 break;
694776 }
695777 $this->addRaw( 'titles', $ns . $row->page_title );
696778 }
697 - if( $count < $aplimit || !$row ) {
698 - $this->addStatusMessage( $prop, array('next' => 0) );
699 - } else {
700 - $this->addStatusMessage( $prop, array('next' => $row->page_title) );
701 - }
702779 $this->db->freeResult( $res );
703780 }
704781
705 - //
706 - // TODO: This is very inefficient - we can get the actual page information, instead we make two identical query.
707 - //
 782+ /**
 783+ * Add pages by the namespace without language links to the output
 784+ */
708785 function genMetaNoLangLinksPages(&$prop, &$genInfo) {
 786+ //
 787+ // TODO: This is very inefficient - we can get the actual page information, instead we make two identical query.
 788+ //
709789 global $wgContLang;
710790 extract( $this->getParams( $prop, $genInfo ));
711791
@@ -714,11 +794,11 @@
715795 // Find all pages without any rows in the langlinks table
716796 //
717797 $sql = 'SELECT'
718 - . ' page_id'
 798+ . ' page_id, page_title'
719799 . " FROM $page LEFT JOIN $langlinks ON page_id = ll_from"
720800 . ' WHERE'
721 - . ' ll_from IS NULL AND page_id >= ' . intval($nlfromid)
722 - . ' ORDER BY page_id'
 801+ . ' ll_from IS NULL AND page_namespace=' . intval($nlnamespace) . ' AND page_title>=' . $this->db->addQuotes($nlfrom)
 802+ . ' ORDER BY page_namespace, page_title'
723803 . ' LIMIT ' . intval($nllimit+1);
724804
725805 $this->startProfiling();
@@ -728,20 +808,17 @@
729809 // Add found page ids to the list of requested titles - they will be auto-populated later
730810 $count = 0;
731811 while ( $row = $this->db->fetchObject( $res ) ) {
732 - if( ++$count >= $nllimit ) {
733 - // We've reached the one extra which shows that there are
734 - // additional pages to be had. Stop here...
 812+ if( ++$count > $nllimit ) {
 813+ // We've reached the one extra which shows that there are additional pages to be had. Stop here...
 814+ $this->addStatusMessage( $prop, array('next' => $row->page_title) );
735815 break;
736816 }
737817 $this->addRaw( 'pageids', $row->page_id );
738818 }
739 - if( $count < $nllimit || !$row ) {
740 - $this->addStatusMessage( $prop, array('next' => 0) );
741 - } else {
742 - $this->addStatusMessage( $prop, array('next' => $row->page_id) );
743 - }
744819 $this->db->freeResult( $res );
745820 }
 821+
 822+
746823 //
747824 // ************************************* PAGE INFO GENERATORS *************************************
748825 //
@@ -851,7 +928,7 @@
852929 //
853930 $parameters = $this->getParams( $prop, $genInfo );
854931 $contFrom = $parameters["{$code}contfrom"];
855 - $limit = intval($parameters["{$code}limit"]) + 1;
 932+ $limit = intval($parameters["{$code}limit"]);
856933 $filter = $parameters["{$code}filter"];
857934 if( count($filter) != 1 ) {
858935 $this->dieUsage( "{$code}filter must either be 'all', 'existing', or 'nonredirects'", "{$code}_badmultifilter" );
@@ -947,7 +1024,7 @@
9481025 ."{$prefix}_from >= " . intval($fromPageId) . "))))";
9491026 }
9501027 }
951 - $options = array( 'ORDER BY' => $orderBy, 'LIMIT' => $limit );
 1028+ $options = array( 'ORDER BY' => $orderBy, 'LIMIT' => $limit+1 );
9521029 //
9531030 // Execute
9541031 //
@@ -962,24 +1039,22 @@
9631040
9641041 $count = 0;
9651042 while ( $row = $this->db->fetchObject( $res ) ) {
966 - if( ++$count >= $limit ) {
967 - // We've reached the one extra which shows that there are
968 - // additional pages to be had. Stop here...
 1043+ if( ++$count > $limit ) {
 1044+ // We've reached the one extra which shows that there are additional pages to be had. Stop here...
 1045+ $this->addStatusMessage( $prop,
 1046+ array('next' => ($isImage ? NS_IMAGE : $row->to_namespace) ."|{$row->to_title}|{$row->from_id}") );
9691047 break;
9701048 }
9711049 $pageId = $this->lookupPageIdByTitle( ($isImage ? NS_IMAGE : $row->to_namespace), $row->to_title );
9721050 $values = $this->getLinkInfo( $row->from_namespace, $row->from_title, $row->from_id );
9731051 $this->addPageSubElement( $pageId, $prop, $code, $values );
9741052 }
975 - if( $count < $limit || !$row ) {
976 - $this->addStatusMessage( $prop, array('next' => 0) );
977 - } else {
978 - $this->addStatusMessage( $prop,
979 - array('next' => ($isImage ? NS_IMAGE : $row->to_namespace) ."|{$row->to_title}|{$row->from_id}") );
980 - }
9811053 $this->db->freeResult( $res );
9821054 }
9831055
 1056+ /**
 1057+ * Add a list of revisions to the page history
 1058+ */
9841059 function genPageHistory(&$prop, &$genInfo) {
9851060 if( empty( $this->existingPageIds ) ) {
9861061 return;
@@ -1032,6 +1107,30 @@
10331108 $this->endProfiling($prop);
10341109 }
10351110
 1111+ /**
 1112+ * Add the raw content of the pages
 1113+ */
 1114+ function genPageContent(&$prop, &$genInfo) {
 1115+ if( empty( $this->existingPageIds ) ) {
 1116+ return;
 1117+ }
 1118+ $this->startProfiling();
 1119+ $res = $this->db->select(
 1120+ array('page', 'text'),
 1121+ array('page_id', 'old_text'),
 1122+ array('page_latest = old_id', 'page_id' => $this->existingPageIds),
 1123+ $this->classname . '::genPageContent'
 1124+ );
 1125+ $this->endProfiling($prop);
 1126+
 1127+ while ( $row = $this->db->fetchObject( $res ) ) {
 1128+ $this->addPageSubElement( $row->page_id, $prop, 'xml:space', 'preserve', false);
 1129+ $this->addPageSubElement( $row->page_id, $prop, '*', $row->old_text, false);
 1130+ }
 1131+ $this->db->freeResult( $res );
 1132+ }
 1133+
 1134+
10361135 //
10371136 // ************************************* UTILITIES *************************************
10381137 //
@@ -1102,6 +1201,9 @@
11031202 return $val;
11041203 }
11051204
 1205+ /**
 1206+ * Creates an array describing the properties of a given link
 1207+ */
11061208 function getLinkInfo( $ns, $title, $id = -1, $isRedirect = false ) {
11071209 return $this->getTitleInfo( Title::makeTitle( $ns, $title ), $id, $isRedirect );
11081210 }
@@ -1132,6 +1234,23 @@
11331235 return $data;
11341236 }
11351237
 1238+ /**
 1239+ * Adds a sub element to the page by its id.
 1240+ * Example for $multiItems = true (useful when there are many subelements with the same name, like langlinks or backlinks)
 1241+ * 'pages' => array (
 1242+ * $pageId => array (
 1243+ * $mainElem => array (
 1244+ * '_element' => $itemElem,
 1245+ * 0 => $params
 1246+ * 1 => $params
 1247+ * .....
 1248+ * Example for $multiItems = false (useful when there are few elements with unique names)
 1249+ * 'pages' => array (
 1250+ * $pageId => array (
 1251+ * $mainElem => array (
 1252+ * $itemElem => $params
 1253+ * .....
 1254+ */
11361255 function addPageSubElement( $pageId, $mainElem, $itemElem, $params, $multiItems = true ) {
11371256 $data = & $this->data['pages'][$pageId][$mainElem];
11381257 if( $multiItems ) {
@@ -1145,6 +1264,9 @@
11461265 }
11471266 }
11481267
 1268+ /**
 1269+ * Validate the proper format of the timestamp string (14 digits), and add quotes to it.
 1270+ */
11491271 function prepareTimestamp( $value ) {
11501272 if ( preg_match( '/^[0-9]{14}$/', $value ) ) {
11511273 return $this->db->addQuotes( $value );
@@ -1166,25 +1288,25 @@
11671289
11681290 $indentSize = 12;
11691291 $indstr = str_repeat(" ", $indentSize+7);
 1292+ $formatString = " %-{$indentSize}s - %s\n\n";
11701293
11711294 $formats = "";
11721295 foreach( $this->outputGenerators as $format => &$generator ) {
1173 - $formats .= sprintf( " %-{$indentSize}s - %s\n",
1174 - $format,
 1296+ $formats .= sprintf( $formatString, $format,
11751297 mergeDescriptionStrings($generator[GEN_DESC], $indstr));
11761298 }
11771299
11781300 $props = "\n *These properties apply to the entire site*\n";
11791301 foreach( $this->propGenerators as $property => &$generator ) {
11801302 if( $generator[GEN_ISMETA] ) {
1181 - $props .= sprintf( " %-{$indentSize}s - %s\n", $property,
 1303+ $props .= sprintf( $formatString, $property,
11821304 mergeDescriptionStrings($generator[GEN_DESC], $indstr));
11831305 }
11841306 }
11851307 $props .= "\n *These properties apply to the specified pages*\n";
11861308 foreach( $this->propGenerators as $property => &$generator ) {
11871309 if( !$generator[GEN_ISMETA] ) {
1188 - $props .= sprintf( " %-{$indentSize}s - %s\n", $property,
 1310+ $props .= sprintf( $formatString, $property,
11891311 mergeDescriptionStrings($generator[GEN_DESC], $indstr));
11901312 }
11911313 }
@@ -1195,49 +1317,50 @@
11961318 "",
11971319 "*------ Error: $message ($errorcode) ------*",
11981320 "",
1199 - "Summary:",
 1321+ "*Summary*",
12001322 " This API provides a way for your applications to query data directly from the MediaWiki servers.",
12011323 " One or more pieces of information about the site and/or a given list of pages can be retrieved.",
12021324 " Information may be returned in either a machine (xml, json, php) or a human readable (html, dbg) format.",
12031325 "",
1204 - "Usage:",
 1326+ "*Usage*",
12051327 " query.php ? format=... & what=...|...|... & titles=...|...|... & ...",
12061328 "",
1207 - "Common parameters:",
 1329+ "*Common parameters*",
12081330 " format - How should the output be formatted. See formats section.",
12091331 " what - What information the server should return. See properties section.",
12101332 " titles - A list of titles, separated by the pipe '|' symbol.",
12111333 " pageids - A list of page ids, separated by the pipe '|' symbol.",
12121334 " noprofile - When present, each sql query execution time will be hidden. (Optional)",
12131335 "",
1214 - "Examples:",
 1336+ "*Examples*",
12151337 " query.php?format=xml&what=links|templates&titles=User:Yurik",
12161338 " This query will return a list of all links and templates used on the User:Yurik",
12171339 "",
12181340 " query.php?format=xml&what=revisions&titles=Main_Page&rvlimit=100&rvstart=20060401000000&rvcomments",
12191341 " Get a list of 100 last revisions of the main page with comments, but only if it happened after midnight April 1st 2006",
12201342 "",
1221 - "Supported Formats:",
 1343+ "",
 1344+ "*Supported Formats*",
12221345 $formats,
12231346 "",
1224 - "Supported Properties:",
 1347+ "*Supported Properties*",
12251348 $props,
12261349 "",
1227 - "Notes:",
 1350+ "*Notes*",
12281351 " Some properties may add status information to the 'query' element.",
12291352 "",
1230 - "Credits:",
 1353+ "*Credits*",
 1354+ " This feature is maintained by Yuri Astrakhan (FirstnameLastname@gmail.com)",
 1355+ " You can also leave your comments and suggestions at http://en.wikipedia.org/wiki/User_talk:Yurik",
 1356+ "",
12311357 " This extension came as the result of IRC discussion between Yuri Astrakhan (en:Yurik), Tim Starling (en:Tim Starling), and Daniel Kinzler(de:Duesentrieb)",
12321358 " The extension was first implemented by Tim to provide interlanguage links and history.",
12331359 " It was later completelly rewritten by Yuri to allow for modular properties, meta information, and various formatting options.",
12341360 "",
1235 - " The code is maintained by Yuri Astrakhan (FirstnameLastname@gmail.com)",
1236 - " You can also leave your comments and suggestions at http://en.wikipedia.org/wiki/User_talk:Yurik",
1237 - "",
1238 - "User Status:",
 1361+ "*User Status*",
12391362 " You are " . ($wgUser->isAnon() ? "an anonymous" : "a logged-in") . " " . ($wgUser->isBot() ? "bot" : "user") . " " . $wgUser->getName(),
12401363 "",
1241 - "Version:",
 1364+ "*Version*",
12421365 ' $Id$',
12431366 "",
12441367 );
@@ -1248,6 +1371,9 @@
12491372 die(0);
12501373 }
12511374
 1375+ /**
 1376+ * Adds a status message into the <query> element, for a given module.
 1377+ */
12521378 function addStatusMessage( $module, $value, $preserveXmlSpacing = false ) {
12531379 if( !array_key_exists( 'query', $this->data )) {
12541380 $this->data['query'] = array();
@@ -1274,15 +1400,25 @@
12751401 }
12761402 }
12771403
 1404+ /**
 1405+ * Records the time of the call to this method
 1406+ */
12781407 function startProfiling() {
12791408 $this->startTime = wfTime();
12801409 }
 1410+
 1411+ /**
 1412+ * Records the running time of the given module since last startProfiling() call.
 1413+ */
12811414 function endProfiling( $module ) {
12821415 $timeDelta = wfTime() - $this->startTime;
12831416 unset($this->startTime);
12841417 $this->addStatusMessage( $module, array( 'time' => sprintf( "%1.2fms", $timeDelta * 1000.0 ) ));
12851418 }
12861419
 1420+ /**
 1421+ * Validate the value against the minimum and user/bot maximum limits. Prints usage info on failure.
 1422+ */
12871423 function validateLimit( $varname, &$value, $max, $botMax = false, $min = 1 ) {
12881424 global $wgUser;
12891425 if( !$botMax ) $botMax = $max;
@@ -1302,9 +1438,14 @@
13031439 }
13041440 }
13051441
 1442+
13061443 //
13071444 // ************************************* Print Methods *************************************
13081445 //
 1446+
 1447+/**
 1448+* Prints data in html format. Escapes all unsafe characters. Adds an HTML warning in the begining.
 1449+*/
13091450 function printHTML( &$data ) {
13101451 global $wgRequest;
13111452 ?>
@@ -1330,6 +1471,10 @@
13311472 </body>
13321473 <?php
13331474 }
 1475+
 1476+/**
 1477+* Prety-print various elements in HTML format, such as xml tags and URLs. This method also replaces any "<" with &lt;
 1478+*/
13341479 function htmlprinter( $text ) {
13351480 // encode all tags as safe blue strings
13361481 $text = ereg_replace( '\<([^>]+)\>', '<font color=blue>&lt;\1&gt;</font>', $text );
@@ -1342,26 +1487,48 @@
13431488 echo $text;
13441489 }
13451490
 1491+/**
 1492+* Output data in XML format
 1493+*/
13461494 function printXML( &$data ) {
13471495 global $wgRequest;
13481496 echo '<?xml version="1.0" encoding="utf-8"?>';
13491497 recXmlPrint( 'echoprinter', 'yurik', $data, $wgRequest->getCheck('xmlindent') ? -2 : null );
13501498 }
 1499+/**
 1500+* Pass-through printer.
 1501+*/
13511502 function echoprinter( $text ) {
13521503 echo $text;
13531504 }
 1505+
 1506+/**
 1507+* Sanitizes the data and prints it with the print_r()
 1508+*/
13541509 function printHumanReadable( &$data ) {
13551510 sanitizeOutputData($data);
13561511 print_r($data);
13571512 }
1358 -function printParsableCode( &$data ) {
1359 - sanitizeOutputData($data);
 1513+
 1514+/**
 1515+* Prints the data as is, using var_export().
 1516+* This format exposes all internals of the data object unescaped, thus it must never be outputed with meta set to text/*
 1517+*/
 1518+function printDebugCode( &$data ) {
13601519 var_export($data);
13611520 }
 1521+
 1522+/**
 1523+* Sanitizes the data and serialize() it so that other php scripts can easily consume the data
 1524+*/
13621525 function printPHP( &$data ) {
13631526 sanitizeOutputData($data);
13641527 echo serialize($data);
13651528 }
 1529+
 1530+/**
 1531+* Sanitizes the data and serializes it in JSON format
 1532+*/
13661533 function printJSON( &$data ) {
13671534 sanitizeOutputData($data);
13681535 if ( !function_exists( 'json_encode' ) ) {
@@ -1446,6 +1613,9 @@
14471614 }
14481615 }
14491616
 1617+/**
 1618+* Helper method that merges an array of strings and prepends each line with an indentation string
 1619+*/
14501620 function mergeDescriptionStrings( &$value, $indstr ) {
14511621 if( is_array($value) ) {
14521622 $value = implode( "\n", $value );
@@ -1453,6 +1623,9 @@
14541624 return str_replace("\n", "\n$indstr", $value);
14551625 }
14561626
 1627+/**
 1628+* Merge all known generator parameters into one array of values. Used for logging.
 1629+*/
14571630 function mergeParameters( &$generators ) {
14581631 $params = array();
14591632 foreach( $generators as $property => &$generator ) {

Status & tagging log