* (bug 32415) Empty page get no size attribute in API output.
* (bug 31759) Undefined property notice in querypages API.
* (bug 32495) API should allow purge by pageids.
+* (bug 33147) API examples should explain what they do.
=== Languages updated in 1.19 ===
$msg .= "Parameters:\n$paramsMsg";
}
- $msg .= $this->makeHelpArrayToString( $lnPrfx, "Example", $this->getExamples() );
+ $examples = $this->getExamples();
+ if ( $examples !== false ) {
+ if ( !is_array( $examples ) ) {
+ $examples = array(
+ $examples
+ );
+ }
+ $msg .= "Example" . ( count( $examples ) > 1 ? 's' : '' ) . ":\n";
+ foreach( $examples as $k => $v ) {
+
+ if ( is_numeric( $k ) ) {
+ $msg .= " $v\n";
+ } else {
+ $v .= ":";
+ if ( is_array( $v ) ) {
+ $msgExample = implode( "\n", array_map( array( $this, 'indentExampleText' ), $v ) );
+ } else {
+ $msgExample = " $v";
+ }
+ $msg .= wordwrap( $msgExample, 100, "\n" ) . "\n $k\n";
+ }
+ }
+ }
+
$msg .= $this->makeHelpArrayToString( $lnPrfx, "Help page", $this->getHelpUrls() );
if ( $this->getMain()->getShowVersions() ) {
return $msg;
}
+ /**
+ * @param $item string
+ * @return string
+ */
+ private function indentExampleText( $item ) {
+ return " " . $item;
+ }
+
/**
* @param $prefix string Text to split output items
* @param $title string What is being output
}
$deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] ) ?
- $paramSettings[self::PARAM_DEPRECATED] : false;
+ $paramSettings[self::PARAM_DEPRECATED] : false;
if ( $deprecated ) {
$desc = "DEPRECATED! $desc";
}
$required = isset( $paramSettings[self::PARAM_REQUIRED] ) ?
- $paramSettings[self::PARAM_REQUIRED] : false;
+ $paramSettings[self::PARAM_REQUIRED] : false;
if ( $required ) {
$desc .= $paramPrefix . "This parameter is required";
}
if ( !$isArray
|| $isArray && count( $paramSettings[self::PARAM_TYPE] ) > self::LIMIT_SML1 ) {
$desc .= $paramPrefix . "Maximum number of values " .
- self::LIMIT_SML1 . " (" . self::LIMIT_SML2 . " for bots)";
+ self::LIMIT_SML1 . " (" . self::LIMIT_SML2 . " for bots)";
}
}
}
// returning the version string for ApiBase work
if ( $path ) {
return "{$matches[0]}\n https://svn.wikimedia.org/" .
- "viewvc/mediawiki/trunk/" . dirname( $path ) .
- "/{$matches[2]}";
+ "viewvc/mediawiki/trunk/" . dirname( $path ) .
+ "/{$matches[2]}";
}
return $matches[0];
}
array_shift( $required );
$intersection = array_intersect( array_keys( array_filter( $params,
- array( $this, "parameterNotEmpty" ) ) ), $required );
+ array( $this, "parameterNotEmpty" ) ) ), $required );
if ( count( $intersection ) > 1 ) {
$this->dieUsage( 'The parameters ' . implode( ', ', $intersection ) . ' can not be used together', 'invalidparammix' );
array_shift( $required );
$intersection = array_intersect( array_keys( array_filter( $params,
- array( $this, "parameterNotEmpty" ) ) ), $required );
+ array( $this, "parameterNotEmpty" ) ) ), $required );
if ( count( $intersection ) > 1 ) {
$this->dieUsage( 'The parameters ' . implode( ', ', $intersection ) . ' can not be used together', 'invalidparammix' );
# If no user option was passed, use watchdefault or watchcreation
if ( is_null( $userOption ) ) {
$userOption = $titleObj->exists()
- ? 'watchdefault' : 'watchcreations';
+ ? 'watchdefault' : 'watchcreations';
}
# Watch the article based on the user preference
return (bool)$this->getUser()->getOption( $userOption );
// This is a bit awkward, but we want to avoid calling canApiHighLimits() because it unstubs $wgUser
$valuesList = explode( '|', $value, self::LIMIT_SML2 + 1 );
$sizeLimit = count( $valuesList ) > self::LIMIT_SML1 && $this->mMainModule->canApiHighLimits() ?
- self::LIMIT_SML2 : self::LIMIT_SML1;
+ self::LIMIT_SML2 : self::LIMIT_SML1;
if ( self::truncateArray( $valuesList, $sizeLimit ) ) {
$this->setWarning( "Too many values supplied for parameter '$valueName': the limit is $sizeLimit" );
if ( isset( self::$messageMap[$key] ) ) {
return array( 'code' =>
- wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ),
- 'info' =>
+ wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ),
+ 'info' =>
wfMsgReplaceArgs( self::$messageMap[$key]['info'], $error )
);
}
public function getExamples() {
return array(
- 'api.php?action=compare&fromrev=1&torev=2',
+ 'api.php?action=compare&fromrev=1&torev=2' => 'Creates a diff between revision 1 and 2',
);
}
public function getExamples() {
return array(
- 'api.php?action=delete&title=Main%20Page&token=123ABC',
- 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
+ 'api.php?action=delete&title=Main%20Page&token=123ABC' => 'Deletes the Main Page',
+ 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move' => 'Deletes the Main Page with the reason "Preparing for move"',
);
}
public function getExamples() {
return array(
- 'Edit a page (anonymous user):',
- ' api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\',
- 'Prepend __NOTOC__ to a page (anonymous user):',
- ' api.php?action=edit&title=Test&summary=NOTOC&minor=&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\',
- 'Undo r13579 through r13585 with autosummary (anonymous user):',
- ' api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\\',
+
+ 'api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\'
+ => 'Edit a page (anonymous user)',
+
+ 'api.php?action=edit&title=Test&summary=NOTOC&minor=&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\'
+ => 'Prepend __NOTOC__ to a page (anonymous user)',
+ 'api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\\'
+ => 'Undo r13579 through r13585 with autosummary (anonymous user)',
);
}
public function getExamples() {
return array(
- 'api.php?action=emailuser&target=WikiSysop&text=Content'
+ 'api.php?action=emailuser&target=WikiSysop&text=Content' => 'Sends an email to the User "WikiSysop" with the text "Content"',
);
}
public function getExamples() {
return array(
- 'Revert Wiki.png to the version of 20110305152740:',
- ' api.php?action=filerevert&filename=Wiki.png&comment=Revert&archivename=20110305152740!Wiki.png&token=+\\',
+ 'api.php?action=filerevert&filename=Wiki.png&comment=Revert&archivename=20110305152740!Wiki.png&token=+\\'
+ => 'Revert Wiki.png to the version of 20110305152740',
);
}
}
public function getExamples() {
- return 'api.php?action=query&meta=siteinfo&siprop=namespaces&format=' . $this->getModuleName();
+ return array(
+ 'api.php?action=query&meta=siteinfo&siprop=namespaces&format=' . $this->getModuleName()
+ => "Formats the query result in the {$this->getModuleName()} format",
+ );
}
public function getHelpUrls() {
public function getExamples() {
return array(
- 'Whole help page:',
- ' api.php?action=help',
- 'Module (action) help page:',
- ' api.php?action=help&modules=protect',
- 'Query (list) modules help page:',
- ' api.php?action=help&querymodules=categorymembers',
- 'Query (prop) modules help page:',
- ' api.php?action=help&querymodules=info',
- 'Query (meta) modules help page:',
- ' api.php?action=help&querymodules=siteinfo',
+ 'api.php?action=help' => 'Whole help page',
+ 'api.php?action=help&modules=protect' => 'Module (action) help page',
+ 'api.php?action=help&querymodules=categorymembers' => 'Query (list) modules help page',
+ 'api.php?action=help&querymodules=info' => 'Query (prop) modules help page',
+ 'api.php?action=help&querymodules=siteinfo' => 'Query (meta) modules help page',
);
}
public function getExamples() {
return array(
- 'Import [[meta:Help:Parserfunctions]] to namespace 100 with full history:',
- ' api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&namespace=100&fullhistory=&token=123ABC',
+ 'api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&namespace=100&fullhistory=&token=123ABC'
+ => 'Import [[meta:Help:Parserfunctions]] to namespace 100 with full history',
);
}
public function getExamples() {
return array(
- 'api.php?action=logout'
+ 'api.php?action=logout' => 'Logs the current user out',
);
}
$result = $this->getResult();
$retval['classname'] = get_class( $obj );
$retval['description'] = implode( "\n", (array)$obj->getFinalDescription() );
- $examples = (array)$obj->getExamples();
- $retval['examples'] = implode( "\n", $examples );
+
+ $retval['examples'] = '';
+
$retval['version'] = implode( "\n", (array)$obj->getVersion() );
$retval['prefix'] = $obj->getModulePrefix();
}
$result->setIndexedTagName( $retval['helpurls'], 'helpurl' );
- $retval['allexamples'] = $examples;
- if ( isset( $retval['allexamples'][0] ) && $retval['allexamples'][0] === false ) {
- $retval['allexamples'] = array();
+ $examples = $obj->getExamples();
+ $retval['allexamples'] = array();
+ if ( $examples !== false ) {
+ foreach( $examples as $k => $v ) {
+ if ( strlen( $retval['examples'] ) ) {
+ $retval['examples'] .= ' ';
+ }
+ $item = array();
+ if ( is_numeric( $k ) ) {
+ $retval['examples'] .= $v;
+ $result->setContent( $item, $v );
+ } else {
+ if ( !is_array( $v ) ) {
+ $item['description'] = $v;
+ } else {
+ $item['description'] = implode( $v, "\n" );
+ }
+ $retval['examples'] .= $item['description'] . ' ' . $k;
+ $result->setContent( $item, $k );
+ }
+ $retval['allexamples'][] = $item;
+ }
}
$result->setIndexedTagName( $retval['allexamples'], 'example' );
public function getExamples() {
return array(
- 'api.php?action=purge&titles=Main_Page|API'
+ 'api.php?action=purge&titles=Main_Page|API' => 'Purges the "Main Page" and the "API" page',
);
}
public function getExamples() {
return array(
- 'Simple Use',
- ' Show a list of images starting at the letter "B"',
- ' api.php?action=query&list=allimages&aifrom=B',
- 'Using as Generator',
- ' Show info about 4 images starting at the letter "T"',
- ' api.php?action=query&generator=allimages&gailimit=4&gaifrom=T&prop=imageinfo',
+ 'api.php?action=query&list=allimages&aifrom=B' => array(
+ 'Simple Use',
+ 'Show a list of images starting at the letter "B"',
+ ),
+ 'api.php?action=query&generator=allimages&gailimit=4&gaifrom=T&prop=imageinfo' => array(
+ 'Using as Generator',
+ 'Show info about 4 images starting at the letter "T"',
+ ),
);
}
public function getExamples() {
return array(
- 'Simple Use',
- ' Show a list of pages starting at the letter "B"',
- ' api.php?action=query&list=allpages&apfrom=B',
- 'Using as Generator',
- ' Show info about 4 pages starting at the letter "T"',
- ' api.php?action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info',
- ' Show content of first 2 non-redirect pages begining at "Re"',
- ' api.php?action=query&generator=allpages&gaplimit=2&gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
+ 'api.php?action=query&list=allpages&apfrom=B' => array(
+ 'Simple Use',
+ 'Show a list of pages starting at the letter "B"',
+ ),
+ 'api.php?action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info' => array(
+ 'Using as Generator',
+ 'Show info about 4 pages starting at the letter "T"',
+ ),
+ 'api.php?action=query&generator=allpages&gaplimit=2&gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content' => array(
+ 'Show content of first 2 non-redirect pages begining at "Re"',
+ )
);
}
public function getExamples() {
return array(
- 'Get a list of categories [[Albert Einstein]] belongs to:',
- ' api.php?action=query&prop=categories&titles=Albert%20Einstein',
- 'Get information about all categories used in the [[Albert Einstein]]:',
- ' api.php?action=query&generator=categories&titles=Albert%20Einstein&prop=info'
+ 'api.php?action=query&prop=categories&titles=Albert%20Einstein' => 'Get a list of categories [[Albert Einstein]] belongs to',
+ 'api.php?action=query&generator=categories&titles=Albert%20Einstein&prop=info' => 'Get information about all categories used in the [[Albert Einstein]]',
);
}
public function getExamples() {
return array(
- 'Get first 10 pages in [[Category:Physics]]:',
- ' api.php?action=query&list=categorymembers&cmtitle=Category:Physics',
- 'Get page info about first 10 pages in [[Category:Physics]]:',
- ' api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info',
+ 'api.php?action=query&list=categorymembers&cmtitle=Category:Physics' => 'Get first 10 pages in [[Category:Physics]]',
+ 'api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info' => 'Get page info about first 10 pages in [[Category:Physics]]',
);
}
public function getExamples() {
return array(
- 'List the last deleted revisions of Main Page and Talk:Main Page, with content (mode 1):',
- ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content',
- 'List the last 50 deleted contributions by Bob (mode 2):',
- ' api.php?action=query&list=deletedrevs&druser=Bob&drlimit=50',
- 'List the first 50 deleted revisions in the main namespace (mode 3):',
- ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50',
- 'List the first 50 deleted pages in the Talk namespace (mode 3):',
- ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique=',
+ 'api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
+ => 'List the last deleted revisions of Main Page and Talk:Main Page, with content (mode 1)',
+ 'api.php?action=query&list=deletedrevs&druser=Bob&drlimit=50'
+ => 'List the last 50 deleted contributions by Bob (mode 2)',
+ 'api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50'
+ => 'List the first 50 deleted revisions in the main namespace (mode 3)',
+ 'api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
+ => 'List the first 50 deleted pages in the Talk namespace (mode 3):',
);
}
public function getExamples() {
return array(
- 'Get a list of external links on the [[Main Page]]:',
- ' api.php?action=query&prop=extlinks&titles=Main%20Page',
+ 'api.php?action=query&prop=extlinks&titles=Main%20Page' => 'Get a list of external links on the [[Main Page]]',
);
}
public function getExamples() {
return array(
- 'Simple Use',
- ' Show a list of all deleted files',
- ' api.php?action=query&list=filearchive',
+ 'api.php?action=query&list=filearchive' => array(
+ 'Simple Use',
+ 'Show a list of all deleted files',
+ ),
);
}
public function getExamples() {
return array(
- 'Get interwiki links from the [[Main Page]]:',
- ' api.php?action=query&prop=iwlinks&titles=Main%20Page',
+ 'api.php?action=query&prop=iwlinks&titles=Main%20Page' => 'Get interwiki links from the [[Main Page]]',
);
}
public function getExamples() {
return array(
- 'Get a list of images used in the [[Main Page]]:',
- ' api.php?action=query&prop=images&titles=Main%20Page',
- 'Get information about all images used in the [[Main Page]]:',
- ' api.php?action=query&generator=images&titles=Main%20Page&prop=info'
+ 'api.php?action=query&prop=images&titles=Main%20Page' => 'Get a list of images used in the [[Main Page]]',
+ 'api.php?action=query&generator=images&titles=Main%20Page&prop=info' => 'Get information about all images used in the [[Main Page]]',
);
}
public function getExamples() {
return array(
- 'Get interlanguage links from the [[Main Page]]:',
- ' api.php?action=query&prop=langlinks&titles=Main%20Page&redirects=',
+ 'api.php?action=query&prop=langlinks&titles=Main%20Page&redirects=' => 'Get interlanguage links from the [[Main Page]]',
);
}
}
public function getExamples() {
+ $desc = $this->description;
+ $name = $this->getModuleName();
return array(
- "Get {$this->description}s from the [[Main Page]]:",
- " api.php?action=query&prop={$this->getModuleName()}&titles=Main%20Page",
- "Get information about the {$this->description} pages in the [[Main Page]]:",
- " api.php?action=query&generator={$this->getModuleName()}&titles=Main%20Page&prop=info",
- "Get {$this->description}s from the Main Page in the User and Template namespaces:",
- " api.php?action=query&prop={$this->getModuleName()}&titles=Main%20Page&{$this->prefix}namespace=2|10"
+ "api.php?action=query&prop={$name}&titles=Main%20Page" => "Get {$desc}s from the [[Main Page]]:",
+ "api.php?action=query&generator={$name}&titles=Main%20Page&prop=info" => "Get information about the {$desc} pages in the [[Main Page]]:",
+ "api.php?action=query&prop={$name}&titles=Main%20Page&{$this->prefix}namespace=2|10" => "Get {$desc}s from the Main Page in the User and Template namespaces:",
);
}
public function getExamples() {
return array(
- 'Get data with content for the last revision of titles "API" and "Main Page":',
+ 'Get data with content for the last revision of titles "API" and "Main Page"',
' api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
- 'Get last 5 revisions of the "Main Page":',
+ 'Get last 5 revisions of the "Main Page"',
' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
- 'Get first 5 revisions of the "Main Page":',
+ 'Get first 5 revisions of the "Main Page"',
' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
- 'Get first 5 revisions of the "Main Page" made after 2006-05-01:',
+ 'Get first 5 revisions of the "Main Page" made after 2006-05-01',
' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
public function getExamples() {
return array(
- 'Upload from a URL:',
- ' api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png',
- 'Complete an upload that failed due to warnings:',
- ' api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1',
+ 'api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
+ => 'Upload from a URL',
+ 'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1'
+ => 'Complete an upload that failed due to warnings',
);
}
public function getExamples() {
return array(
- 'api.php?action=watch&title=Main_Page',
- 'api.php?action=watch&title=Main_Page&unwatch=',
+ 'api.php?action=watch&title=Main_Page' => 'Watch the page "Main Page"',
+ 'api.php?action=watch&title=Main_Page&unwatch=' => 'Unwatch the page "Main Page"',
);
}