http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89173
Revision: 89173
Author: ashley
Date: 2011-05-30 14:35:09 +0000 (Mon, 30 May 2011)
Log Message:
-----------
tweaks to ShortUrl extension:
*added version number to $wgExtensionCredits
*"double quotes" to 'single quotes' where appropriate
*renamed some functions from UpperCamelCase to lowerCamelCase as per our coding
conventions
*added __METHOD__ to one DB query
*moved two wfMemcKey calls in ShortUrl.utils.php to a variable for better
performance
*spacing & variable name tweaks
Modified Paths:
--------------
trunk/extensions/ShortUrl/ShortUrl.hooks.php
trunk/extensions/ShortUrl/ShortUrl.php
trunk/extensions/ShortUrl/ShortUrl.utils.php
trunk/extensions/ShortUrl/SpecialShortUrl.php
trunk/extensions/ShortUrl/js/ext.shortUrl.js
trunk/extensions/ShortUrl/populateShortUrlTable.php
Modified: trunk/extensions/ShortUrl/ShortUrl.hooks.php
===================================================================
--- trunk/extensions/ShortUrl/ShortUrl.hooks.php 2011-05-30 14:18:47 UTC
(rev 89172)
+++ trunk/extensions/ShortUrl/ShortUrl.hooks.php 2011-05-30 14:35:09 UTC
(rev 89173)
@@ -18,8 +18,9 @@
* @param $tpl
* @return bool
*/
- public static function AddToolboxLink( &$tpl ) {
+ public static function addToolboxLink( &$tpl ) {
global $wgOut, $wgShortUrlPrefix;
+
if ( $wgShortUrlPrefix == null ) {
$urlPrefix = SpecialPage::getTitleFor( 'ShortUrl'
)->getFullURL() . '/';
} else {
@@ -28,14 +29,14 @@
$title = $wgOut->getTitle();
if ( ShortUrlUtils::needsShortUrl( $title ) ) {
- $shortId = ShortUrlUtils::EncodeTitle( $title );
+ $shortId = ShortUrlUtils::encodeTitle( $title );
$shortURL = $urlPrefix . $shortId;
$html = Html::rawElement( 'li', array( 'id' =>
't-shorturl' ),
Html::Element( 'a', array(
'href' => $shortURL,
'title' => wfMsg(
'shorturl-toolbox-title' )
),
- wfMsg ( 'shorturl-toolbox-text' ) )
+ wfMsg( 'shorturl-toolbox-text' ) )
);
echo $html;
@@ -47,7 +48,7 @@
* @param $out OutputPage
* @param $text string the HTML text to be added
*/
- public static function OutputPageBeforeHTML( &$out, &$text ) {
+ public static function onOutputPageBeforeHTML( &$out, &$text ) {
global $wgOut;
$title = $wgOut->getTitle();
if ( ShortUrlUtils::needsShortUrl( $title ) ) {
@@ -60,9 +61,9 @@
* @param $du DatabaseUpdater
* @return bool
*/
- public static function SetupSchema( DatabaseUpdater $du ) {
+ public static function setupSchema( DatabaseUpdater $du ) {
$base = dirname( __FILE__ ) . '/schemas';
- $du->addExtensionTable( "shorturls", "$base/shorturls.sql" );
+ $du->addExtensionTable( 'shorturls', "$base/shorturls.sql" );
return true;
}
Modified: trunk/extensions/ShortUrl/ShortUrl.php
===================================================================
--- trunk/extensions/ShortUrl/ShortUrl.php 2011-05-30 14:18:47 UTC (rev
89172)
+++ trunk/extensions/ShortUrl/ShortUrl.php 2011-05-30 14:35:09 UTC (rev
89173)
@@ -19,6 +19,7 @@
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'ShortUrl',
+ 'version' => '1.0',
'author' => 'Yuvi Panda',
'url' => 'http://www.mediawiki.org/wiki/Extension:ShortUrl',
'descriptionmsg' => 'shorturl-desc',
@@ -34,9 +35,9 @@
$wgAutoloadClasses['SpecialShortUrl'] = $dir . 'SpecialShortUrl.php';
$wgSpecialPages['ShortUrl'] = 'SpecialShortUrl';
-$wgHooks['SkinTemplateToolboxEnd'][] = 'ShortUrlHooks::AddToolboxLink';
-$wgHooks['LoadExtensionSchemaUpdates'][] = 'ShortUrlHooks::SetupSchema';
-$wgHooks['OutputPageBeforeHTML'][] = 'ShortUrlHooks::OutputPageBeforeHTML';
+$wgHooks['SkinTemplateToolboxEnd'][] = 'ShortUrlHooks::addToolboxLink';
+$wgHooks['LoadExtensionSchemaUpdates'][] = 'ShortUrlHooks::setupSchema';
+$wgHooks['OutputPageBeforeHTML'][] = 'ShortUrlHooks::onOutputPageBeforeHTML';
$wgResourceModules['ext.shortUrl'] = array(
'scripts' => 'js/ext.shortUrl.js',
Modified: trunk/extensions/ShortUrl/ShortUrl.utils.php
===================================================================
--- trunk/extensions/ShortUrl/ShortUrl.utils.php 2011-05-30 14:18:47 UTC
(rev 89172)
+++ trunk/extensions/ShortUrl/ShortUrl.utils.php 2011-05-30 14:35:09 UTC
(rev 89173)
@@ -22,44 +22,50 @@
* @param $title Title
* @return mixed|string
*/
- public static function EncodeTitle ( $title ) {
+ public static function encodeTitle( $title ) {
global $wgMemc;
- $id = $wgMemc->get( wfMemcKey( 'shorturls', 'title',
$title->getFullText() ) );
+ $memcKey = wfMemcKey( 'shorturls', 'title',
$title->getFullText() );
+ $id = $wgMemc->get( $memcKey );
if ( !$id ) {
$dbr = wfGetDB( DB_SLAVE );
$query = $dbr->select(
'shorturls',
array( 'su_id' ),
- array( 'su_namespace' =>
$title->getNamespace(), 'su_title' => $title->getDBkey() ),
- __METHOD__ );
+ array(
+ 'su_namespace' =>
$title->getNamespace(),
+ 'su_title' => $title->getDBkey()
+ ),
+ __METHOD__
+ );
if ( $dbr->numRows( $query ) > 0 ) {
$entry = $dbr->fetchObject( $query );
$id = $entry->su_id;
} else {
$dbw = wfGetDB( DB_MASTER );
- $row_data = array(
+ $rowData = array(
'su_id' => $dbw->nextSequenceValue(
'shorturls_id_seq' ),
'su_namespace' =>
$title->getNamespace(),
'su_title' => $title->getDBkey()
);
- $dbw->insert( 'shorturls', $row_data );
+ $dbw->insert( 'shorturls', $rowData, __METHOD__
);
$id = $dbw->insertId();
}
- $wgMemc->set( wfMemcKey( 'shorturls', 'title',
$title->getFullText() ), $id, 0 );
+ $wgMemc->set( $memcKey, $id, 0 );
}
return base_convert( $id, 10, 36 );
}
/**
- * @param $data string
+ * @param $urlFragment String
* @return Title
*/
- public static function DecodeURL ( $urlfragment ) {
+ public static function decodeURL( $urlFragment ) {
global $wgMemc;
- $id = intval( base_convert ( $urlfragment, 36, 10 ) );
- $entry = $wgMemc->get( wfMemcKey( 'shorturls', 'id', $id ) );
+ $id = intval( base_convert( $urlFragment, 36, 10 ) );
+ $memcKey = wfMemcKey( 'shorturls', 'id', $id );
+ $entry = $wgMemc->get( $memcKey );
if ( !$entry ) {
$dbr = wfGetDB( DB_SLAVE );
$query = $dbr->select(
@@ -70,16 +76,16 @@
);
$entry = $dbr->fetchRow( $query ); // Less overhead on
memcaching
- $wgMemc->set( wfMemcKey( 'shorturls', 'id', $id ),
$entry, 0 );
+ $wgMemc->set( $memcKey, $entry, 0 );
}
return Title::makeTitle( $entry['su_namespace'],
$entry['su_title'] );
}
/**
* @param $title Title
- * @return True if a shorturl needs to be displayed
+ * @return Boolean: true if a short URL needs to be displayed
*/
- public static function NeedsShortUrl( $title ) {
- return $title->exists() && ! $title->equals(
Title::newMainPage() );
+ public static function needsShortUrl( $title ) {
+ return $title->exists() && !$title->equals(
Title::newMainPage() );
}
}
Modified: trunk/extensions/ShortUrl/SpecialShortUrl.php
===================================================================
--- trunk/extensions/ShortUrl/SpecialShortUrl.php 2011-05-30 14:18:47 UTC
(rev 89172)
+++ trunk/extensions/ShortUrl/SpecialShortUrl.php 2011-05-30 14:35:09 UTC
(rev 89173)
@@ -1,7 +1,6 @@
<?php
/**
- * Setup for ShortUrl extension, a special page that provides redirects to
articles
- * via their page IDs
+ * A special page that provides redirects to articles via their page IDs
*
* @file
* @ingroup Extensions
@@ -36,13 +35,13 @@
public function execute( $par ) {
global $wgOut;
- $title = ShortUrlUtils::DecodeURL( $par );
+ $title = ShortUrlUtils::decodeURL( $par );
if ( $title ) {
$wgOut->redirect( $title->getFullURL(), '301' );
return;
}
// Wrong ID
- $notfound = Html::element( 'p', array(), wfMsg (
'shorturl-not-found', $par ) );
- $wgOut->addHTML( $notfound );
+ $notFound = Html::element( 'p', array(), wfMsg(
'shorturl-not-found', $par ) );
+ $wgOut->addHTML( $notFound );
}
}
Modified: trunk/extensions/ShortUrl/js/ext.shortUrl.js
===================================================================
--- trunk/extensions/ShortUrl/js/ext.shortUrl.js 2011-05-30 14:18:47 UTC
(rev 89172)
+++ trunk/extensions/ShortUrl/js/ext.shortUrl.js 2011-05-30 14:35:09 UTC
(rev 89173)
@@ -1,6 +1,6 @@
-jQuery( function ( $ ) {
- if( $("#t-shorturl").length ) {
- var url = $("#t-shorturl a").attr("href");
- $("#firstHeading").append('<a class="title-shortlink" href="' + url +
'">' + url + '</a>');
- }
+jQuery( function( $ ) {
+ if( $( '#t-shorturl' ).length ) {
+ var url = $( '#t-shorturl a' ).attr( 'href' );
+ $( '#firstHeading' ).append( '<a class="title-shortlink"
href="' + url + '">' + url + '</a>' );
+ }
});
Modified: trunk/extensions/ShortUrl/populateShortUrlTable.php
===================================================================
--- trunk/extensions/ShortUrl/populateShortUrlTable.php 2011-05-30 14:18:47 UTC
(rev 89172)
+++ trunk/extensions/ShortUrl/populateShortUrlTable.php 2011-05-30 14:35:09 UTC
(rev 89173)
@@ -9,7 +9,7 @@
class PopulateShortUrlsTable extends Maintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Populates ShortUrls Table with all
existing articles";
+ $this->mDescription = 'Populates ShortUrls Table with all
existing articles';
}
private function insertRows( $a ) {
@@ -22,37 +22,37 @@
);
}
- //FIXME: Refactor out code in ShortUrl.functions.php so it can be used
here
+ // @todo FIXME: Refactor out code in ShortUrl.functions.php so it can
be used here
public function execute() {
$rowCount = 0;
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
- "page",
- array( "page_namespace", "page_title" ),
+ 'page',
+ array( 'page_namespace', 'page_title' ),
array(),
__METHOD__
);
- $insert_buffer = array();
+ $insertBuffer = array();
foreach( $res as $row ) {
- $row_data = array(
+ $rowData = array(
'su_namespace' => $row->page_namespace,
'su_title' => $row->page_title
);
- array_push( $insert_buffer, $row_data );
- if( count( $insert_buffer ) % 100 == 0) {
- $this->insertRows( $insert_buffer );
- $insert_buffer = array();
+ array_push( $insertBuffer, $rowData );
+ if( count( $insertBuffer ) % 100 == 0 ) {
+ $this->insertRows( $insertBuffer );
+ $insertBuffer = array();
}
$this->output( $rowCount . " titles done\n" );
$rowCount++;
}
- if( count( $insert_buffer ) > 0 ) {
- $this->insertRows( $insert_buffer );
+ if( count( $insertBuffer ) > 0 ) {
+ $this->insertRows( $insertBuffer );
}
}
}
-$maintClass = "PopulateShortUrlsTable";
+$maintClass = 'PopulateShortUrlsTable';
require_once( DO_MAINTENANCE );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs