| Index: trunk/phase3/includes/api/ApiQueryPageProps.php |
| — | — | @@ -0,0 +1,184 @@ |
| | 2 | +<?php |
| | 3 | + |
| | 4 | +/** |
| | 5 | + * Created on Sep 25, 2006 |
| | 6 | + * |
| | 7 | + * API for MediaWiki 1.8+ |
| | 8 | + * |
| | 9 | + * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| | 10 | + * |
| | 11 | + * This program is free software; you can redistribute it and/or modify |
| | 12 | + * it under the terms of the GNU General Public License as published by |
| | 13 | + * the Free Software Foundation; either version 2 of the License, or |
| | 14 | + * (at your option) any later version. |
| | 15 | + * |
| | 16 | + * This program is distributed in the hope that it will be useful, |
| | 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| | 19 | + * GNU General Public License for more details. |
| | 20 | + * |
| | 21 | + * You should have received a copy of the GNU General Public License along |
| | 22 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| | 23 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| | 24 | + * http://www.gnu.org/copyleft/gpl.html |
| | 25 | + */ |
| | 26 | + |
| | 27 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| | 28 | + // Eclipse helper - will be ignored in production |
| | 29 | + require_once( 'ApiQueryBase.php' ); |
| | 30 | +} |
| | 31 | + |
| | 32 | +/** |
| | 33 | + * A query module to show basic page information. |
| | 34 | + * |
| | 35 | + * @ingroup API |
| | 36 | + */ |
| | 37 | +class ApiQueryPageProps extends ApiQueryBase { |
| | 38 | + |
| | 39 | + public function __construct( $query, $moduleName ) { |
| | 40 | + parent::__construct( $query, $moduleName, 'pp' ); |
| | 41 | + } |
| | 42 | + |
| | 43 | + public function execute() { |
| | 44 | + $this->params = $this->extractRequestParams(); |
| | 45 | + |
| | 46 | + $pageSet = $this->getPageSet(); |
| | 47 | + $this->titles = $pageSet->getGoodTitles(); |
| | 48 | + $this->missing = $pageSet->getMissingTitles(); |
| | 49 | + $this->everything = $this->titles + $this->missing; |
| | 50 | + $result = $this->getResult(); |
| | 51 | + |
| | 52 | + uasort( $this->everything, array( 'Title', 'compare' ) ); |
| | 53 | + if ( !is_null( $this->params['continue'] ) ) { |
| | 54 | + // Throw away any titles we're gonna skip so they don't |
| | 55 | + // clutter queries |
| | 56 | + $cont = explode( '|', $this->params['continue'] ); |
| | 57 | + if ( count( $cont ) != 2 ) { |
| | 58 | + $this->dieUsage( 'Invalid continue param. You should pass the original ' . |
| | 59 | + 'value returned by the previous query', '_badcontinue' ); |
| | 60 | + } |
| | 61 | + $conttitle = Title::makeTitleSafe( $cont[0], $cont[1] ); |
| | 62 | + foreach ( $this->everything as $pageid => $title ) { |
| | 63 | + if ( Title::compare( $title, $conttitle ) >= 0 ) { |
| | 64 | + break; |
| | 65 | + } |
| | 66 | + unset( $this->titles[$pageid] ); |
| | 67 | + unset( $this->missing[$pageid] ); |
| | 68 | + unset( $this->everything[$pageid] ); |
| | 69 | + } |
| | 70 | + } |
| | 71 | + |
| | 72 | + |
| | 73 | + |
| | 74 | + foreach ( $this->everything as $pageid => $title ) { |
| | 75 | + $pageInfo = $this->extractPageInfo( $pageid, $title ); |
| | 76 | + $fit = $result->addValue( array( |
| | 77 | + 'query', |
| | 78 | + 'pages' |
| | 79 | + ), $pageid, $pageInfo ); |
| | 80 | + if ( !$fit ) { |
| | 81 | + $this->setContinueEnumParameter( 'continue', |
| | 82 | + $title->getNamespace() . '|' . |
| | 83 | + $title->getText() ); |
| | 84 | + break; |
| | 85 | + } |
| | 86 | + } |
| | 87 | + } |
| | 88 | + |
| | 89 | + /** |
| | 90 | + * Get a result array with information about a title |
| | 91 | + * @param $pageid int Page ID (negative for missing titles) |
| | 92 | + * @param $title Title object |
| | 93 | + * @return array |
| | 94 | + */ |
| | 95 | + private function extractPageInfo( $pageid, $title ) { |
| | 96 | + global $wgPageProps; |
| | 97 | + |
| | 98 | + $pageInfo = array(); |
| | 99 | + if ( $title->exists() ) { |
| | 100 | + |
| | 101 | + $dbr = wfGetDB( DB_SLAVE ); |
| | 102 | + |
| | 103 | + $res = $dbr->select( |
| | 104 | + 'page_props', |
| | 105 | + array( 'pp_propname', 'pp_value' ), |
| | 106 | + array( 'pp_page' => $pageid ), |
| | 107 | + __METHOD__ |
| | 108 | + ); |
| | 109 | + |
| | 110 | + foreach( $res as $row ) { |
| | 111 | + if( isset( $wgPageProps[$row->pp_propname] ) ) { |
| | 112 | + if( !is_null( $prop ) && !in_array( $row->pp_propname, $prop ) ) { |
| | 113 | + continue; |
| | 114 | + } |
| | 115 | + $pageInfo[$row->pp_propname] = $row->pp_value; |
| | 116 | + } |
| | 117 | + } |
| | 118 | + |
| | 119 | + } |
| | 120 | + |
| | 121 | + return $pageInfo; |
| | 122 | + } |
| | 123 | + |
| | 124 | + public function getCacheMode( $params ) { |
| | 125 | + return 'public'; |
| | 126 | + } |
| | 127 | + |
| | 128 | + public function getAllowedParams() { |
| | 129 | + global $wgPageProps; |
| | 130 | + |
| | 131 | + return array( |
| | 132 | + 'prop' => array( |
| | 133 | + ApiBase::PARAM_DFLT => null, |
| | 134 | + ApiBase::PARAM_ISMULTI => true, |
| | 135 | + ApiBase::PARAM_TYPE => array_keys( $wgPageProps ) |
| | 136 | + ), |
| | 137 | + 'continue' => null, |
| | 138 | + ); |
| | 139 | + } |
| | 140 | + |
| | 141 | + public function getParamDescription() { |
| | 142 | + global $wgPageProps; |
| | 143 | + |
| | 144 | + $ret = array( |
| | 145 | + 'prop' => array( |
| | 146 | + 'Which additional properties to get:', |
| | 147 | + ), |
| | 148 | + 'continue' => 'When more results are available, use this to continue', |
| | 149 | + ); |
| | 150 | + |
| | 151 | + $maxLen = max( array_map( 'strlen', array_keys( $wgPageProps ) ) ); |
| | 152 | + $matchLen = $maxLen + 2; |
| | 153 | + if( $maxLen < 12 ) { |
| | 154 | + $matchLen = 14; |
| | 155 | + } |
| | 156 | + |
| | 157 | + foreach( $wgPageProps as $propName => $desc ) { |
| | 158 | + $pretext = " $propName" . str_repeat( ' ', $matchLen - strlen( $propName ) ); |
| | 159 | + |
| | 160 | + $ret['prop'][] = "$pretext- $desc"; |
| | 161 | + } |
| | 162 | + |
| | 163 | + return $ret; |
| | 164 | + } |
| | 165 | + |
| | 166 | + public function getDescription() { |
| | 167 | + return 'Get various properties about a page...'; |
| | 168 | + } |
| | 169 | + |
| | 170 | + public function getPossibleErrors() { |
| | 171 | + return array_merge( parent::getPossibleErrors(), array( |
| | 172 | + array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ), |
| | 173 | + ) ); |
| | 174 | + } |
| | 175 | + |
| | 176 | + protected function getExamples() { |
| | 177 | + return array( |
| | 178 | + 'api.php?action=query&prop=pageprops&titles=Category:Foo', |
| | 179 | + ); |
| | 180 | + } |
| | 181 | + |
| | 182 | + public function getVersion() { |
| | 183 | + return __CLASS__ . ': $Id$'; |
| | 184 | + } |
| | 185 | +} |
| Index: trunk/phase3/includes/api/ApiQuery.php |
| — | — | @@ -58,6 +58,7 @@ |
| 59 | 59 | 'extlinks' => 'ApiQueryExternalLinks', |
| 60 | 60 | 'categoryinfo' => 'ApiQueryCategoryInfo', |
| 61 | 61 | 'duplicatefiles' => 'ApiQueryDuplicateFiles', |
| | 62 | + 'pageprops' => 'ApiQueryPageProps', |
| 62 | 63 | ); |
| 63 | 64 | |
| 64 | 65 | private $mQueryListModules = array( |
| Index: trunk/phase3/includes/AutoLoader.php |
| — | — | @@ -306,6 +306,7 @@ |
| 307 | 307 | 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php', |
| 308 | 308 | 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php', |
| 309 | 309 | 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php', |
| | 310 | + 'ApiQueryPageProps' => 'includes/api/ApiQueryPageProps.php', |
| 310 | 311 | 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php', |
| 311 | 312 | 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php', |
| 312 | 313 | 'ApiQueryRecentChanges' => 'includes/api/ApiQueryRecentChanges.php', |
| Index: trunk/phase3/includes/DefaultSettings.php |
| — | — | @@ -4432,6 +4432,15 @@ |
| 4433 | 4433 | $wgExceptionHooks = array(); |
| 4434 | 4434 | |
| 4435 | 4435 | /** |
| | 4436 | + * List of page property names and descriptions of what they are. |
| | 4437 | + * This is used for the API prop=pageprops module to know which |
| | 4438 | + * page props to search for. |
| | 4439 | + */ |
| | 4440 | +$wgPageProps = array( |
| | 4441 | + 'hiddencat' => 'Whether or not the page has a category with the __HIDDENCAT__ magic word', |
| | 4442 | +); |
| | 4443 | + |
| | 4444 | +/** |
| 4436 | 4445 | * Page property link table invalidation lists. When a page property |
| 4437 | 4446 | * changes, this may require other link tables to be updated (eg |
| 4438 | 4447 | * adding __HIDDENCAT__ means the hiddencat tracking category will |
| Index: trunk/phase3/RELEASE-NOTES |
| — | — | @@ -330,7 +330,8 @@ |
| 331 | 331 | the timestamp of the last edit |
| 332 | 332 | * (bug 24677) axto= parameters added to allcategories, allimages, alllinks, allmessages, |
| 333 | 333 | allpages, and allusers |
| 334 | | -* (bug 24236) Add add, remove, add-self, remove-self tags to meta=siteinfo&siprop=usergroups |
| | 334 | +* (bug 24236) Add add, remove, add-self, remove-self tags to meta=siteinfo&siprop=usergroups |
| | 335 | +* (bug 24484) Add prop=pageprops module |
| 335 | 336 | |
| 336 | 337 | === Languages updated in 1.17 === |
| 337 | 338 | |