Merge "[Hygiene] Rename internal uses of "article" to "page"" into dev

This commit is contained in:
jenkins-bot 2015-11-17 11:37:58 +00:00 committed by Gerrit Code Review
commit 0f9193e8c2
6 changed files with 66 additions and 66 deletions

View file

@ -44,19 +44,19 @@ class Hooks {
*/
public static function onFuncRelated( Parser $parser ) {
$parserOutput = $parser->getOutput();
$relatedArticles = $parserOutput->getExtensionData( 'RelatedArticles' );
if ( !$relatedArticles ) {
$relatedArticles = array();
$relatedPages = $parserOutput->getExtensionData( 'RelatedArticles' );
if ( !$relatedPages ) {
$relatedPages = array();
}
$args = func_get_args();
array_shift( $args );
// Add all the related articles passed by the parser function
// Add all the related pages passed by the parser function
// {{#related:Test with read more|Foo|Bar}}
foreach ( $args as $relatedArticle ) {
$relatedArticles[] = $relatedArticle;
foreach ( $args as $relatedPage ) {
$relatedPages[] = $relatedPage;
}
$parserOutput->setExtensionData( 'RelatedArticles', $relatedArticles );
$parserOutput->setExtensionData( 'RelatedArticles', $relatedPages );
return '';
}
@ -64,7 +64,7 @@ class Hooks {
/**
* Handler for the <code>ParserClearState</code> hook.
*
* Empties the internal list so that related articles are not passed on to future
* Empties the internal list so that related pages are not passed on to future
* ParserOutput's - note that {{#related:Foo}} appends and can be used multiple times
* in the page.
*
@ -83,10 +83,10 @@ class Hooks {
}
/**
* Passes the related articles list from the cached parser output
* Passes the related pages list from the cached parser output
* object to the output page for rendering.
*
* The list of related articles will be retrieved using
* The list of related pages will be retrieved using
* <code>ParserOutput#getExtensionData</code>.
*
* @param OutputPage $out
@ -104,37 +104,37 @@ class Hooks {
}
/**
* Generates anchor element attributes for each entry in list of articles.
* Generates anchor element attributes for each entry in list of pages.
*
* The attributes that are generated are: <code>href</code>,
* <code>text</code>, and <code>class</code>, with the latter always
* set to <code>"interwiki-relart"</code>.
*
* If the the article is of the form <code>"Foo && Bar"</code>, then
* If the the page is of the form <code>"Foo && Bar"</code>, then
* the <code>text</code> attribute will be set to "Bar", otherwise the
* article's {@see Title::getPrefixedText prefixed text} will be used.
* page's {@see Title::getPrefixedText prefixed text} will be used.
*
* @param array[string] $relatedArticles
* @param array[string] $relatedPages
* @return array An array of maps, each with <code>href</code>,
* <code>text</code>, and <code>class</code> entries.
*/
private static function getRelatedArticlesUrls( array $relatedArticles ) {
$relatedArticlesUrls = array();
private static function getRelatedPagesUrls( array $relatedPages ) {
$relatedPagesUrls = array();
foreach ( $relatedArticles as $article ) {
foreach ( $relatedPages as $page ) {
// Tribute to Evan
$article = urldecode( $article );
$page = urldecode( $page );
$altText = '';
if ( preg_match( '/\&\&/', $article ) ) {
$parts = array_map( 'trim', explode( '&&', $article, 2 ) );
$article = $parts[0];
if ( preg_match( '/\&\&/', $page ) ) {
$parts = array_map( 'trim', explode( '&&', $page, 2 ) );
$page = $parts[0];
$altText = $parts[1];
}
$title = Title::newFromText( $article );
$title = Title::newFromText( $page );
if ( $title ) {
$relatedArticlesUrls[] = array(
$relatedPagesUrls[] = array(
'href' => $title->getLocalURL(),
'text' => $altText ?: $title->getPrefixedText(),
'class' => 'interwiki-relart'
@ -142,13 +142,13 @@ class Hooks {
}
};
return $relatedArticlesUrls;
return $relatedPagesUrls;
}
/**
* Handler for the <code>SkinBuildSidebar</code> hook.
*
* Retrieves the list of related articles
* Retrieves the list of related pages
* and adds its HTML representation to the sidebar.
*
* @param Skin $skin
@ -157,18 +157,18 @@ class Hooks {
*/
public static function onSkinBuildSidebar( Skin $skin, &$bar ) {
$out = $skin->getOutput();
$relatedArticles = $out->getProperty( 'RelatedArticles' );
$relatedPages = $out->getProperty( 'RelatedArticles' );
if ( !$relatedArticles ) {
if ( !$relatedPages ) {
return true;
}
$relatedArticlesUrls = self::getRelatedArticlesUrls( $relatedArticles );
$relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
// build relatedarticles <li>'s
$relatedArticles = array();
foreach ( (array) $relatedArticlesUrls as $url ) {
$relatedArticles[] =
$relatedPages = array();
foreach ( (array) $relatedPagesUrls as $url ) {
$relatedPages[] =
Html::rawElement( 'li', array( 'class' => htmlspecialchars( $url['class'] ) ),
Html::element( 'a', array( 'href' => htmlspecialchars( $url['href'] ) ),
$url['text']
@ -179,7 +179,7 @@ class Hooks {
// build complete html
$bar[$skin->msg( 'relatedarticles-title' )->text()] =
Html::rawElement( 'ul', array(),
implode( '', $relatedArticles )
implode( '', $relatedPages )
);
return true;
@ -188,25 +188,25 @@ class Hooks {
/**
* Handler for the <code>SkinTemplateToolboxEnd</code> hook.
*
* Retrieves the list of related articles from the template and
* Retrieves the list of related pages from the template and
* <code>echo</code>s its HTML representation to the sidebar.
*
* @param SkinTemplate $skinTpl
* @return boolean Always <code>true</code>
*/
public static function onSkinTemplateToolboxEnd( BaseTemplate &$skinTpl ) {
$relatedArticles = $skinTpl->getSkin()->getOutput()->getProperty( 'RelatedArticles' );
$relatedPages = $skinTpl->getSkin()->getOutput()->getProperty( 'RelatedArticles' );
if ( !$relatedArticles ) {
if ( !$relatedPages ) {
return true;
}
$relatedArticlesUrls = self::getRelatedArticlesUrls( $relatedArticles );
$relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
// build relatedarticles <li>'s
$relatedArticles = array();
foreach ( (array) $relatedArticlesUrls as $url ) {
$relatedArticles[] =
$relatedPages = array();
foreach ( (array) $relatedPagesUrls as $url ) {
$relatedPages[] =
Html::rawElement( 'li', array( 'class' => htmlspecialchars( $url['class'] ) ),
Html::element( 'a', array( 'href' => htmlspecialchars( $url['href'] ) ),
$url['text']
@ -227,7 +227,7 @@ class Hooks {
Html::element( 'h3', array(), wfMessage( 'relatedarticles-title' )->text() ) .
Html::openElement( 'div', array( 'class' => 'body' ) ) .
Html::openElement( 'ul' ) .
implode( '', $relatedArticles );
implode( '', $relatedPages );
return true;
}

View file

@ -1,7 +1,7 @@
( function ( $ ) {
var config = mw.config.get( [ 'skin', 'wgNamespaceNumber', 'wgMFMode', 'wgIsMainPage' ] ),
relatedPages = new mw.relatedArticles.RelatedPagesGateway(
relatedPages = new mw.relatedPages.RelatedPagesGateway(
new mw.Api(),
mw.config.get( 'wgPageName' ),
mw.config.get( 'wgRelatedArticles' ),

View file

@ -1,7 +1,7 @@
// See https://meta.wikimedia.org/wiki/Schema:RelatedArticles
( function ( $ ) {
var $readMore,
schemaRelatedArticles,
schemaRelatedPages,
skin = mw.config.get( 'skin' ),
$window = $( window );
@ -34,12 +34,12 @@
function logReadMoreSeen() {
if ( isElementInViewport( $readMore ) ) {
$window.off( 'scroll', logReadMoreSeen );
schemaRelatedArticles.log( { eventName: 'seen' } );
schemaRelatedPages.log( { eventName: 'seen' } );
}
}
mw.trackSubscribe( 'ext.relatedArticles.logReady', function ( _, data ) {
schemaRelatedArticles = new mw.eventLog.Schema(
schemaRelatedPages = new mw.eventLog.Schema(
'RelatedArticles',
// not sampled if the config variable is not set
mw.config.get( 'wgRelatedArticlesLoggingSamplingRate', 0 ),
@ -56,7 +56,7 @@
$readMore = data.$readMore;
// log ready
schemaRelatedArticles.log( { eventName: 'ready' } );
schemaRelatedPages.log( { eventName: 'ready' } );
// log when ReadMore is seen by the user
$window.on(
@ -70,7 +70,7 @@
$readMore.on( 'click', 'a', function () {
var index = $( this ).parents( 'li' ).index();
schemaRelatedArticles.log( {
schemaRelatedPages.log( {
eventName: 'clicked',
clickIndex: index + 1
} );

View file

@ -1,20 +1,20 @@
( function ( $ ) {
// FIXME: Move into separate file as this module becomes larger.
mw.relatedArticles = {};
mw.relatedPages = {};
/**
* @class RelatedPagesGateway
* @param {mw.Api} api
* @param {string} currentPage the page that the editorCuratedArticles relate to
* @param {Array} editorCuratedArticles a list of articles curated by editors for the current page
* @param {boolean} useCirrusSearch whether to hit the API when no editor-curated articles are available
* @param {boolean} [onlyUseCirrusSearch=false] whether to ignore the list of editor-curated articles
* @param {string} currentPage the page that the editorCuratedPages relate to
* @param {Array} editorCuratedPages a list of pages curated by editors for the current page
* @param {boolean} useCirrusSearch whether to hit the API when no editor-curated pages are available
* @param {boolean} [onlyUseCirrusSearch=false] whether to ignore the list of editor-curated pages
*/
function RelatedPagesGateway(
api,
currentPage,
editorCuratedArticles,
editorCuratedPages,
useCirrusSearch,
onlyUseCirrusSearch
) {
@ -23,10 +23,10 @@
this.useCirrusSearch = useCirrusSearch;
if ( onlyUseCirrusSearch ) {
editorCuratedArticles = [];
editorCuratedPages = [];
}
this.editorCuratedArticles = editorCuratedArticles || [];
this.editorCuratedPages = editorCuratedPages || [];
}
OO.initClass( RelatedPagesGateway );
@ -50,7 +50,7 @@
* * The Wikidata description, if any
*
* @method
* @param {number} limit of articles to get
* @param {number} limit of pages to get
* @return {jQuery.Promise}
*/
RelatedPagesGateway.prototype.getForCurrentPage = function ( limit ) {
@ -62,13 +62,13 @@
pithumbsize: 80,
wbptterms: 'description'
},
relatedArticles = ( this.editorCuratedArticles ).slice( 0, limit );
relatedPages = ( this.editorCuratedPages ).slice( 0, limit );
if ( relatedArticles.length ) {
parameters.pilimit = relatedArticles.length;
if ( relatedPages.length ) {
parameters.pilimit = relatedPages.length;
parameters[ 'continue' ] = ''; // jscs:ignore requireDotNotation
parameters.titles = relatedArticles;
parameters.titles = relatedPages;
} else if ( this.useCirrusSearch ) {
parameters.pilimit = limit;
@ -117,5 +117,5 @@
} );
}
mw.relatedArticles.RelatedPagesGateway = RelatedPagesGateway;
mw.relatedPages.RelatedPagesGateway = RelatedPagesGateway;
}( jQuery ) );

View file

@ -12,23 +12,23 @@ class HooksTest extends PHPUnit_Framework_TestCase {
public function test_onParserClearState() {
$parser = new Parser();
$parserOutput = $parser->mOutput = new ParserOutput();
$relatedArticles = array( 'Maybeshewill' );
$relatedPages = array( 'Maybeshewill' );
$parserOutput->setExtensionData( 'RelatedArticles', $relatedArticles );
$parserOutput->setProperty( 'RelatedArticles', $relatedArticles );
$parserOutput->setExtensionData( 'RelatedArticles', $relatedPages );
$parserOutput->setProperty( 'RelatedArticles', $relatedPages );
Hooks::onParserClearState( $parser );
$this->assertEquals(
array(),
$parserOutput->getExtensionData( 'RelatedArticles' ),
'It clears the list of related articles.'
'It clears the list of related pages.'
);
$this->assertEquals(
false,
$parserOutput->getProperty( 'RelatedArticles' ),
'[T115698] It unsets the list of related articles that were set as a property.'
'[T115698] It unsets the list of related pages that were set as a property.'
);
}
}

View file

@ -1,5 +1,5 @@
( function ( M, $ ) {
var RelatedPagesGateway = mw.relatedArticles.RelatedPagesGateway,
var RelatedPagesGateway = mw.relatedPages.RelatedPagesGateway,
relatedPages = {
query: {
pages: {