r14545 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14544‎ | r14545 | r14546 >
Date:02:45, 3 June 2006
Author:brion
Status:old
Tags:
Comment:
Revert last commit, by request (apparently it's broken)
Modified paths:
  • /trunk/extensions/BotQuery/query.php (modified) (history)

Diff [purge]

Index: trunk/extensions/BotQuery/query.php
@@ -111,7 +111,7 @@
112112 * 0) Function to call
113113 * 1) true/false - does this property work on individual pages? (false for site's metadata)
114114 * 2) array of accepted parameters
115 - * 3) array of default parameter values. If the default value is an array itself, only the listed values are allowed, and the 1st value is taken as default.
 115+ * 3) array of default parameter values
116116 * 4) Format description
117117 */
118118 var $propGenerators = array(
@@ -209,7 +209,7 @@
210210 "blfilter - Of all given pages, which should be queried:",
211211 " 'nonredirects', 'existing' (blue links, default), or 'all' (red links)",
212212 "bllimit - how many total links to return",
213 - "blcontfrom - from which point to continue. Use the 'next' value from the previous queries.",
 213+ "blcontfrom - from which point to continue. Use the 'next' value from previous queries.",
214214 "Example: query.php?what=backlinks&titles=Main%20Page&bllimit=10",
215215 )),
216216 'embeddedin' => array( 'genPageBackLinksHelper', false,
@@ -221,40 +221,35 @@
222222 "eifilter - Of all given pages, which should be queried:",
223223 " 'nonredirects', 'existing' (blue links, default), or 'all' (red links)",
224224 "eilimit - how many total links to return",
225 - "eicontfrom - from which point to continue. Use the 'next' value from the previous queries.",
 225+ "eicontfrom - from which point to continue. Use the 'next' value from previous queries.",
226226 "Example: query.php?what=embeddedin&titles=Template:Stub&eilimit=10",
227227 )),
228228 'imagelinks' => array( 'genPageBackLinksHelper', false,
229229 array( 'ilfilter', 'illimit', 'ilcontfrom' ),
230 - array( array('all', 'existing', 'nonredirects'), 50, null ),
 230+ array( array('existing', 'nonredirects', 'all'), 50, null ),
231231 array(
232232 "What pages use this image(s)",
233233 "ilfilter - Of all given images, which should be queried:",
234 - " 'nonredirects', 'existing', or 'all' (default, includes non-existant or those stored on Wikimedia Commons)",
 234+ " 'nonredirects', 'existing' (default), or 'all' (including non-existant)",
235235 "illimit - how many total links to return",
236 - "ilcontfrom - from which point to continue. Use the 'next' value from the previous queries.",
237 - "Example: query.php?what=imagelinks&titles=Image:HermitageAcrossNeva.jpg&illimit=10",
 236+ "ilcontfrom - from which point to continue. Use the 'next' value from previous queries.",
 237+ "Example: query.php?what=imagelinks&titles=image:test.jpg&illimit=10",
238238 )),
239239 'revisions' => array( 'genPageHistory', false,
240 - array( 'rvcomments', 'rvcontent', 'rvlimit', 'rvoffset', 'rvstart', 'rvend' ),
241 - array( false, false, 50, 0, null, null ),
 240+ array( 'rvcomments', 'rvlimit', 'rvoffset', 'rvstart', 'rvend' ),
 241+ array( false, 50, 0, null, null ),
242242 array(
243243 "Revision history - Lists edits performed to the given pages",
244244 "Parameters supported:",
245245 "rvcomments - if specified, the result will include summary strings",
246 - "rvcontent - if specified, the result will include raw wiki text.",
247 - " This parameter is *very slow*, use only when needed.",
248246 "rvlimit - how many links to return *for each title*",
249247 "rvoffset - when too many results are found, use this to page",
250248 "rvstart - timestamp of the earliest entry",
251249 "rvend - timestamp of the latest entry",
252250 "Example: query.php?what=revisions&titles=Main%20Page&rvlimit=10&rvcomments",
253251 )),
254 - 'content' => array( 'genPageContent', false, null, null,
255 - array(
256 - "Raw page content - Retrieves raw wiki markup for each page.",
257 - "This query is *very slow*! Please optimize content requests to reduce load on the servers.",
258 - "Duplicate results may be obtained through revisions+rvcontent request",
 252+ 'content' => array( 'genPageContent', false, null, null, array(
 253+ "Raw page content",
259254 "Example: query.php?what=content&titles=Main%20Page",
260255 )),
261256 );
@@ -325,7 +320,9 @@
326321 function output($isError = false) {
327322 global $wgRequest, $wgUser;
328323
329 - $this->recordProfiling( 'total', 'time', $this->totalStartTime );
 324+ // hack: pretend that profiling was started at the begining of the class execution.
 325+ $this->startTime = $this->totalStartTime;
 326+ $this->endProfiling( 'total' );
330327
331328 $printer = $this->outputGenerators[$this->format][GEN_FUNCTION];
332329 $mime = $this->outputGenerators[$this->format][GEN_MIME];
@@ -407,7 +404,7 @@
408405 */
409406 function genPageInfo() {
410407 global $wgUser, $wgRequest;
411 - $this->startProfiling();
 408+
412409 $where = array();
413410
414411 //
@@ -417,8 +414,8 @@
418415 if( $titles !== null ) {
419416 $titles = explode( '|', $titles );
420417 $linkBatch = new LinkBatch;
421 - foreach ( $titles as &$titleString ) {
422 - $titleObj = &Title::newFromText( $titleString );
 418+ foreach ( $titles as $titleString ) {
 419+ $titleObj = Title::newFromText( $titleString );
423420 if ( !$titleObj ) {
424421 $this->dieUsage( "bad title $titleString", 'pi_invalidtitle' );
425422 }
@@ -445,6 +442,7 @@
446443 } else {
447444 $nonexistentPages = array(); // empty data to keep unset() happy
448445 }
 446+
449447 //
450448 // List of Page IDs
451449 //
@@ -460,10 +458,9 @@
461459 $where['page_id'] = $pageids;
462460 $this->requestsize += count($pageids);
463461 }
464 -
 462+
465463 // Do we have anything to do?
466464 if( $this->requestsize == 0 ) {
467 - // Do not end profiling here, as it will introduce an element to the data object, and the usage screen may not be shown.
468465 return false; // Nothing to do for any of the page generators
469466 }
470467
@@ -484,12 +481,12 @@
485482 // Query page information with the given lists of titles & pageIDs
486483 //
487484 $this->redirectPageIds = array();
488 - $this->startDbProfiling();
 485+ $this->startProfiling();
489486 $res = $this->db->select( 'page',
490487 array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_touched', 'page_latest' ),
491488 $this->db->makeList( $where, LIST_OR ),
492489 $this->classname . '::genPageInfo' );
493 - $this->endDbProfiling('pageInfo');
 490+ $this->endProfiling('pageInfo');
494491 while( $row = $this->db->fetchObject( $res ) ) {
495492 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
496493 if ( !$title->userCanRead() ) {
@@ -571,7 +568,7 @@
572569 $data['_element'] = 'title';
573570 $data[] = $givenTitle;
574571 }
575 - $this->endProfiling('pageInfo');
 572+
576573 return true; // success
577574 }
578575
@@ -586,7 +583,6 @@
587584 */
588585 function genMetaSiteInfo(&$prop, &$genInfo) {
589586 global $wgSitename, $wgVersion, $wgCapitalLinks;
590 - $this->startProfiling();
591587 $meta = array();
592588 $mainPage = Title::newFromText( wfMsgForContent( 'mainpage' ) );
593589
@@ -597,7 +593,6 @@
598594 $meta['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // "case-insensitive" option is reserved for future
599595
600596 $this->data['meta']['site'] = $meta;
601 - $this->endProfiling($prop);
602597 }
603598
604599 /**
@@ -605,14 +600,12 @@
606601 */
607602 function genMetaNamespaceInfo(&$prop, &$genInfo) {
608603 global $wgContLang;
609 - $this->startProfiling();
610604 $meta = array();
611605 $meta['_element'] = 'ns';
612606 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
613607 $meta[$ns] = array( "id"=>$ns, "*" => $title );
614608 }
615609 $this->data['meta']['namespaces'] = $meta;
616 - $this->endProfiling($prop);
617610 }
618611
619612 /**
@@ -620,7 +613,7 @@
621614 */
622615 function genMetaUserInfo(&$prop, &$genInfo) {
623616 global $wgUser;
624 - $this->startProfiling();
 617+
625618 extract( $this->getParams( $prop, $genInfo ));
626619 $meta = array();
627620 $meta['name'] = $wgUser->getName();
@@ -634,14 +627,13 @@
635628 $meta['rights']['_element'] = 'r';
636629 }
637630 $this->data['meta']['user'] = $meta;
638 - $this->endProfiling($prop);
639631 }
640632
641633 /**
642634 * Add pagids of the most recently modified pages to the output
643635 */
644636 function genMetaRecentChanges(&$prop, &$genInfo) {
645 - $this->startProfiling();
 637+
646638 extract( $this->getParams( $prop, $genInfo ));
647639 # It makes no sense to hide both anons and logged-in users
648640 if( in_array('anons', $rchide) && in_array('liu', $rchide) ) {
@@ -678,7 +670,7 @@
679671 $options = array( 'USE INDEX' => 'rc_timestamp', 'LIMIT' => $rclimit );
680672 $options['ORDER BY'] = 'rc_timestamp' . ( $rcfrom != '' ? '' : ' DESC' );
681673
682 - $this->startDbProfiling();
 674+ $this->startProfiling();
683675 $res = $this->db->select(
684676 'recentchanges',
685677 'rc_cur_id',
@@ -686,14 +678,13 @@
687679 $this->classname . '::genMetaRecentChanges',
688680 $options
689681 );
690 - $this->endDbProfiling($prop);
 682+ $this->endProfiling($prop);
691683 while ( $row = $this->db->fetchObject( $res ) ) {
692684 if( $row->rc_cur_id != 0 ) {
693685 $this->addRaw( 'pageids', $row->rc_cur_id );
694686 }
695687 }
696688 $this->db->freeResult( $res );
697 - $this->endProfiling($prop);
698689 }
699690
700691 /**
@@ -701,12 +692,12 @@
702693 */
703694 function genUserPages(&$prop, &$genInfo) {
704695 global $wgContLang;
705 - $this->startProfiling();
 696+
706697 extract( $this->getParams( $prop, $genInfo ));
707698
708699 $this->validateLimit( 'uslimit', $uslimit, 50, 1000 );
709700
710 - $this->startDbProfiling();
 701+ $this->startProfiling();
711702 $res = $this->db->select(
712703 'user',
713704 'user_name',
@@ -714,7 +705,7 @@
715706 $this->classname . '::genUserPages',
716707 array( 'ORDER BY' => 'user_name', 'LIMIT' => $uslimit )
717708 );
718 - $this->endDbProfiling($prop);
 709+ $this->endProfiling($prop);
719710
720711 $userNS = $wgContLang->getNsText(NS_USER);
721712 if( !$userNS ) $userNS = 'User';
@@ -724,7 +715,6 @@
725716 $this->addRaw( 'titles', $userNS . $row->user_name );
726717 }
727718 $this->db->freeResult( $res );
728 - $this->endProfiling($prop);
729719 }
730720
731721 /**
@@ -735,7 +725,6 @@
736726 // TODO: This is very inefficient - we can get the actual page information, instead we make two identical query.
737727 //
738728 global $wgContLang;
739 - $this->startProfiling();
740729 extract( $this->getParams( $prop, $genInfo ));
741730
742731 $this->validateLimit( 'aplimit', $aplimit, 50, 1000 );
@@ -747,14 +736,14 @@
748737 $ns .= ':';
749738 }
750739
751 - $this->startDbProfiling();
 740+ $this->startProfiling();
752741 $res = $this->db->select(
753742 'page',
754743 'page_title',
755744 array( 'page_namespace' => intval($apnamespace), 'page_title>=' . $this->db->addQuotes($apfrom) ),
756745 $this->classname . '::genMetaAllPages',
757 - array( 'USE INDEX' => 'name_title', 'LIMIT' => $aplimit+1, 'ORDER BY' => 'page_namespace, page_title' ));
758 - $this->endDbProfiling($prop);
 746+ array( 'FORCE INDEX' => 'name_title', 'LIMIT' => $aplimit+1, 'ORDER BY' => 'page_namespace, page_title' ));
 747+ $this->endProfiling($prop);
759748
760749 // Add found page ids to the list of requested titles - they will be auto-populated later
761750 $count = 0;
@@ -767,7 +756,6 @@
768757 $this->addRaw( 'titles', $ns . $row->page_title );
769758 }
770759 $this->db->freeResult( $res );
771 - $this->endProfiling($prop);
772760 }
773761
774762 /**
@@ -778,7 +766,6 @@
779767 // TODO: This is very inefficient - we can get the actual page information, instead we make two identical query.
780768 //
781769 global $wgContLang;
782 - $this->startProfiling();
783770 extract( $this->getParams( $prop, $genInfo ));
784771 $this->validateLimit( 'nllimit', $nllimit, 50, 1000 );
785772 extract( $this->db->tableNames( 'page', 'langlinks' ) );
@@ -794,9 +781,9 @@
795782 . ' ORDER BY page_namespace, page_title'
796783 . ' LIMIT ' . intval($nllimit+1);
797784
798 - $this->startDbProfiling();
 785+ $this->startProfiling();
799786 $res = $this->db->query( $sql, $this->classname . '::genMetaNoLangLinksPages' );
800 - $this->endDbProfiling($prop);
 787+ $this->endProfiling($prop);
801788
802789 // Add found page ids to the list of requested titles - they will be auto-populated later
803790 $count = 0;
@@ -809,7 +796,6 @@
810797 $this->addRaw( 'pageids', $row->page_id );
811798 }
812799 $this->db->freeResult( $res );
813 - $this->endProfiling($prop);
814800 }
815801
816802
@@ -826,7 +812,6 @@
827813 if( empty( $this->redirectPageIds ) ) {
828814 return;
829815 }
830 - $this->startProfiling();
831816 extract( $this->db->tableNames( 'page', 'pagelinks' ) );
832817
833818 //
@@ -858,9 +843,9 @@
859844 "pb.page_is_redirect IS NULL OR pb.page_is_redirect = '1'"
860845 ), LIST_AND );
861846
862 - $this->startDbProfiling();
 847+ $this->startProfiling();
863848 $res = $this->db->query( $sql, $this->classname . '::genRedirectInfo' );
864 - $this->endDbProfiling('redirects');
 849+ $this->endProfiling('redirects');
865850 while ( $row = $this->db->fetchObject( $res ) ) {
866851 $this->addPageSubElement( $row->a_id, 'redirect', 'to', $this->getLinkInfo( $row->b_namespace, $row->b_title, $row->b_id, $row->b_is_redirect ), false);
867852 if( $row->b_is_redirect ) {
@@ -868,7 +853,6 @@
869854 }
870855 }
871856 $this->db->freeResult( $res );
872 - $this->endProfiling($prop);
873857 }
874858
875859 var $genPageLinksSettings = array( // database column name prefix, output element name
@@ -883,10 +867,9 @@
884868 if( empty($this->nonRedirPageIds) ) {
885869 return;
886870 }
887 - $this->startProfiling();
888871 extract( $this->genPageLinksSettings[$prop] );
889872
890 - $this->startDbProfiling();
 873+ $this->startProfiling();
891874 $res = $this->db->select(
892875 $linktbl,
893876 array( "{$prefix}_from from_id",
@@ -894,7 +877,7 @@
895878 "{$prefix}_title to_title" ),
896879 array( "{$prefix}_from" => $this->nonRedirPageIds ),
897880 $this->classname . "::genPageLinks_{$code}" );
898 - $this->endDbProfiling($prop);
 881+ $this->endProfiling($prop);
899882
900883 while ( $row = $this->db->fetchObject( $res ) ) {
901884 if( $langlinks ) {
@@ -905,7 +888,6 @@
906889 $this->addPageSubElement( $row->from_id, $prop, $code, $values);
907890 }
908891 $this->db->freeResult( $res );
909 - $this->endProfiling($prop);
910892 }
911893
912894 var $genPageBackLinksSettings = array( // database column name prefix, output element name
@@ -918,7 +900,7 @@
919901 * $type - either 'template' or 'page'
920902 */
921903 function genPageBackLinksHelper(&$prop, &$genInfo) {
922 - $this->startProfiling();
 904+
923905 extract( $this->genPageBackLinksSettings[$prop] );
924906
925907 //
@@ -1027,14 +1009,14 @@
10281010 //
10291011 // Execute
10301012 //
1031 - $this->startDbProfiling();
 1013+ $this->startProfiling();
10321014 $res = $this->db->select(
10331015 array( $linktbl, 'page' ),
10341016 $columns,
10351017 $where,
10361018 $this->classname . "::genPageBackLinks_{$code}",
10371019 $options );
1038 - $this->endDbProfiling($prop);
 1020+ $this->endProfiling($prop);
10391021
10401022 $count = 0;
10411023 while ( $row = $this->db->fetchObject( $res ) ) {
@@ -1049,7 +1031,6 @@
10501032 $this->addPageSubElement( $pageId, $prop, $code, $values );
10511033 }
10521034 $this->db->freeResult( $res );
1053 - $this->endProfiling($prop);
10541035 }
10551036
10561037 /**
@@ -1059,11 +1040,9 @@
10601041 if( empty( $this->existingPageIds ) ) {
10611042 return;
10621043 }
1063 - $this->startProfiling();
10641044 extract( $this->getParams( $prop, $genInfo ));
10651045
1066 - $tables = array('revision');
1067 - $fields = array('rev_id', 'rev_text_id', 'rev_timestamp', 'rev_user', 'rev_user_text', 'rev_minor_edit');
 1046+ $fields = array('rev_id', 'rev_timestamp', 'rev_user', 'rev_user_text', 'rev_minor_edit');
10681047 if( isset($rvcomments) ) {
10691048 $fields[] = 'rev_comment';
10701049 }
@@ -1081,30 +1060,15 @@
10821061 if( $rvoffset !== 0 ) {
10831062 $options['OFFSET'] = $rvoffset;
10841063 }
1085 - if( isset($rvcontent) ) {
1086 - $this->validateLimit( 'content + rvlimit * pages', $rvlimit * count($this->existingPageIds), 50, 200 );
1087 - $tables[] = 'text';
1088 - $fields[] = 'old_id';
1089 - $fields[] = 'old_text';
1090 - $fields[] = 'old_flags';
1091 - $conds[] = 'rev_text_id=old_id';
1092 - } else {
1093 - $this->validateLimit( 'rvlimit * pages', $rvlimit * count($this->existingPageIds), 200, 2000 );
1094 - }
1095 -
1096 - $this->startDbProfiling();
 1064+ $this->validateLimit( 'rvlimit * pages', $rvlimit * count($this->existingPageIds), 200, 2000 );
 1065+
 1066+ $this->startProfiling();
10971067 foreach( $this->existingPageIds as $pageId ) {
10981068 $conds['rev_page'] = $pageId;
1099 - $res = $this->db->select(
1100 - $tables,
1101 - $fields,
1102 - $conds,
1103 - $this->classname . '::genPageHistory',
1104 - $options );
 1069+ $res = $this->db->select( 'revision', $fields, $conds, $this->classname . '::genPageHistory', $options );
11051070 while ( $row = $this->db->fetchObject( $res ) ) {
11061071 $vals = array(
11071072 'revid' => $row->rev_id,
1108 - 'oldid' => $row->rev_text_id,
11091073 'timestamp' => wfTimestamp( TS_ISO_8601, $row->rev_timestamp ),
11101074 'user' => $row->rev_user_text,
11111075 );
@@ -1114,17 +1078,11 @@
11151079 if( $row->rev_minor_edit ) {
11161080 $vals['minor'] = '';
11171081 }
1118 - if( $rvcomments ) {
1119 - $vals['comment'] = $row->rev_comment;
1120 - }
1121 - if( isset($rvcontent) ) {
1122 - $vals['*'] = Revision::getRevisionText( $row );
1123 - }
 1082+ $vals['*'] = $rvcomments ? $row->rev_comment : '';
11241083 $this->addPageSubElement( $pageId, 'revisions', 'rv', $vals);
11251084 }
11261085 $this->db->freeResult( $res );
11271086 }
1128 - $this->endDbProfiling($prop);
11291087 $this->endProfiling($prop);
11301088 }
11311089
@@ -1135,33 +1093,23 @@
11361094 if( empty( $this->existingPageIds ) ) {
11371095 return;
11381096 }
 1097+ $this->validateLimit( 'co_querytoobig', count($this->existingPageIds), 50, 200 );
11391098 $this->startProfiling();
1140 -
1141 - // Generate the WHERE clause for pageIds+RevisionIds
1142 - $ids = array();
1143 - foreach( $this->data['pages'] as $pageId => &$page ) {
1144 - if( $pageId > 0 ) {
1145 - $ids[] = "(rev_page=$pageId AND rev_id={$page['revid']})";
1146 - }
1147 - }
1148 - $this->validateLimit( 'co_querytoobig', count($ids), 50, 200 );
1149 -
1150 - $this->startDbProfiling();
11511099 $res = $this->db->select(
1152 - array('revision', 'text'),
1153 - array('rev_page', 'old_id', 'old_text', 'old_flags'),
1154 - array('rev_text_id=old_id', implode('OR', $ids)),
 1100+ array('page', 'revision', 'text'),
 1101+ array('page_id', 'old_id', 'old_text', 'old_flags'),
 1102+ array('page_id=rev_page', 'page_latest=rev_id', 'rev_text_id=old_id', 'page_id' => $this->existingPageIds),
11551103 $this->classname . '::genPageContent'
11561104 );
11571105 while ( $row = $this->db->fetchObject( $res ) ) {
1158 - $this->addPageSubElement( $row->rev_page, $prop, 'xml:space', 'preserve', false);
1159 - $this->addPageSubElement( $row->rev_page, $prop, '*', Revision::getRevisionText( $row ), false);
 1106+ $this->addPageSubElement( $row->page_id, $prop, 'xml:space', 'preserve', false);
 1107+ $this->addPageSubElement( $row->page_id, $prop, '*', Revision::getRevisionText( $row ), false);
11601108 }
11611109 $this->db->freeResult( $res );
1162 - $this->endDbProfiling($prop); // Revision::getRevisionText is also a database call, so we include them in this scope
1163 - $this->endProfiling($prop);
 1110+ $this->endProfiling($prop); // getRevisionText is also a database call
11641111 }
11651112
 1113+
11661114 //
11671115 // ************************************* UTILITIES *************************************
11681116 //
@@ -1437,33 +1385,15 @@
14381386 function startProfiling() {
14391387 $this->startTime = wfTime();
14401388 }
1441 - /**
1442 - * Same as startProfiling, but used for DB access only
1443 - */
1444 - function startDbProfiling() {
1445 - $this->startDbTime = wfTime();
1446 - }
14471389
14481390 /**
1449 - * Records the running time of the given module since last startDbProfiling() call.
 1391+ * Records the running time of the given module since last startProfiling() call.
14501392 */
14511393 function endProfiling( $module ) {
1452 - $this->recordProfiling( $module, 'time', $this->startTime );
 1394+ $timeDelta = wfTime() - $this->startTime;
 1395+ unset($this->startTime);
 1396+ $this->addStatusMessage( $module, array( 'time' => sprintf( "%1.2fms", $timeDelta * 1000.0 ) ));
14531397 }
1454 - /**
1455 - * Same as endProfiling, but used for DB access only
1456 - */
1457 - function endDbProfiling( $module ) {
1458 - $this->recordProfiling( $module, 'dbtime', $this->startDbTime );
1459 - }
1460 - /**
1461 - * Helper profiling function
1462 - */
1463 - function recordProfiling( $module, $type, &$start ) {
1464 - $timeDelta = wfTime() - $start;
1465 - unset($start);
1466 - $this->addStatusMessage( $module, array( $type => sprintf( "%1.2fms", $timeDelta * 1000.0 ) ));
1467 - }
14681398
14691399 /**
14701400 * Validate the value against the minimum and user/bot maximum limits. Prints usage info on failure.

Status & tagging log